mirror of
https://github.com/isc-projects/bind9.git
synced 2026-05-28 04:34:54 -04:00
initial checkin of mdnkit, for multilingual domain names, from jpnic
This commit is contained in:
parent
1afae09da4
commit
04bdb23457
114 changed files with 47297 additions and 2 deletions
192
contrib/idn/mdnkit/ChangeLog
Normal file
192
contrib/idn/mdnkit/ChangeLog
Normal file
|
|
@ -0,0 +1,192 @@
|
|||
2000-11-27
|
||||
* wsock/config/mdnconf.tcl: implement "unwrap all" button.
|
||||
* wsock/README.txt, wsock/README_j.txt: add description on "unwrap
|
||||
all" button. add important notice on installing a new version
|
||||
to the top of each file.
|
||||
* Makefile.in, tools/rpm/mdnkit.spec: update for version 1.2.
|
||||
* wsock/bin/README_e.txt, wsock/bind/README_j.txt: updated.
|
||||
* version 1.2 release.
|
||||
|
||||
2000-11-22
|
||||
* lib/brace.c, lib/lace.c, lib/race.c: keep lint happy.
|
||||
* lib/brace.c: fix a bug that the encoder outputs a broken string.
|
||||
* dnsproxy/dnsproxy.conf.sample, lib/mdnres.conf.sample: add
|
||||
description of new normalization schemes.
|
||||
|
||||
2000-11-21
|
||||
* lib/translator.c, include/mdn/translator.h: add new parameter
|
||||
"local_alternate_converter" to mdn_translator_translate(), to
|
||||
accept and correctly process names encoded in alternate-encoding.
|
||||
* lib/msgtrans.c, include/mdn/msgtrans.h: add a new parameter
|
||||
to mdn_msgtrans_param_t which is required for the new
|
||||
mdn_translator_translate() above.
|
||||
* dnsproxy/translate.c, wsock/common/convert.c: according to the
|
||||
changes above.
|
||||
* DISTFILES: replace patch/bind8/bind-8.2.2-P5-patch with
|
||||
patch/bind8/bind-8.2.2-P7-patch.
|
||||
* lib/Makefile.in, tools/runmdn/Makefile.in: increase version
|
||||
number.
|
||||
* lib/brace.c, lib/lace.c, lib/race.c: fix buffer overrun bugs.
|
||||
* wsock/README.txt, wsock/README_j.txt: updated.
|
||||
* README, README.ja: updated for version 1.2 release.
|
||||
* Makefile.in: updated for version 1.2-rc1.
|
||||
|
||||
2000-11-20
|
||||
* lib/race.c: fix a buffer overrun bug.
|
||||
* patch/bind8/bind-8.2.2-P5-patch: removed.
|
||||
* patch/bind8/bind-8.2.2-P7-patch: created.
|
||||
|
||||
2000-11-17
|
||||
* lib/normalizer.c: add normalize scheme "ja-kana-fullwidth"
|
||||
as an alias of "ja-fullwidth". also add new scheme
|
||||
"ja-alnum-halfwidth".
|
||||
* lib/normalizer.c: make the size of intermediate buffer used for
|
||||
normalization grow dynamically. previously, the size was a fixed
|
||||
value based on the size of the input string and overflow was
|
||||
possible.
|
||||
* lib/brace.c: add internal error checking. keep lint happy.
|
||||
* dnsproxy/config.c, dnsproxy/config.h: removed (renamed to
|
||||
proxycnf.[ch], in order to avoid confusion with include/config.h).
|
||||
* dnsproxy/proxycnf.c, dnsproxy/proxycnf.h: created.
|
||||
* DISTFILES, dnsproxy/Makefile.in, dnsproxy/make.os2,
|
||||
dnsproxy/make.wnt: remove dnsproxy/config.[ch], add
|
||||
dnsproxy/proxycnf.[ch]
|
||||
* dnsproxy/logging.c, dnsproxy/message.c dnsproxy/proxycnf.c:
|
||||
include <config.h>.
|
||||
* configure.in, configure, acconfig.h, include/config.h.in:
|
||||
add checking whether the system defines BOOL type or not.
|
||||
add configuration option --with-brace-suffix and --with-lace-prefix.
|
||||
* README, README.ja: mention about new configuration options above.
|
||||
* dnsproxy/dnsproxy.h: take the definition of BOOL out. use own
|
||||
version of TRUE/FALSE, instead of system-supplied ones.
|
||||
* wsock/config/mdnconf.tcl: add log configuration feature (log level
|
||||
and log file). implement log file operation (view/delete).
|
||||
change widgets layout so that they look neater.
|
||||
* wsock/common/encoding.c, wsock/common/jpnicmdn.h: add new
|
||||
function for retrieving the pathname of the log file from the
|
||||
registry.
|
||||
* wsock/common/printf.c: retrieve log file pathname from the
|
||||
registry. stop writing log if the log level is negative.
|
||||
* tools/mdnconv/Makefile.in: add dependency to libmdn.la.
|
||||
* man/mdnres.conf.5.in, tools/mdnconv/mdnconv.1: add description
|
||||
on the new encodings and normalization schemes.
|
||||
* dnsproxy/dnsproxy.8: removed.
|
||||
* dnsproxy/dnsproxy.8.in: created.
|
||||
* dnsproxy/Makefile.in: generate dnsproxy.8 from dnsproxy.8.in,
|
||||
reflecting correct path.
|
||||
* DISTFILES: replace dnsproxy/dnsproxy.8 with dnsproxy/dnsproxy.8.in.
|
||||
|
||||
2000-11-16
|
||||
* lib/brace.c: fix buffer-overrun bugs.
|
||||
|
||||
2000-11-14
|
||||
* include/mdn/brace.h, lib/mdn/brace.c: created. (for BRACE encoding)
|
||||
* include/mdn/lace.h, lib/mdn/lace.c: created. (for LACE encoding)
|
||||
* include/mdn/util.h, lib/util.c: incorporate some functionalities
|
||||
from race.c, such as UTF-8 <-> UTF-16 conversion.
|
||||
* lib/race.c: move some functionalities shared with brace.c and
|
||||
lace.c out to util.c.
|
||||
* lib/converter.c: add BRACE and LACE converters.
|
||||
* include/mdn/Makefile.in: add brace.h and lace.h to the intall files.
|
||||
* lib/Makefile.in: add brace.c and lace.c.
|
||||
* DISTFILES: add include/mdn/{brace,lace}.h, lib/{brace,lace}.c.
|
||||
|
||||
2000-11-10
|
||||
* lib/normalizer.c: add normalize scheme
|
||||
"ja-compose-voiced-sound".
|
||||
|
||||
2000-11-06
|
||||
* wsock/common/printf.c: mDN Wrapper enable libmdn trace
|
||||
* wsock/wsock11/dllmain.c: mDN Wrapper enable libmdn trace
|
||||
* wsock/wsock20/dllmain.c: mDN Wrapper enable libmdn trace
|
||||
* wsock/common/jpnicmdn.h: mDN Wrapper enable libmdn trace
|
||||
* wsock/common/jpnicmdn.def: mDN Wrapper enable libmdn trace
|
||||
* wsock/wsock11/dllfunc.c: check status of conversion
|
||||
* wsock/wsock20/dllfunc.c: check status of conversion
|
||||
* wsock/common/encoding.c: Fixed query on program side encoding
|
||||
* wsock/common/convert.c : Fixed setting program side encoding
|
||||
|
||||
2000-11-02
|
||||
* lib/util.c, include/mdn/util.h: created.
|
||||
* lib/race.c, tools/mdnconv/util.c: make use of the above util
|
||||
module.
|
||||
* DISTFILES, include/mdn/Makefile.in, lib/Makefile.in,
|
||||
tools/runmdn/Makefile.in, lib/make.wnt, lib/make.os2: add
|
||||
util.[ch].
|
||||
* lib/Makefile.in, tools/runmdn/Makefile.in: increase revision
|
||||
number.
|
||||
* tools/runmdn/Makefile.in: use INSTALL_SCRIPT rather than
|
||||
INSTALL_PROGRAM for shell script installation.
|
||||
* tools/rpm/mdnkit.spec: increase version and serial.
|
||||
* Makefile.in: change package name to mdnkit-1.1-src. add patch
|
||||
target.
|
||||
* DISTFILES: add ChangeLog and NEWS.
|
||||
* lib/msgtrans.c: remove extra semicolon at the end of #undef
|
||||
line.
|
||||
* tools/rpm/mdnkit.spec: update for version 1.1.
|
||||
* README, README.ja: update for version 1.1.
|
||||
* version 1.1 release.
|
||||
|
||||
2000-11-01
|
||||
* lib/race.c, tools/mdnconv/util.c: fix race prefix matching bug.
|
||||
Previously, matching failed if the prefix contains any uppercase
|
||||
letters (such as Bq--),
|
||||
|
||||
2000-10-31
|
||||
* dnsproxy/dnsproxy.8: fix typo.
|
||||
* dnsproxy/dnsproxy.conf.sample: add log-level entry. correct
|
||||
description of the behavior when log-file is not specified.
|
||||
* NEWS: created.
|
||||
|
||||
2000-10-30
|
||||
* patch/bind9/bind-9.0.0-patch (lib/dns/config/confparser.y):
|
||||
typo fixed.
|
||||
|
||||
2000-10-27
|
||||
* dnsproxy/Makefile.in: remove -DDEBUG.
|
||||
* dnsproxy/logging.c: supply default log file if not specfied.
|
||||
* dnsproxy/translate.c: make the log correctly display "tcp" or
|
||||
"udp" instead of "unknown". fix typo.
|
||||
* dnsproxy/winserv.c: comment out message logging code because
|
||||
they are also recorded in event logger.
|
||||
|
||||
2000-10-26
|
||||
* dnsproxy/config.c: stop redefining logging macros (since it's
|
||||
not needed). use fprintf instead of log_printf for logging (since
|
||||
log file is not yet determined at this stage).
|
||||
* dnsproxy/dnsproxy.8: add description on log-level entry.
|
||||
mention about SIGHUP feature.
|
||||
* dnsproxy/dnsproxy.h: add log-level constants. change log macro
|
||||
definitions. add prototypes for new logging functions.
|
||||
* dnsproxy/logging.c: add log-level setting feature, including new
|
||||
logging interface functions and log-level entry in the
|
||||
configuration file. add log file turnover support
|
||||
(close and reopen the file when receiving SIGHUP)
|
||||
* dnsproxy/server.c: ignore transient errors such as EAGAIN or
|
||||
EINTR. do not quit server process even if recvfrom returns
|
||||
ECONNREFUSED, which seems to happen on Linux. Same for
|
||||
ENETUNREACH and EHOSTUNREACH.
|
||||
* dnsproxy/translate.c: make mdn_log_level_info messages are
|
||||
logged at 'warn' level instead of 'trace' level.
|
||||
* dnsproxy/unxmain.c: add handler for SIGHUP.
|
||||
|
||||
2000-10-25
|
||||
* lib/utf8.c: fix mdn_utf8_getmb so that it returns correct
|
||||
value.
|
||||
|
||||
2000-10-24
|
||||
* dnsproxy/server.c: don't terminate server process even if
|
||||
recvfrom (on UDP socket) returns 0.
|
||||
* tools/mdnconv/mdnconv.1: correct syntax of -noconf option.
|
||||
|
||||
2000-10-23
|
||||
* dnsproxy/message.c: fix DNS message ID allocation bug (only
|
||||
4096 IDs out of 65536 could be used before). release internal
|
||||
data structure for each request when receiving reply (previously
|
||||
it is kept for 10 minutes, causing large memory footprint for
|
||||
busy servers). add some debug statements.
|
||||
* dnsproxy/server.c: increase interval for calling timer dispatch
|
||||
routine (1sec -> 10sec).
|
||||
|
||||
2000-10-08
|
||||
* version 1.0 release
|
||||
55
contrib/idn/mdnkit/LICENSE.txt
Normal file
55
contrib/idn/mdnkit/LICENSE.txt
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
Tokyo, Japan.
|
||||
|
||||
1. Use, Modification and Redistribution (including distribution of any
|
||||
modified or derived work) in source and/or binary forms is permitted
|
||||
under this License Terms and Conditions.
|
||||
|
||||
2. Redistribution of source code must retain the copyright notices as they
|
||||
appear in each source code file, this License Terms and Conditions.
|
||||
|
||||
3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
this License Terms and Conditions, in the documentation and/or other
|
||||
materials provided with the distribution. For the purposes of binary
|
||||
distribution the "Copyright Notice" refers to the following language:
|
||||
"Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
|
||||
4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
derived from this Software without specific prior written approval of
|
||||
JPNIC.
|
||||
|
||||
5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
6. Indemnification by Licensee
|
||||
Any person or entities using and/or redistributing this Software under
|
||||
this License Terms and Conditions shall defend indemnify and hold
|
||||
harmless JPNIC from and against any and all judgements damages,
|
||||
expenses, settlement liabilities, cost and other liabilities of any
|
||||
kind as a result of use and redistribution of this Software or any
|
||||
claim, suite, action, litigation or proceeding by any third party
|
||||
arising out of or relates to this License Terms and Conditions.
|
||||
|
||||
7. Governing Law, Jurisdiction and Venue
|
||||
This License Terms and Conditions shall be governed by and and
|
||||
construed in accordance with the law of Japan. Any person or entities
|
||||
using and/or redistributing this Software under this License Terms and
|
||||
Conditions hereby agrees and consent to the personal and exclusive
|
||||
jurisdiction and venue of Tokyo District Court of Japan.
|
||||
87
contrib/idn/mdnkit/Makefile.in
Normal file
87
contrib/idn/mdnkit/Makefile.in
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
# $Id: Makefile.in,v 1.31 2000/11/27 01:58:31 ishisone 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
# Tokyo, Japan.
|
||||
#
|
||||
# 1. Use, Modification and Redistribution (including distribution of any
|
||||
# modified or derived work) in source and/or binary forms is permitted
|
||||
# under this License Terms and Conditions.
|
||||
#
|
||||
# 2. Redistribution of source code must retain the copyright notices as they
|
||||
# appear in each source code file, this License Terms and Conditions.
|
||||
#
|
||||
# 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
# this License Terms and Conditions, in the documentation and/or other
|
||||
# materials provided with the distribution. For the purposes of binary
|
||||
# distribution the "Copyright Notice" refers to the following language:
|
||||
# "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
#
|
||||
# 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
# derived from this Software without specific prior written approval of
|
||||
# JPNIC.
|
||||
#
|
||||
# 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
#
|
||||
# 6. Indemnification by Licensee
|
||||
# Any person or entities using and/or redistributing this Software under
|
||||
# this License Terms and Conditions shall defend indemnify and hold
|
||||
# harmless JPNIC from and against any and all judgements damages,
|
||||
# expenses, settlement liabilities, cost and other liabilities of any
|
||||
# kind as a result of use and redistribution of this Software or any
|
||||
# claim, suite, action, litigation or proceeding by any third party
|
||||
# arising out of or relates to this License Terms and Conditions.
|
||||
#
|
||||
# 7. Governing Law, Jurisdiction and Venue
|
||||
# This License Terms and Conditions shall be governed by and and
|
||||
# construed in accordance with the law of Japan. Any person or entities
|
||||
# using and/or redistributing this Software under this License Terms and
|
||||
# Conditions hereby agrees and consent to the personal and exclusive
|
||||
# jurisdiction and venue of Tokyo District Court of Japan.
|
||||
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
prefix = @prefix@
|
||||
exec_prefix = @exec_prefix@
|
||||
|
||||
SUBDIRS = include lib dnsproxy man tools
|
||||
|
||||
CUR_VERSION = 1.2
|
||||
PREV_VERSION = 1.1
|
||||
PREV_TAG = REL_1_1
|
||||
|
||||
DISTFILE = mdnkit-$(CUR_VERSION)-src
|
||||
PATCHFILE = mdnkit-$(PREV_VERSION)-$(CUR_VERSION)-src-patch
|
||||
|
||||
all:
|
||||
for d in $(SUBDIRS); do (cd $$d; $(MAKE) all); done
|
||||
|
||||
install:
|
||||
for d in $(SUBDIRS); do (cd $$d; $(MAKE) install); done
|
||||
|
||||
clean:
|
||||
for d in $(SUBDIRS); do (cd $$d; $(MAKE) clean); done
|
||||
|
||||
dist:
|
||||
cd $(srcdir); mktarpkg --gzip=9 $(DISTFILE)
|
||||
|
||||
patch:
|
||||
cd $(srcdir); mkcvspatch --gzip=9 --header=patch.header \
|
||||
--from=$(PREV_TAG) $(PATCHFILE)
|
||||
58
contrib/idn/mdnkit/NEWS
Normal file
58
contrib/idn/mdnkit/NEWS
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
; $Id: NEWS,v 1.5 2000/11/21 09:03:23 ishisone Exp $
|
||||
|
||||
Major changes in version 1.2:
|
||||
|
||||
* New encoding converters for `BRACE' and `LACE' are implemented.
|
||||
|
||||
* New normalize schemes `ja-compose-voiced-sound', 'ja-kana-fullwidth'
|
||||
and 'ja-alnum-halfwidth' introduced.
|
||||
|
||||
* mDN Wrapper is thoroughly overhauled.
|
||||
- Log level can be specified by using GUI (or directly editing the
|
||||
registry Software\JPNIC\MDN\LogLevel). Note that fine grain
|
||||
control over logging is supported only by the MDN library (libmdn).
|
||||
Log output from mDN Wrapper itself can be turned on or off, but
|
||||
no log level support.
|
||||
- Log file can also specified.
|
||||
- Some serious bugs are fixed, including incorrect program-side
|
||||
encoding (codeset) detection.
|
||||
- Advanced configuration feature implemented. Now DNS encoding and
|
||||
normalization can be customizable. Also you can configure which
|
||||
winsock DLL to be wrapped.
|
||||
|
||||
* dnsproxy and mDN Wrapper now correctly accept and process client-
|
||||
supplied domain names encoded in the alternate encoding. Previously
|
||||
worked correctly only when the alternate encoding happened to be the
|
||||
same as the server encoding.
|
||||
|
||||
* 8bit-through patch for BIND-8.2.2-P5 is replaced by a new patch
|
||||
for BIND-8.2.2-P7.
|
||||
|
||||
* A buffer overrun bug in RACE converter is fixed.
|
||||
|
||||
|
||||
Major changes in version 1.1:
|
||||
|
||||
* Log level of dnsproxy can be specified with ``log-level'' entry.
|
||||
available levels are `none', `fatal', `warning' and `trace'. See
|
||||
dnsproxy.8 or dnsproxy.conf.sample for details.
|
||||
|
||||
* Sending SIGHUP to dnsproxy causes it to close and re-open the log file.
|
||||
Useful for log file turnover.
|
||||
|
||||
* If log file is not specified, dnsproxy uses the default log file
|
||||
/tmp/dnsproxy.log. Previously behavior was that no logging was done
|
||||
at all, conflicting with what document says.
|
||||
|
||||
* dnsproxy won't terminate even if recvfrom() returns unexpected
|
||||
errors such as `connection refused (ECONNREFUSED)'. On Linux, it is
|
||||
reported that it sometimes returns this error even for
|
||||
connection-less (ie UDP) sockets.
|
||||
|
||||
* DNS message ID allocation/release bugs in dnsproxy are fixed.
|
||||
Previously dnsproxy seems to stop working if it receives more than
|
||||
4096 requests in 10 minutes.
|
||||
|
||||
* RACE conversion bug is fixed. Previously, if the prefix part contains
|
||||
any uppercase letters (such as "Bq--"), it is not recognized as a
|
||||
RACE prefix.
|
||||
304
contrib/idn/mdnkit/README
Normal file
304
contrib/idn/mdnkit/README
Normal file
|
|
@ -0,0 +1,304 @@
|
|||
|
||||
mDNkit
|
||||
-- multilingual domain name evaluation kit --
|
||||
version 1.2
|
||||
Japan Network Information Center (JPNIC)
|
||||
|
||||
|
||||
* Overview
|
||||
|
||||
mDNkit is a kit for evaluating various proposed methods regarding
|
||||
multilingualized/internationalized DNS. To handle multilingualized
|
||||
domain name, the following features are required:
|
||||
+ encoding conversion of domain names between
|
||||
the encoding application uses (local encoding) and
|
||||
the encoding on DNS protocol.
|
||||
+ normalization of domain names.
|
||||
mDNkit provides several ways for adding these features.
|
||||
|
||||
This kit consists of following components.
|
||||
|
||||
+ DNS proxy server (dnsproxy)
|
||||
This works as a fake DNS server for the clients. It receives
|
||||
DNS request containing domain names in the client's local
|
||||
encoding (e.g. Shift_JIS), translates them into the encoding
|
||||
on DNS protocol (e.g. UTF-8 or RACE), and forwards to the real
|
||||
DNS server. Also the response from the server is converted
|
||||
back to the client's local encoding and returned. See
|
||||
``1. using dnsproxy'' below.
|
||||
|
||||
+ a command dynamically adds MDN feature to unix applications (runmdn)
|
||||
This command enables normal applications to handle
|
||||
multilingual domain names by dynamically attaching special
|
||||
library to them. See ``2. using runmdn'' below.
|
||||
|
||||
+ a patch for BIND-9 that adds MDN capability
|
||||
This patch adds MDN capability to BIND9. BIND 9 employs a
|
||||
completely new name resolving scheme called ``light weight
|
||||
resolver'', consisting of client-side library (liblwres) and a
|
||||
name resolving daemon (lwresd). This patch adds MDN features
|
||||
to them. See ``3. using patched version of bind-9'' below.
|
||||
|
||||
+ mDN wrapper for Windows applications
|
||||
On windows, name resolving request is passed to WINSOCK DLL. So,
|
||||
replacing WINSOCK DLL with multi-lingual domain name version
|
||||
makes legacy windows applications compatible with mDN. This is
|
||||
wrapper DLL for WINSOCK's name resolving functions. See
|
||||
``4. using mDN wrapper'' below.
|
||||
|
||||
+ a codeset converter for named.conf/zone master files (mdnconv)
|
||||
This is a codeset (encoding) converter specially designed for
|
||||
converting named.conf and zone master files from your local
|
||||
encoding (e.g. EUC-JP) to the encoding which internationalized
|
||||
DNS servers employ (e.g. UTF-8).
|
||||
|
||||
+ libraries for handling multilingual domain names (libmdn, libmdnres)
|
||||
These are the basic libraries implementing encoding conversion
|
||||
and normalization. All the commands in this kit (such as
|
||||
dnsproxy and mdnconv) are built using these libraries.
|
||||
|
||||
+ a patch that makes BIND-8 8-bit through
|
||||
This is needed in order for named and resolver to handle
|
||||
non-ascii domain names encoded in local encoding or UTF-8.
|
||||
The patch is rudimentary; it makes almost any byte sequence
|
||||
legal as a domain name (which is what 8-bit through is for).
|
||||
|
||||
+ a patch for making Squid cache server 8-bit through
|
||||
This is a simple patch that disables Squid's validity check
|
||||
for host name part in URLs. Without this patch, Squid rejects
|
||||
URLs containing multilingual domain name (correctly).
|
||||
|
||||
|
||||
This kit provides several ways to handle multilingual domain names
|
||||
using above components.
|
||||
|
||||
** 1. using dnsproxy
|
||||
|
||||
domain name encoding domain name
|
||||
in local conversion and in encoding
|
||||
+------------+ encoding normalization on DNS
|
||||
| client | +----------------+ protocol +----------+
|
||||
|application |------------>| dnsproxy |------------>|DNS server|
|
||||
| with |<------------| |<------------| |
|
||||
|8bit through| +----------------+ +----------+
|
||||
| resolver |
|
||||
+------------+
|
||||
|
||||
** 2. using runmdn
|
||||
|
||||
encoding domain name
|
||||
conversion and in encoding
|
||||
normalization on DNS
|
||||
+-----------+-------------+ protocol
|
||||
| client | dynamically | +----------+
|
||||
|application| attached |---------------->|DNS server|
|
||||
|with normal| library |<----------------| |
|
||||
| resolver | (libmdnres) | +----------+
|
||||
+-----------+-------------+
|
||||
|
||||
** 3. using patched version of bind-9
|
||||
|
||||
domain name normalization domain name
|
||||
in UTF-8 and encoding in encoding
|
||||
+------------+ encoding conversion on DNS
|
||||
| client | +----------------+ protocol +----------+
|
||||
|application |------------>| light weight |------------>|DNS server|
|
||||
|with bind9's|<------------| resolver |<------------| |
|
||||
|light weight| | daemon | +----------+
|
||||
| resolver | +----------------+
|
||||
+------------+
|
||||
|
||||
** 4. using mDN wrapper
|
||||
|
||||
domain name normalization domain name
|
||||
in local and encoding in ecnoding
|
||||
+-----------+ encoding conversion on DNS
|
||||
| legacy | +---------+---------+ protocol +----------+
|
||||
| windows |------------>| mDN | orignal |---------->|DNS server|
|
||||
| network |<------------| wrapper | winsock |<----------| |
|
||||
|application| +---------+---------+ +----------+
|
||||
+-----------+
|
||||
|
||||
* Directory structure of this distribution
|
||||
|
||||
Below is a directory structure of this distribution with some
|
||||
important files and their brief description.
|
||||
|
||||
+README this file
|
||||
+README.ja .. in Japanese
|
||||
+DISTFILES list of files in this distribution
|
||||
+NEWS what's new in this version
|
||||
+ChangeLog list of changes
|
||||
+configure a `configure' script
|
||||
+Makefile.in toplevel makefile template
|
||||
+include/
|
||||
| +config.h.in template header file for configuration
|
||||
| +mdn/ header files for mdn library
|
||||
+dnsproxy/ source directory for DNS proxy server
|
||||
+lib/ source directory for mdn library
|
||||
+wsock/ source directory for mDN wrapper
|
||||
+tools/ source directory for tools
|
||||
| +mdnconv/ source directory for codeset converter
|
||||
| +runmdn/ source directory for runmdn command
|
||||
+patch/ various patch files
|
||||
| +bind8/ bind-8 patch directory
|
||||
| +bind9/ bind-9 patch directory
|
||||
| +squid/ squid patch directory
|
||||
+util/ utilities
|
||||
|
||||
|
||||
* Compilation and installation
|
||||
|
||||
0. Prerequisite
|
||||
|
||||
If your system's library does not have iconv() function, which is a
|
||||
general codeset conversion utility, install it as an external library.
|
||||
You also need external library if the system's implementation cannot
|
||||
handle UTF-8 encoding, or it doesn't support some encodings which your
|
||||
client applications uses.
|
||||
|
||||
You can get a free version of iconv() implementation (under LGPL
|
||||
license), from:
|
||||
|
||||
http://clisp.cons.org/~haible/packages-libiconv.html
|
||||
|
||||
1. Running configure script
|
||||
|
||||
Run `configure' script in the top directory. This checks various
|
||||
characteristics of your system and it will create Makefiles and
|
||||
config.h appropriate for your system.
|
||||
|
||||
% ./configure
|
||||
|
||||
`configure' accepts many options. Here is a list of some important
|
||||
options.
|
||||
|
||||
--with-iconv=LIB
|
||||
If your libc doesn't contain iconv(), specify the library
|
||||
that contains iconv(). For example, if iconv() is libiconv
|
||||
in /usr/local/lib, you should specify:
|
||||
|
||||
--with-iconv="-L/usr/local/lib -liconv"
|
||||
|
||||
Note that if the library is a shared one, you might also want to
|
||||
specify -R option, like:
|
||||
|
||||
--with-iconv="-L/usr/local/lib -R/usr/local/lib -liconv"
|
||||
|
||||
If the header file "iconv.h" has installed in a non-standard
|
||||
directory like /usr/local/include, you should specify CFLAGS
|
||||
environment variable. See below.
|
||||
|
||||
--with-iconv-sofile=PATH
|
||||
``runmdn'' command in this kit needs to know the pathname of
|
||||
shared library file that contains iconv(), if iconv() is not
|
||||
part of libc. mDNkit tries to find out the pathname from the
|
||||
informaiton provided by ``--with-iconv'' option described
|
||||
above. But when it fails, you have to specify it with this
|
||||
option, like:
|
||||
|
||||
--with-iconv-sofile=/usr/local/lib/libiconv.so.2.0
|
||||
|
||||
--with-utf8=NAME
|
||||
If your iconv() (precisely, iconv_open()) does not accept
|
||||
"UTF-8" as the name of UTF-8 encoding, specify the name for
|
||||
it. For example if your iconv() uses "utf8" instead, you
|
||||
should specify:
|
||||
|
||||
--with-utf8=utf8
|
||||
|
||||
--with-race-prefix=PREFIX
|
||||
--with-brace-suffix=SUFFIX
|
||||
--with-lace-prefix=PREFIX
|
||||
RACE (Row-based ASCII-Compatible Encoding), BRACE (Bi-mode
|
||||
Row-based ASCII-Compatible Encoding) and LACE (Length-based
|
||||
ASCII Compatible Encoding) are proposed encodings for
|
||||
multilingual domain name in DNS protocol data. They uses a
|
||||
fixed prefix (or suffix) string to distinguish names encoded
|
||||
by them from normal ASCII domain names. These prefix/suffix
|
||||
are defined by the current Internet Drafts and mDNkit uses
|
||||
them by default, but later version of the drafts may change
|
||||
them. In that case you can specify the prefix/suffix with
|
||||
these options.
|
||||
|
||||
--enable-zld
|
||||
The ZLD (zero level domain) support is disabled by default.
|
||||
If you want to try this feature, this option must be
|
||||
specified.
|
||||
|
||||
--sbindir=DIR
|
||||
Specifies the install directory for dnsproxy. Default is
|
||||
/usr/local/sbin.
|
||||
|
||||
--bindir=DIR
|
||||
Specifies the install directory for mdnconv and runmdn.
|
||||
Default is /usr/local/bin.
|
||||
|
||||
--sysconfdir=DIR
|
||||
Specifies the install directory for sample files of dnsproxy
|
||||
configuration and mDNkit's resolver configuration. Default is
|
||||
/usr/local/etc.
|
||||
|
||||
--mandir=DIR
|
||||
Specifies the base install directory for online manuals.
|
||||
Default is /usr/local/man.
|
||||
|
||||
`configure' has many more options. To see the list of available
|
||||
options, you should run it with --help option.
|
||||
|
||||
% ./configure --help
|
||||
|
||||
If you want to specify extra compiler options, like adding non-standard
|
||||
directory to include file search path, use environment variable CFLAGS.
|
||||
|
||||
% CFLAGS="-I/usr/local/include -O2" ./configure ... (for sh)
|
||||
% setenv CFLAGS "-I/usr/local/include -g"; ./configure ... (for csh)
|
||||
|
||||
2. Compiling
|
||||
|
||||
Run `make' for compilation.
|
||||
|
||||
% make
|
||||
|
||||
3. Installation
|
||||
|
||||
Run `make install' to install binaries and manuals. Don't forget to
|
||||
become a super-user before the installation.
|
||||
|
||||
% su
|
||||
# make install
|
||||
|
||||
4. Configuration and usage
|
||||
|
||||
Please consult online manuals for configuration and usage of `dnsproxy'
|
||||
`mdnconv', and `runmdn'. Also for `mdnconv' and `runmdn', please refer
|
||||
the manual of mDNkit's resolver configuration file `mdnres.conf'.
|
||||
|
||||
% man dnsproxy
|
||||
% man mdnconv
|
||||
% man runmdn
|
||||
% man mdnres.conf
|
||||
|
||||
|
||||
* Applying patches
|
||||
|
||||
This distribution also contains patches for BIND 8.2.2-P7,
|
||||
BIND 8.2.3-T6B, BIND 9.0.0 and Squid 2.3.STABLE3. The top of these
|
||||
patch files describe how to apply the patch and (re)install.
|
||||
|
||||
Note that on Solaris, "patch" command that comes with the system
|
||||
sometimes doesn't work correctly. You may want to install the GNU
|
||||
version of the command (http://www.gnu.org/software/patch/) and use
|
||||
it.
|
||||
|
||||
|
||||
* Contact information
|
||||
|
||||
Please see http//www.nic.ad.jp/jp/research/idn/ for the latest news
|
||||
about this kit.
|
||||
|
||||
Bug reports and comments on this kit should be sent to
|
||||
mdnkit-bugs@nic.ad.jp and idn-cmt@nic.ad.jp, respectively.
|
||||
|
||||
|
||||
; $Id: README,v 1.15 2000/11/21 07:54:13 ishisone Exp $
|
||||
300
contrib/idn/mdnkit/README.ja
Normal file
300
contrib/idn/mdnkit/README.ja
Normal file
|
|
@ -0,0 +1,300 @@
|
|||
|
||||
mDNkit
|
||||
-- 多言語ドメイン名評価キット --
|
||||
バージョン 1.2
|
||||
(社) 日本ネットワークインフォメーションセンター (JPNIC)
|
||||
|
||||
|
||||
* 概要
|
||||
|
||||
mDNkit とは DNS で多言語ドメイン名を扱うために提案されている各種の方式
|
||||
を評価するためのキットです。多言語ドメイン名を扱うためには、次のような
|
||||
機能が要求されます。
|
||||
|
||||
・アプリケーションが使用するエンコーディング (ローカルエンコーディング)
|
||||
と DNS プロトコル上のエンコーディングとの間の、ドメイン名のエンコー
|
||||
ディング変換。
|
||||
・ドメイン名の正規化。
|
||||
|
||||
mDNkit では、これらの機能を追加するための各種の方法を提供しています。
|
||||
|
||||
この配布キットには次のようなものが含まれます。
|
||||
|
||||
・DNSプロキシサーバ (dnsproxy)
|
||||
ドメイン名変換機能をもつ DNS のプロキシサーバです。クライアントから
|
||||
受信した DNS メッセージ中のドメイン名をクライアントのローカルエンコー
|
||||
ディングから DNS サーバの使用する DNS プロトコル上のエンコーディング
|
||||
へと変換して DNS サーバに送信します。また DNS サーバから返されたDNS
|
||||
メッセージ中のドメイン名をクライアントのローカルエンコーディングに戻
|
||||
してクライアントに返します。詳しくは、後述の「1. dnsproxy を使う」を
|
||||
御覧ください。
|
||||
|
||||
・UNIX アプリケーションに MDN 機能を動的に追加するコマンド (runmdn)
|
||||
UNIX の通常のアプリケーションで多言語ドメイン名を取り扱うために、特
|
||||
別なライブラリを動的にリンクするためのコマンドです。詳しくは、後述の
|
||||
「2. runmdn を使う」を御覧ください。
|
||||
|
||||
・bind-9 に MDN 機能を追加するパッチ
|
||||
bind-9 に MDN の機能を追加するパッチです。bind-9 では、クライアント
|
||||
側のライブラリ (liblwres) と、新しい名前解決用デーモン (lwresd) から
|
||||
成る、ライトウエイトリゾルバという全く新しい名前解決の方法が使われて
|
||||
います。このパッチは、これらに MDN の機能を追加します。詳しくは、後
|
||||
述の「3. bind9 にパッチを当てて使う」を御覧ください。
|
||||
|
||||
・Windows アプリケーション用の mDN ラッパー
|
||||
WINSOCK の名前解決機能に対するラッパー DLL です。Windows 上では、名
|
||||
前解決の要求は、WINSOCK DLL を通して行われます。そこで、これを多言語
|
||||
ドメイン用の WINSOCK DLL に置き換えることで、従来の Windows アプリケー
|
||||
ションでも mDN 機能を使用できるようにします。詳しくは、後述の
|
||||
「4. mDN ラッパーを使う」を御覧ください。
|
||||
|
||||
・named.conf およびゾーンマスタファイル用コードセットコンバータ (mdnconv)
|
||||
named.conf およびゾーンマスタファイルを対象としたコードセット (エン
|
||||
コーディング)変換用ツールです。SJIS などのローカルエンコーディングで
|
||||
書かれたこれらのファイルを、多言語化 DNS で使用するエンコーディング
|
||||
(例えばUTF-8) へと変換します。
|
||||
|
||||
・多言語ドメイン名を処理するためのライブラリ (libmdn, libmdnres)
|
||||
dnsproxy や mdnconv が利用しているライブラリです。エンコーディング変
|
||||
換や正規化、ZLD (zero-level domain) の処理等の機能を提供します。
|
||||
|
||||
・bind-8 を 8 ビットスルー化するパッチ
|
||||
named やリゾルバでローカルエンコーディングや UTF-8 エンコーディング
|
||||
のドメイン名を使用可能にするためのパッチです。8ビットスルーなのでほ
|
||||
とんどどんなコードでも通ってしまいます。
|
||||
|
||||
・squid を 8 ビットスルー化するパッチ
|
||||
URL 中のホスト名に関する正当性チェックを外すためのパッチです。このパッ
|
||||
チを当てないと Squid は多言語ドメイン名を含む URL をエラーとしてはじ
|
||||
いてしまいます。
|
||||
|
||||
|
||||
この配布キットは、以上のものを用いて、多言語ドメイン名を扱うための複数
|
||||
の方法を提供しています。
|
||||
|
||||
** 1. dnsproxy を使う
|
||||
|
||||
ローカルエン エンコーディン DNS プロトコル上の
|
||||
コードィング グ変換および正 エンコーディングの
|
||||
+----------------+のドメイン名 規化 ドメイン名
|
||||
|クライアント | +--------------+ +------+
|
||||
|アプリケーション|------------>| dnsproxy |------------>| DNS |
|
||||
|と 8ビットスルー|<------------| |<------------|サーバ|
|
||||
|化したリゾルバ | +--------------+ +------+
|
||||
+----------------+
|
||||
|
||||
** 2. runmdn を使う
|
||||
|
||||
エンコーディング変換 DNS プロトコル上の
|
||||
および正規化 エンコーディングの
|
||||
+----------------+------------------+ ドメイン名
|
||||
|クライアント |動的にリンクされた| +------+
|
||||
|アプリケーション| ライブラリ |---------------->| DNS |
|
||||
|と通常のリゾルバ| (libmdnres) |<----------------|サーバ|
|
||||
+----------------+------------------+ +------+
|
||||
|
||||
** 3. bind9 にパッチを当てて使う
|
||||
|
||||
UTF-8 のド エンコーディ DNS プロトコル上の
|
||||
メイン名 ング変換およ エンコーディングの
|
||||
+----------------+ び正規化 ドメイン名
|
||||
|クライアント | +----------------+ +------+
|
||||
|アプリケーション|---------->| ライトウェイト |------------>| DNS |
|
||||
|と bind9のライト|-----------| リゾルバ |<------------|サーバ|
|
||||
|ウェイトリゾルバ| | デーモン | +------+
|
||||
+----------------+ +----------------+
|
||||
|
||||
** 4. mDN ラッパーを使う
|
||||
|
||||
ローカルエ 正規化および DNS プロトコル上の
|
||||
ンコーディ エンコーディ エンコーディングの
|
||||
+----------------+ ングのドメ ング変換 ドメイン名
|
||||
|従来の Windows | イン名 +---------+------------+ +------+
|
||||
|ネットワーク |---------->| mDN | オリジナル |---------->| DNS |
|
||||
|アプリケーション|<----------| ラッパー| winsock |<----------|サーバ|
|
||||
+----------------+ +---------+------------+ +------+
|
||||
|
||||
|
||||
* ディレクトリ構成
|
||||
|
||||
配布キットのディレクトリ構成と、主要なファイルを示します。
|
||||
|
||||
README 英語版の README
|
||||
README.ja このファイル
|
||||
DISTFILES 配布されるファイル一覧
|
||||
NEWS 主な変更
|
||||
ChangeLog 変更詳細
|
||||
configure configure スクリプト
|
||||
Makefile.in トップレベルの Makefile のテンプレート
|
||||
include/ インクルードファイルディレクトリ
|
||||
config.h.in config.h のテンプレート
|
||||
mdn/ mdn ライブラリ用インクルードファイル
|
||||
dnsproxy/ DNS プロキシサーバソース
|
||||
lib/ mdn ライブラリソース
|
||||
wsock/ mDN ラッパーソース
|
||||
tools/ 周辺ツール
|
||||
mdnconv/ コードセットコンバータソース
|
||||
runmdn/ runmdn コマンドソース
|
||||
patch/ 各種パッチファイル
|
||||
bind8/ bind8 用パッチ
|
||||
bind9/ bind9 用パッチ
|
||||
squid/ squid 用パッチ
|
||||
util/ ユーティリティ
|
||||
|
||||
|
||||
* コンパイルおよびインストール
|
||||
|
||||
0. 前準備
|
||||
|
||||
もしあなたの使用しているシステムのライブラリに iconv() がない場合、あ
|
||||
るいはあっても UTF-8 を扱うことができない場合にはあらかじめ iconv() を
|
||||
インストールしておいてください。iconv() の実装は、例えば LGPL のものが
|
||||
|
||||
http://clisp.cons.org/~haible/packages-libiconv.html
|
||||
|
||||
から入手可能です。
|
||||
|
||||
1. configure スクリプトの実行
|
||||
|
||||
トップディレクトリにある configure スクリプトを実行してください。
|
||||
|
||||
% ./configure
|
||||
|
||||
configure スクリプトにはいくつかのオプションを指定することができます。
|
||||
mdn に直接関係するものは次の通りです。
|
||||
|
||||
--with-iconv=LIB
|
||||
libc に iconv が入っていない場合 (上記のパッケージを入れた
|
||||
場合など) に、iconv のライブラリを指定します。例えば
|
||||
|
||||
--with-iconv="-L/usr/local/lib -liconv"
|
||||
|
||||
のように指定します。もし iconv が共有ライブラリになっている
|
||||
場合には、-R オプションも指定して
|
||||
|
||||
--with-iconv="-L/usr/local/lib -R/usr/local/lib -liconv"
|
||||
|
||||
とする必要があるかもしれません。
|
||||
|
||||
--with-iconv-sofile=PATH
|
||||
mDNkit に含まれている runmdn コマンドは、iconv() が libc の一
|
||||
部として提供されないときに、iconv() を含む共有ライブラリへのパ
|
||||
ス名を知る必要があります。mDNkit は、--with-iconv オプションの
|
||||
記述を基にパス名を検索しますが、これに失敗したときに、以下のよ
|
||||
うに共有ライブラリを指定することができます。
|
||||
|
||||
--with-iconv-sofile=/usr/local/lib/libiconvv.so.2.0
|
||||
|
||||
--with-utf8=NAME
|
||||
iconv に utf-8 エンコーディングを指定する場合、本ライブラリは
|
||||
デフォルトでは "UTF-8" という名前を指定します。もしあなたの
|
||||
システムの iconv が "UTF-8" という名前を受け付けない場合には、
|
||||
代りの名前を指定します。例えば "UTF-8" ではなく "utf8" の
|
||||
場合には次のように指定します。
|
||||
|
||||
--with-utf8=utf8
|
||||
|
||||
--with-race-prefix=PREFIX
|
||||
--with-brace-suffix=SUFFIX
|
||||
--with-lace-prefix=PREFIX
|
||||
RACE (Row-based ASCII-Compatible Encoding)、BRACE (Bi-mode
|
||||
Row-based ASCII-Compatible Encoding) および LACE (Length-based
|
||||
ASCII Compatible Encoding) はいずれも DNS プロトコル
|
||||
上で使用される多言語ドメイン名に関して提案されているエンコーディ
|
||||
ング方式です。通常の ASCII ドメイン名とこれらによってエンコー
|
||||
ドされたドメイン名を区別するために、固定の接頭辞 (BRACE の場合
|
||||
には接尾辞) が用いられます。
|
||||
|
||||
mDNkit では現在のインターネットドラフトで定義されている接頭辞
|
||||
あるいは接尾辞を使用するようになっていますが、今後のドラフトで
|
||||
変わるかもしれません。そこで、これらのオプションを用いて指定で
|
||||
きるようになっています。
|
||||
|
||||
--enable-zld
|
||||
ZLD (zero level domain) は、デフォルトでは使用できません。この
|
||||
機能を使用したいときに、このオプションを指定します。
|
||||
|
||||
--sbindir=DIR
|
||||
DNS プロキシサーバをインストールするディレクトリを指定します。
|
||||
デフォルトでは /usr/local/sbin です。
|
||||
|
||||
--bindir=DIR
|
||||
コードセットコンバータ mdnconv をインストールするディレクトリを
|
||||
指定します。デフォルトでは /usr/local/bin です。
|
||||
|
||||
--sysconfdir=DIR
|
||||
DNS プロキシサーバの設定ファイルをインストールするディレクトリを
|
||||
指定します。デフォルトでは /usr/local/etc です。
|
||||
|
||||
--mandir=DIR
|
||||
オンラインマニュアルのインストールディレクトリを指定します。
|
||||
デフォルトでは /usr/local/man です。
|
||||
|
||||
--with-iconv オプションではライブラリだけを指定します。もしインクルー
|
||||
ドファイル iconv.h がデフォルトのインクルードファイルのパスにインストー
|
||||
ルされていない場合、あるいは他に C コンパイラへのオプションを指定した
|
||||
い場合には環境変数 CFLAGS を使用してください。例えば
|
||||
|
||||
% CFLAGS=-I/usr/local/include ./configure ...
|
||||
(sh 系のシェルの場合)
|
||||
% setenv CFLAGS -I/usr/local/include; ./configure ...
|
||||
(csh 系のシェルの場合)
|
||||
|
||||
とします。
|
||||
|
||||
configure には他にも多くのオプションがありますが、残りは一般的なオプショ
|
||||
ンなので説明は省きます。
|
||||
|
||||
% ./configure --help
|
||||
|
||||
を実行するとオプションの一覧が表示されます。
|
||||
|
||||
2. コンパイル
|
||||
|
||||
configure を実行すると Makefile などが生成されますので、続けて makeを
|
||||
実行してコンパイルします。
|
||||
|
||||
% make
|
||||
|
||||
3. インストール
|
||||
|
||||
スーパユーザになってインストールします。
|
||||
|
||||
% su
|
||||
# make install
|
||||
|
||||
4. Configuration and usage
|
||||
|
||||
インストールされるツール (dnsproxy、mdnconv、runmdn) の使い方、設定方
|
||||
法に関してはオンラインマニュアルをご覧ください。mdnconv と runmdn につ
|
||||
いては、mDNkit のリゾルバ設定ファイル mdnres.conf のマニュアルも参照し
|
||||
てください。
|
||||
|
||||
% man dnsproxy
|
||||
% man mdnconv
|
||||
% man runmdn
|
||||
% man mdnres.conf
|
||||
|
||||
|
||||
* パッチの当て方
|
||||
|
||||
この配布キットには、bind-8.2.2-P7、bind-8.2.3-T6B、bind-9.0.0、および
|
||||
squid-2.3-STABLE3 に対するパッチが含まれています。パッチの当て方は、パッ
|
||||
チファイルの先頭に書かれていますのでそちらを参照してください。
|
||||
|
||||
Solaris では、システム付属の patch コマンドが正常に動作しないことがあ
|
||||
ります。そのような場合には、GNU バージョンの patch
|
||||
(http://www.gnu.org/software/patch/) をインストールして、これを使用し
|
||||
てください。
|
||||
|
||||
|
||||
* 本キットに関する最新情報、問い合わせについて
|
||||
|
||||
本キットに関する最新情報については、
|
||||
http://www.nic.ad.jp/jp/research/idn/ を参照してください
|
||||
|
||||
本キットに関するバグレポートおよびコメントは、それぞれ
|
||||
mdnkit-bugs@nic.ad.jp および idn-cmt@nic.ad.jp へお願いします。
|
||||
|
||||
|
||||
; $Id: README.ja,v 1.18 2000/11/21 07:54:13 ishisone Exp $
|
||||
77
contrib/idn/mdnkit/acconfig.h
Normal file
77
contrib/idn/mdnkit/acconfig.h
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
/* $Id: acconfig.h,v 1.4 2000/11/17 06:51:11 ishisone 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
@TOP@
|
||||
|
||||
/* Define if your iconv() does not accept "UTF-8" as the codeset name for utf-8. */
|
||||
#undef MDN_UTF8_ENCODING_NAME
|
||||
|
||||
/* Define if you want ZLD feature compiled in. */
|
||||
#undef MDN_SUPPORT_ZLD
|
||||
|
||||
/* Define if the prefix of RACE encoding differs from 'bq--'. */
|
||||
#undef MDN_RACE_PREFIX
|
||||
|
||||
/* Define if the suffix of BRACE encoding differs from '-8q9'. */
|
||||
#undef MDN_BRACE_SUFFIX
|
||||
|
||||
/* Define if the prefix of LACE encoding differs from 'bq--'. */
|
||||
#undef MDN_LACE_PREFIX
|
||||
|
||||
/* Define as an appropriate type (ex. int) if your system doesn't have. */
|
||||
#undef BOOL
|
||||
434
contrib/idn/mdnkit/aclocal.m4
vendored
Normal file
434
contrib/idn/mdnkit/aclocal.m4
vendored
Normal file
|
|
@ -0,0 +1,434 @@
|
|||
## libtool.m4 - Configure libtool for the target system. -*-Shell-script-*-
|
||||
## Copyright (C) 1996-1999, 2000 Free Software Foundation, Inc.
|
||||
## Originally by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
|
||||
##
|
||||
## This program is free software; you can redistribute it and/or modify
|
||||
## it under the terms of the GNU General Public License as published by
|
||||
## the Free Software Foundation; either version 2 of the License, or
|
||||
## (at your option) any later version.
|
||||
##
|
||||
## This program is distributed in the hope that it will be useful, but
|
||||
## WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
## General Public License for more details.
|
||||
##
|
||||
## You should have received a copy of the GNU General Public License
|
||||
## along with this program; if not, write to the Free Software
|
||||
## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
##
|
||||
## As a special exception to the GNU General Public License, if you
|
||||
## distribute this file as part of a program that contains a
|
||||
## configuration script generated by Autoconf, you may include it under
|
||||
## the same distribution terms that you use for the rest of that program.
|
||||
|
||||
# serial 40 AC_PROG_LIBTOOL
|
||||
AC_DEFUN(AC_PROG_LIBTOOL,
|
||||
[AC_REQUIRE([AC_LIBTOOL_SETUP])dnl
|
||||
|
||||
# Save cache, so that ltconfig can load it
|
||||
AC_CACHE_SAVE
|
||||
|
||||
# Actually configure libtool. ac_aux_dir is where install-sh is found.
|
||||
CC="$CC" CFLAGS="$CFLAGS" CPPFLAGS="$CPPFLAGS" \
|
||||
LD="$LD" LDFLAGS="$LDFLAGS" LIBS="$LIBS" \
|
||||
LN_S="$LN_S" NM="$NM" RANLIB="$RANLIB" \
|
||||
DLLTOOL="$DLLTOOL" AS="$AS" OBJDUMP="$OBJDUMP" \
|
||||
${CONFIG_SHELL-/bin/sh} $ac_aux_dir/ltconfig --no-reexec \
|
||||
$libtool_flags --no-verify $ac_aux_dir/ltmain.sh $lt_target \
|
||||
|| AC_MSG_ERROR([libtool configure failed])
|
||||
|
||||
# Reload cache, that may have been modified by ltconfig
|
||||
AC_CACHE_LOAD
|
||||
|
||||
# This can be used to rebuild libtool when needed
|
||||
LIBTOOL_DEPS="$ac_aux_dir/ltconfig $ac_aux_dir/ltmain.sh"
|
||||
|
||||
# Always use our own libtool.
|
||||
LIBTOOL='$(SHELL) $(top_builddir)/libtool'
|
||||
AC_SUBST(LIBTOOL)dnl
|
||||
|
||||
# Redirect the config.log output again, so that the ltconfig log is not
|
||||
# clobbered by the next message.
|
||||
exec 5>>./config.log
|
||||
])
|
||||
|
||||
AC_DEFUN(AC_LIBTOOL_SETUP,
|
||||
[AC_PREREQ(2.13)dnl
|
||||
AC_REQUIRE([AC_ENABLE_SHARED])dnl
|
||||
AC_REQUIRE([AC_ENABLE_STATIC])dnl
|
||||
AC_REQUIRE([AC_ENABLE_FAST_INSTALL])dnl
|
||||
AC_REQUIRE([AC_CANONICAL_HOST])dnl
|
||||
AC_REQUIRE([AC_CANONICAL_BUILD])dnl
|
||||
AC_REQUIRE([AC_PROG_RANLIB])dnl
|
||||
AC_REQUIRE([AC_PROG_CC])dnl
|
||||
AC_REQUIRE([AC_PROG_LD])dnl
|
||||
AC_REQUIRE([AC_PROG_NM])dnl
|
||||
AC_REQUIRE([AC_PROG_LN_S])dnl
|
||||
dnl
|
||||
|
||||
case "$target" in
|
||||
NONE) lt_target="$host" ;;
|
||||
*) lt_target="$target" ;;
|
||||
esac
|
||||
|
||||
# Check for any special flags to pass to ltconfig.
|
||||
libtool_flags="--cache-file=$cache_file"
|
||||
test "$enable_shared" = no && libtool_flags="$libtool_flags --disable-shared"
|
||||
test "$enable_static" = no && libtool_flags="$libtool_flags --disable-static"
|
||||
test "$enable_fast_install" = no && libtool_flags="$libtool_flags --disable-fast-install"
|
||||
test "$ac_cv_prog_gcc" = yes && libtool_flags="$libtool_flags --with-gcc"
|
||||
test "$ac_cv_prog_gnu_ld" = yes && libtool_flags="$libtool_flags --with-gnu-ld"
|
||||
ifdef([AC_PROVIDE_AC_LIBTOOL_DLOPEN],
|
||||
[libtool_flags="$libtool_flags --enable-dlopen"])
|
||||
ifdef([AC_PROVIDE_AC_LIBTOOL_WIN32_DLL],
|
||||
[libtool_flags="$libtool_flags --enable-win32-dll"])
|
||||
AC_ARG_ENABLE(libtool-lock,
|
||||
[ --disable-libtool-lock avoid locking (might break parallel builds)])
|
||||
test "x$enable_libtool_lock" = xno && libtool_flags="$libtool_flags --disable-lock"
|
||||
test x"$silent" = xyes && libtool_flags="$libtool_flags --silent"
|
||||
|
||||
# Some flags need to be propagated to the compiler or linker for good
|
||||
# libtool support.
|
||||
case "$lt_target" in
|
||||
*-*-irix6*)
|
||||
# Find out which ABI we are using.
|
||||
echo '[#]line __oline__ "configure"' > conftest.$ac_ext
|
||||
if AC_TRY_EVAL(ac_compile); then
|
||||
case "`/usr/bin/file conftest.o`" in
|
||||
*32-bit*)
|
||||
LD="${LD-ld} -32"
|
||||
;;
|
||||
*N32*)
|
||||
LD="${LD-ld} -n32"
|
||||
;;
|
||||
*64-bit*)
|
||||
LD="${LD-ld} -64"
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
rm -rf conftest*
|
||||
;;
|
||||
|
||||
*-*-sco3.2v5*)
|
||||
# On SCO OpenServer 5, we need -belf to get full-featured binaries.
|
||||
SAVE_CFLAGS="$CFLAGS"
|
||||
CFLAGS="$CFLAGS -belf"
|
||||
AC_CACHE_CHECK([whether the C compiler needs -belf], lt_cv_cc_needs_belf,
|
||||
[AC_TRY_LINK([],[],[lt_cv_cc_needs_belf=yes],[lt_cv_cc_needs_belf=no])])
|
||||
if test x"$lt_cv_cc_needs_belf" != x"yes"; then
|
||||
# this is probably gcc 2.8.0, egcs 1.0 or newer; no need for -belf
|
||||
CFLAGS="$SAVE_CFLAGS"
|
||||
fi
|
||||
;;
|
||||
|
||||
ifdef([AC_PROVIDE_AC_LIBTOOL_WIN32_DLL],
|
||||
[*-*-cygwin* | *-*-mingw*)
|
||||
AC_CHECK_TOOL(DLLTOOL, dlltool, false)
|
||||
AC_CHECK_TOOL(AS, as, false)
|
||||
AC_CHECK_TOOL(OBJDUMP, objdump, false)
|
||||
;;
|
||||
])
|
||||
esac
|
||||
])
|
||||
|
||||
# AC_LIBTOOL_DLOPEN - enable checks for dlopen support
|
||||
AC_DEFUN(AC_LIBTOOL_DLOPEN, [AC_BEFORE([$0],[AC_LIBTOOL_SETUP])])
|
||||
|
||||
# AC_LIBTOOL_WIN32_DLL - declare package support for building win32 dll's
|
||||
AC_DEFUN(AC_LIBTOOL_WIN32_DLL, [AC_BEFORE([$0], [AC_LIBTOOL_SETUP])])
|
||||
|
||||
# AC_ENABLE_SHARED - implement the --enable-shared flag
|
||||
# Usage: AC_ENABLE_SHARED[(DEFAULT)]
|
||||
# Where DEFAULT is either `yes' or `no'. If omitted, it defaults to
|
||||
# `yes'.
|
||||
AC_DEFUN(AC_ENABLE_SHARED, [dnl
|
||||
define([AC_ENABLE_SHARED_DEFAULT], ifelse($1, no, no, yes))dnl
|
||||
AC_ARG_ENABLE(shared,
|
||||
changequote(<<, >>)dnl
|
||||
<< --enable-shared[=PKGS] build shared libraries [default=>>AC_ENABLE_SHARED_DEFAULT],
|
||||
changequote([, ])dnl
|
||||
[p=${PACKAGE-default}
|
||||
case "$enableval" in
|
||||
yes) enable_shared=yes ;;
|
||||
no) enable_shared=no ;;
|
||||
*)
|
||||
enable_shared=no
|
||||
# Look at the argument we got. We use all the common list separators.
|
||||
IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:,"
|
||||
for pkg in $enableval; do
|
||||
if test "X$pkg" = "X$p"; then
|
||||
enable_shared=yes
|
||||
fi
|
||||
done
|
||||
IFS="$ac_save_ifs"
|
||||
;;
|
||||
esac],
|
||||
enable_shared=AC_ENABLE_SHARED_DEFAULT)dnl
|
||||
])
|
||||
|
||||
# AC_DISABLE_SHARED - set the default shared flag to --disable-shared
|
||||
AC_DEFUN(AC_DISABLE_SHARED, [AC_BEFORE([$0],[AC_LIBTOOL_SETUP])dnl
|
||||
AC_ENABLE_SHARED(no)])
|
||||
|
||||
# AC_ENABLE_STATIC - implement the --enable-static flag
|
||||
# Usage: AC_ENABLE_STATIC[(DEFAULT)]
|
||||
# Where DEFAULT is either `yes' or `no'. If omitted, it defaults to
|
||||
# `yes'.
|
||||
AC_DEFUN(AC_ENABLE_STATIC, [dnl
|
||||
define([AC_ENABLE_STATIC_DEFAULT], ifelse($1, no, no, yes))dnl
|
||||
AC_ARG_ENABLE(static,
|
||||
changequote(<<, >>)dnl
|
||||
<< --enable-static[=PKGS] build static libraries [default=>>AC_ENABLE_STATIC_DEFAULT],
|
||||
changequote([, ])dnl
|
||||
[p=${PACKAGE-default}
|
||||
case "$enableval" in
|
||||
yes) enable_static=yes ;;
|
||||
no) enable_static=no ;;
|
||||
*)
|
||||
enable_static=no
|
||||
# Look at the argument we got. We use all the common list separators.
|
||||
IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:,"
|
||||
for pkg in $enableval; do
|
||||
if test "X$pkg" = "X$p"; then
|
||||
enable_static=yes
|
||||
fi
|
||||
done
|
||||
IFS="$ac_save_ifs"
|
||||
;;
|
||||
esac],
|
||||
enable_static=AC_ENABLE_STATIC_DEFAULT)dnl
|
||||
])
|
||||
|
||||
# AC_DISABLE_STATIC - set the default static flag to --disable-static
|
||||
AC_DEFUN(AC_DISABLE_STATIC, [AC_BEFORE([$0],[AC_LIBTOOL_SETUP])dnl
|
||||
AC_ENABLE_STATIC(no)])
|
||||
|
||||
|
||||
# AC_ENABLE_FAST_INSTALL - implement the --enable-fast-install flag
|
||||
# Usage: AC_ENABLE_FAST_INSTALL[(DEFAULT)]
|
||||
# Where DEFAULT is either `yes' or `no'. If omitted, it defaults to
|
||||
# `yes'.
|
||||
AC_DEFUN(AC_ENABLE_FAST_INSTALL, [dnl
|
||||
define([AC_ENABLE_FAST_INSTALL_DEFAULT], ifelse($1, no, no, yes))dnl
|
||||
AC_ARG_ENABLE(fast-install,
|
||||
changequote(<<, >>)dnl
|
||||
<< --enable-fast-install[=PKGS] optimize for fast installation [default=>>AC_ENABLE_FAST_INSTALL_DEFAULT],
|
||||
changequote([, ])dnl
|
||||
[p=${PACKAGE-default}
|
||||
case "$enableval" in
|
||||
yes) enable_fast_install=yes ;;
|
||||
no) enable_fast_install=no ;;
|
||||
*)
|
||||
enable_fast_install=no
|
||||
# Look at the argument we got. We use all the common list separators.
|
||||
IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:,"
|
||||
for pkg in $enableval; do
|
||||
if test "X$pkg" = "X$p"; then
|
||||
enable_fast_install=yes
|
||||
fi
|
||||
done
|
||||
IFS="$ac_save_ifs"
|
||||
;;
|
||||
esac],
|
||||
enable_fast_install=AC_ENABLE_FAST_INSTALL_DEFAULT)dnl
|
||||
])
|
||||
|
||||
# AC_ENABLE_FAST_INSTALL - set the default to --disable-fast-install
|
||||
AC_DEFUN(AC_DISABLE_FAST_INSTALL, [AC_BEFORE([$0],[AC_LIBTOOL_SETUP])dnl
|
||||
AC_ENABLE_FAST_INSTALL(no)])
|
||||
|
||||
# AC_PROG_LD - find the path to the GNU or non-GNU linker
|
||||
AC_DEFUN(AC_PROG_LD,
|
||||
[AC_ARG_WITH(gnu-ld,
|
||||
[ --with-gnu-ld assume the C compiler uses GNU ld [default=no]],
|
||||
test "$withval" = no || with_gnu_ld=yes, with_gnu_ld=no)
|
||||
AC_REQUIRE([AC_PROG_CC])dnl
|
||||
AC_REQUIRE([AC_CANONICAL_HOST])dnl
|
||||
AC_REQUIRE([AC_CANONICAL_BUILD])dnl
|
||||
ac_prog=ld
|
||||
if test "$ac_cv_prog_gcc" = yes; then
|
||||
# Check if gcc -print-prog-name=ld gives a path.
|
||||
AC_MSG_CHECKING([for ld used by GCC])
|
||||
ac_prog=`($CC -print-prog-name=ld) 2>&5`
|
||||
case "$ac_prog" in
|
||||
# Accept absolute paths.
|
||||
changequote(,)dnl
|
||||
[\\/]* | [A-Za-z]:[\\/]*)
|
||||
re_direlt='/[^/][^/]*/\.\./'
|
||||
changequote([,])dnl
|
||||
# Canonicalize the path of ld
|
||||
ac_prog=`echo $ac_prog| sed 's%\\\\%/%g'`
|
||||
while echo $ac_prog | grep "$re_direlt" > /dev/null 2>&1; do
|
||||
ac_prog=`echo $ac_prog| sed "s%$re_direlt%/%"`
|
||||
done
|
||||
test -z "$LD" && LD="$ac_prog"
|
||||
;;
|
||||
"")
|
||||
# If it fails, then pretend we aren't using GCC.
|
||||
ac_prog=ld
|
||||
;;
|
||||
*)
|
||||
# If it is relative, then search for the first ld in PATH.
|
||||
with_gnu_ld=unknown
|
||||
;;
|
||||
esac
|
||||
elif test "$with_gnu_ld" = yes; then
|
||||
AC_MSG_CHECKING([for GNU ld])
|
||||
else
|
||||
AC_MSG_CHECKING([for non-GNU ld])
|
||||
fi
|
||||
AC_CACHE_VAL(ac_cv_path_LD,
|
||||
[if test -z "$LD"; then
|
||||
IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}${PATH_SEPARATOR-:}"
|
||||
for ac_dir in $PATH; do
|
||||
test -z "$ac_dir" && ac_dir=.
|
||||
if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then
|
||||
ac_cv_path_LD="$ac_dir/$ac_prog"
|
||||
# Check to see if the program is GNU ld. I'd rather use --version,
|
||||
# but apparently some GNU ld's only accept -v.
|
||||
# Break only if it was the GNU/non-GNU ld that we prefer.
|
||||
if "$ac_cv_path_LD" -v 2>&1 < /dev/null | egrep '(GNU|with BFD)' > /dev/null; then
|
||||
test "$with_gnu_ld" != no && break
|
||||
else
|
||||
test "$with_gnu_ld" != yes && break
|
||||
fi
|
||||
fi
|
||||
done
|
||||
IFS="$ac_save_ifs"
|
||||
else
|
||||
ac_cv_path_LD="$LD" # Let the user override the test with a path.
|
||||
fi])
|
||||
LD="$ac_cv_path_LD"
|
||||
if test -n "$LD"; then
|
||||
AC_MSG_RESULT($LD)
|
||||
else
|
||||
AC_MSG_RESULT(no)
|
||||
fi
|
||||
test -z "$LD" && AC_MSG_ERROR([no acceptable ld found in \$PATH])
|
||||
AC_PROG_LD_GNU
|
||||
])
|
||||
|
||||
AC_DEFUN(AC_PROG_LD_GNU,
|
||||
[AC_CACHE_CHECK([if the linker ($LD) is GNU ld], ac_cv_prog_gnu_ld,
|
||||
[# I'd rather use --version here, but apparently some GNU ld's only accept -v.
|
||||
if $LD -v 2>&1 </dev/null | egrep '(GNU|with BFD)' 1>&5; then
|
||||
ac_cv_prog_gnu_ld=yes
|
||||
else
|
||||
ac_cv_prog_gnu_ld=no
|
||||
fi])
|
||||
])
|
||||
|
||||
# AC_PROG_NM - find the path to a BSD-compatible name lister
|
||||
AC_DEFUN(AC_PROG_NM,
|
||||
[AC_MSG_CHECKING([for BSD-compatible nm])
|
||||
AC_CACHE_VAL(ac_cv_path_NM,
|
||||
[if test -n "$NM"; then
|
||||
# Let the user override the test.
|
||||
ac_cv_path_NM="$NM"
|
||||
else
|
||||
IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}${PATH_SEPARATOR-:}"
|
||||
for ac_dir in $PATH /usr/ccs/bin /usr/ucb /bin; do
|
||||
test -z "$ac_dir" && ac_dir=.
|
||||
if test -f $ac_dir/nm || test -f $ac_dir/nm$ac_exeext ; then
|
||||
# Check to see if the nm accepts a BSD-compat flag.
|
||||
# Adding the `sed 1q' prevents false positives on HP-UX, which says:
|
||||
# nm: unknown option "B" ignored
|
||||
if ($ac_dir/nm -B /dev/null 2>&1 | sed '1q'; exit 0) | egrep /dev/null >/dev/null; then
|
||||
ac_cv_path_NM="$ac_dir/nm -B"
|
||||
break
|
||||
elif ($ac_dir/nm -p /dev/null 2>&1 | sed '1q'; exit 0) | egrep /dev/null >/dev/null; then
|
||||
ac_cv_path_NM="$ac_dir/nm -p"
|
||||
break
|
||||
else
|
||||
ac_cv_path_NM=${ac_cv_path_NM="$ac_dir/nm"} # keep the first match, but
|
||||
continue # so that we can try to find one that supports BSD flags
|
||||
fi
|
||||
fi
|
||||
done
|
||||
IFS="$ac_save_ifs"
|
||||
test -z "$ac_cv_path_NM" && ac_cv_path_NM=nm
|
||||
fi])
|
||||
NM="$ac_cv_path_NM"
|
||||
AC_MSG_RESULT([$NM])
|
||||
])
|
||||
|
||||
# AC_CHECK_LIBM - check for math library
|
||||
AC_DEFUN(AC_CHECK_LIBM,
|
||||
[AC_REQUIRE([AC_CANONICAL_HOST])dnl
|
||||
LIBM=
|
||||
case "$lt_target" in
|
||||
*-*-beos* | *-*-cygwin*)
|
||||
# These system don't have libm
|
||||
;;
|
||||
*-ncr-sysv4.3*)
|
||||
AC_CHECK_LIB(mw, _mwvalidcheckl, LIBM="-lmw")
|
||||
AC_CHECK_LIB(m, main, LIBM="$LIBM -lm")
|
||||
;;
|
||||
*)
|
||||
AC_CHECK_LIB(m, main, LIBM="-lm")
|
||||
;;
|
||||
esac
|
||||
])
|
||||
|
||||
# AC_LIBLTDL_CONVENIENCE[(dir)] - sets LIBLTDL to the link flags for
|
||||
# the libltdl convenience library and INCLTDL to the include flags for
|
||||
# the libltdl header and adds --enable-ltdl-convenience to the
|
||||
# configure arguments. Note that LIBLTDL and INCLTDL are not
|
||||
# AC_SUBSTed, nor is AC_CONFIG_SUBDIRS called. If DIR is not
|
||||
# provided, it is assumed to be `libltdl'. LIBLTDL will be prefixed
|
||||
# with '${top_builddir}/' and INCLTDL will be prefixed with
|
||||
# '${top_srcdir}/' (note the single quotes!). If your package is not
|
||||
# flat and you're not using automake, define top_builddir and
|
||||
# top_srcdir appropriately in the Makefiles.
|
||||
AC_DEFUN(AC_LIBLTDL_CONVENIENCE, [AC_BEFORE([$0],[AC_LIBTOOL_SETUP])dnl
|
||||
case "$enable_ltdl_convenience" in
|
||||
no) AC_MSG_ERROR([this package needs a convenience libltdl]) ;;
|
||||
"") enable_ltdl_convenience=yes
|
||||
ac_configure_args="$ac_configure_args --enable-ltdl-convenience" ;;
|
||||
esac
|
||||
LIBLTDL='${top_builddir}/'ifelse($#,1,[$1],['libltdl'])/libltdlc.la
|
||||
INCLTDL='-I${top_srcdir}/'ifelse($#,1,[$1],['libltdl'])
|
||||
])
|
||||
|
||||
# AC_LIBLTDL_INSTALLABLE[(dir)] - sets LIBLTDL to the link flags for
|
||||
# the libltdl installable library and INCLTDL to the include flags for
|
||||
# the libltdl header and adds --enable-ltdl-install to the configure
|
||||
# arguments. Note that LIBLTDL and INCLTDL are not AC_SUBSTed, nor is
|
||||
# AC_CONFIG_SUBDIRS called. If DIR is not provided and an installed
|
||||
# libltdl is not found, it is assumed to be `libltdl'. LIBLTDL will
|
||||
# be prefixed with '${top_builddir}/' and INCLTDL will be prefixed
|
||||
# with '${top_srcdir}/' (note the single quotes!). If your package is
|
||||
# not flat and you're not using automake, define top_builddir and
|
||||
# top_srcdir appropriately in the Makefiles.
|
||||
# In the future, this macro may have to be called after AC_PROG_LIBTOOL.
|
||||
AC_DEFUN(AC_LIBLTDL_INSTALLABLE, [AC_BEFORE([$0],[AC_LIBTOOL_SETUP])dnl
|
||||
AC_CHECK_LIB(ltdl, main,
|
||||
[test x"$enable_ltdl_install" != xyes && enable_ltdl_install=no],
|
||||
[if test x"$enable_ltdl_install" = xno; then
|
||||
AC_MSG_WARN([libltdl not installed, but installation disabled])
|
||||
else
|
||||
enable_ltdl_install=yes
|
||||
fi
|
||||
])
|
||||
if test x"$enable_ltdl_install" = x"yes"; then
|
||||
ac_configure_args="$ac_configure_args --enable-ltdl-install"
|
||||
LIBLTDL='${top_builddir}/'ifelse($#,1,[$1],['libltdl'])/libltdl.la
|
||||
INCLTDL='-I${top_srcdir}/'ifelse($#,1,[$1],['libltdl'])
|
||||
else
|
||||
ac_configure_args="$ac_configure_args --enable-ltdl-install=no"
|
||||
LIBLTDL="-lltdl"
|
||||
INCLTDL=
|
||||
fi
|
||||
])
|
||||
|
||||
dnl old names
|
||||
AC_DEFUN(AM_PROG_LIBTOOL, [indir([AC_PROG_LIBTOOL])])dnl
|
||||
AC_DEFUN(AM_ENABLE_SHARED, [indir([AC_ENABLE_SHARED], $@)])dnl
|
||||
AC_DEFUN(AM_ENABLE_STATIC, [indir([AC_ENABLE_STATIC], $@)])dnl
|
||||
AC_DEFUN(AM_DISABLE_SHARED, [indir([AC_DISABLE_SHARED], $@)])dnl
|
||||
AC_DEFUN(AM_DISABLE_STATIC, [indir([AC_DISABLE_STATIC], $@)])dnl
|
||||
AC_DEFUN(AM_PROG_LD, [indir([AC_PROG_LD])])dnl
|
||||
AC_DEFUN(AM_PROG_NM, [indir([AC_PROG_NM])])dnl
|
||||
|
||||
dnl This is just to silence aclocal about the macro not being used
|
||||
ifelse([AC_DISABLE_FAST_INSTALL])dnl
|
||||
1183
contrib/idn/mdnkit/config.guess
vendored
Normal file
1183
contrib/idn/mdnkit/config.guess
vendored
Normal file
File diff suppressed because it is too large
Load diff
1268
contrib/idn/mdnkit/config.sub
vendored
Normal file
1268
contrib/idn/mdnkit/config.sub
vendored
Normal file
File diff suppressed because it is too large
Load diff
2411
contrib/idn/mdnkit/configure
vendored
Normal file
2411
contrib/idn/mdnkit/configure
vendored
Normal file
File diff suppressed because it is too large
Load diff
274
contrib/idn/mdnkit/configure.in
Normal file
274
contrib/idn/mdnkit/configure.in
Normal file
|
|
@ -0,0 +1,274 @@
|
|||
dnl $Id: configure.in,v 1.25 2000/11/17 06:51:11 ishisone Exp $
|
||||
dnl Process this file with autoconf to produce a configure script.
|
||||
dnl
|
||||
dnl Copyright (c) 2000 Japan Network Information Center. All rights reserved.
|
||||
dnl
|
||||
dnl By using this file, you agree to the terms and conditions set forth bellow.
|
||||
dnl
|
||||
dnl LICENSE TERMS AND CONDITIONS
|
||||
dnl
|
||||
dnl The following License Terms and Conditions apply, unless a different
|
||||
dnl license is obtained from Japan Network Information Center ("JPNIC"),
|
||||
dnl a Japanese association, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
dnl Tokyo, Japan.
|
||||
dnl
|
||||
dnl 1. Use, Modification and Redistribution (including distribution of any
|
||||
dnl modified or derived work) in source and/or binary forms is permitted
|
||||
dnl under this License Terms and Conditions.
|
||||
dnl
|
||||
dnl 2. Redistribution of source code must retain the copyright notices as they
|
||||
dnl appear in each source code file, this License Terms and Conditions.
|
||||
dnl
|
||||
dnl 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
dnl this License Terms and Conditions, in the documentation and/or other
|
||||
dnl materials provided with the distribution. For the purposes of binary
|
||||
dnl distribution the "Copyright Notice" refers to the following language:
|
||||
dnl "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
dnl
|
||||
dnl 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
dnl derived from this Software without specific prior written approval of
|
||||
dnl JPNIC.
|
||||
dnl
|
||||
dnl 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
dnl "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
dnl LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
dnl PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
dnl FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
dnl CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
dnl SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
dnl BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
dnl WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
dnl OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
dnl ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
dnl
|
||||
dnl 6. Indemnification by Licensee
|
||||
dnl Any person or entities using and/or redistributing this Software under
|
||||
dnl this License Terms and Conditions shall defend indemnify and hold
|
||||
dnl harmless JPNIC from and against any and all judgements damages,
|
||||
dnl expenses, settlement liabilities, cost and other liabilities of any
|
||||
dnl kind as a result of use and redistribution of this Software or any
|
||||
dnl claim, suite, action, litigation or proceeding by any third party
|
||||
dnl arising out of or relates to this License Terms and Conditions.
|
||||
dnl
|
||||
dnl 7. Governing Law, Jurisdiction and Venue
|
||||
dnl This License Terms and Conditions shall be governed by and and
|
||||
dnl construed in accordance with the law of Japan. Any person or entities
|
||||
dnl using and/or redistributing this Software under this License Terms and
|
||||
dnl Conditions hereby agrees and consent to the personal and exclusive
|
||||
dnl jurisdiction and venue of Tokyo District Court of Japan.
|
||||
|
||||
AC_INIT(include/mdn/converter.h)
|
||||
|
||||
AC_CANONICAL_HOST
|
||||
|
||||
zld=no
|
||||
AC_ARG_ENABLE(zld,
|
||||
[ --enable-zld enable ZLD support. [default=no]],
|
||||
zld=$enableval)
|
||||
case "$zld" in
|
||||
no)
|
||||
;;
|
||||
yes)
|
||||
AC_DEFINE(MDN_SUPPORT_ZLD)
|
||||
;;
|
||||
*)
|
||||
AC_MSG_ERROR([You must specify yes or no to --enable-zld option.])
|
||||
;;
|
||||
esac
|
||||
|
||||
utf8name=no
|
||||
AC_ARG_WITH(utf8,
|
||||
[ --with-utf8=NAME codeset name for UTF-8 encoding [UTF-8]],
|
||||
utf8name=$withval)
|
||||
case "$utf8name" in
|
||||
no)
|
||||
;;
|
||||
yes)
|
||||
AC_MSG_ERROR([You must specify NAME to --with-utf8 option.])
|
||||
;;
|
||||
*)
|
||||
AC_DEFINE_UNQUOTED(MDN_UTF8_ENCODING_NAME, "$utf8name")
|
||||
;;
|
||||
esac
|
||||
|
||||
raceprefix=no
|
||||
AC_ARG_WITH(race-prefix,
|
||||
[ --with-race-prefix=PREFIX prefix for RACE encoding [bq--]],
|
||||
raceprefix=$withval)
|
||||
case "$raceprefix" in
|
||||
no)
|
||||
;;
|
||||
yes)
|
||||
AC_MSG_ERROR([You must specify PREFIX to --with-race-prefix option.])
|
||||
;;
|
||||
*)
|
||||
AC_DEFINE_UNQUOTED(MDN_RACE_PREFIX, "$raceprefix")
|
||||
;;
|
||||
esac
|
||||
|
||||
bracesuffix=no
|
||||
AC_ARG_WITH(brace-suffix,
|
||||
[ --with-brace-suffix=PREFIX suffix for BRACE encoding [-8q9]],
|
||||
bracesuffix=$withval)
|
||||
case "$bracesuffix" in
|
||||
no)
|
||||
;;
|
||||
yes)
|
||||
AC_MSG_ERROR([You must specify SUFFIX to --with-brace-suffix option.])
|
||||
;;
|
||||
*)
|
||||
AC_DEFINE_UNQUOTED(MDN_BRACE_SUFFIX, "$bracesuffix")
|
||||
;;
|
||||
esac
|
||||
|
||||
laceprefix=no
|
||||
AC_ARG_WITH(lace-prefix,
|
||||
[ --with-lace-prefix=PREFIX prefix for LACE encoding [bq--]],
|
||||
laceprefix=$withval)
|
||||
case "$laceprefix" in
|
||||
no)
|
||||
;;
|
||||
yes)
|
||||
AC_MSG_ERROR([You must specify PREFIX to --with-lace-prefix option.])
|
||||
;;
|
||||
*)
|
||||
AC_DEFINE_UNQUOTED(MDN_LACE_PREFIX, "$laceprefix")
|
||||
;;
|
||||
esac
|
||||
|
||||
iconv=no
|
||||
AC_ARG_WITH(iconv,
|
||||
[ --with-iconv=LIB special library for iconv []],
|
||||
iconv=$withval)
|
||||
case "$iconv" in
|
||||
no)
|
||||
ICONVLIB=
|
||||
;;
|
||||
yes)
|
||||
AC_MSG_WARN([You must supply LIB to --with-iconv option.
|
||||
-liconv is assumed.])
|
||||
ICONVLIB=-liconv
|
||||
;;
|
||||
*)
|
||||
ICONVLIB=$iconv
|
||||
;;
|
||||
esac
|
||||
AC_SUBST(ICONVLIB)
|
||||
|
||||
AC_ARG_WITH(iconv-sofile,
|
||||
[ --with-iconv-sofile=PATH shared library file for libiconv []],
|
||||
iconv_file=$withval, iconv_file=guess)
|
||||
ICONVSOFILE=
|
||||
case "$iconv_file" in
|
||||
no)
|
||||
ICONVSOFILE=none
|
||||
;;
|
||||
yes)
|
||||
AC_MSG_ERROR([You must supply PATH to --with-iconv-sofile option.])
|
||||
;;
|
||||
guess)
|
||||
if test "$ICONVLIB" = ""; then
|
||||
ICONVSOFILE=none
|
||||
else
|
||||
AC_MSG_CHECKING(pathname of iconv shared library)
|
||||
ic_libdir=
|
||||
ic_libname=
|
||||
case "$host" in
|
||||
*-hpux*)
|
||||
SO=sl
|
||||
;;
|
||||
*)
|
||||
SO=so
|
||||
;;
|
||||
esac
|
||||
for arg in $ICONVLIB; do
|
||||
case "$arg" in
|
||||
-L*) ic_libdir="$ic_libdir `echo $arg | sed s/-L//`" ;;
|
||||
-l*) ic_libname=`echo $arg | sed s/-l//` ;;
|
||||
/*.$SO*) ICONVSOFILE=$arg ;;
|
||||
esac
|
||||
done
|
||||
if test "$ICONVSOFILE" = ""; then
|
||||
if test "$ic_libname" = ""; then
|
||||
AC_MSG_RESULT(unknown)
|
||||
AC_MSG_WARN([use --with-iconv-sofile for specifying iconv shared library file])
|
||||
ICONVSOFILE=none
|
||||
else
|
||||
if test "$ic_libdir" = ""; then
|
||||
# Standard (and semi-standard) library directories
|
||||
ic_libdir="/lib /usr/lib /usr/local/lib"
|
||||
fi
|
||||
for dir in $ic_libdir; do
|
||||
ICONVSOFILE=`ls -r $dir/lib$ic_libname.$SO* 2>/dev/null | head -1`
|
||||
if test "$ICONVSOFILE" != ""; then
|
||||
break
|
||||
fi
|
||||
done
|
||||
if test "$ICONVSOFILE" != ""; then
|
||||
AC_MSG_RESULT($ICONVSOFILE)
|
||||
else
|
||||
AC_MSG_RESULT(unknown)
|
||||
AC_MSG_WARN([use --with-iconv-sofile for specifying iconv shared library file])
|
||||
ICONVSOFILE=none
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
ICONVSOFILE=$iconv_file
|
||||
;;
|
||||
esac
|
||||
AC_SUBST(ICONVSOFILE)
|
||||
|
||||
dnl Figure out preload stuff.
|
||||
PRELOAD_VAR="LD_PRELOAD"
|
||||
PRELOAD_SEP=":"
|
||||
PRELOAD_LAST=""
|
||||
case "$host" in
|
||||
*-solaris*)
|
||||
PRELOAD_SEP=" "
|
||||
;;
|
||||
*-osf*)
|
||||
PRELOAD_VAR="_RLD_LIST"
|
||||
PRELOAD_LAST=":DEFAULT"
|
||||
;;
|
||||
esac
|
||||
AC_SUBST(PRELOAD_VAR)
|
||||
AC_SUBST(PRELOAD_SEP)
|
||||
AC_SUBST(PRELOAD_LAST)
|
||||
|
||||
dnl Checks for standard tools.
|
||||
AC_PROG_CC
|
||||
AC_PROG_INSTALL
|
||||
AM_PROG_LIBTOOL
|
||||
|
||||
dnl Checks for header files.
|
||||
AC_CHECK_HEADERS(unistd.h locale.h langinfo.h sys/select.h iconv.h)
|
||||
|
||||
dnl Checks for data types.
|
||||
AC_TYPE_UID_T
|
||||
dnl for dnsproxy.
|
||||
AC_CHECK_TYPE(BOOL, int)
|
||||
|
||||
dnl Checks for libraries.
|
||||
AC_CHECK_LIB(socket, socket)
|
||||
AC_CHECK_LIB(nsl, inet_addr)
|
||||
|
||||
dnl Checks for library functions.
|
||||
AC_CHECK_FUNCS(vsnprintf setvbuf setlocale nl_langinfo memmove bcopy)
|
||||
|
||||
dnl Output.
|
||||
AC_CONFIG_HEADER(include/config.h)
|
||||
AC_OUTPUT(
|
||||
Makefile
|
||||
include/Makefile
|
||||
include/mdn/Makefile
|
||||
lib/Makefile
|
||||
dnsproxy/Makefile
|
||||
man/Makefile
|
||||
tools/Makefile
|
||||
tools/mdnconv/Makefile
|
||||
tools/runmdn/Makefile
|
||||
tools/runmdn/runmdn
|
||||
)
|
||||
158
contrib/idn/mdnkit/dnsproxy/Makefile.in
Normal file
158
contrib/idn/mdnkit/dnsproxy/Makefile.in
Normal file
|
|
@ -0,0 +1,158 @@
|
|||
# $Id: Makefile.in,v 1.18 2000/11/17 07:36:37 ishisone Exp $
|
||||
# Makefile for mDNS Proxy Server
|
||||
#
|
||||
# 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
# Tokyo, Japan.
|
||||
#
|
||||
# 1. Use, Modification and Redistribution (including distribution of any
|
||||
# modified or derived work) in source and/or binary forms is permitted
|
||||
# under this License Terms and Conditions.
|
||||
#
|
||||
# 2. Redistribution of source code must retain the copyright notices as they
|
||||
# appear in each source code file, this License Terms and Conditions.
|
||||
#
|
||||
# 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
# this License Terms and Conditions, in the documentation and/or other
|
||||
# materials provided with the distribution. For the purposes of binary
|
||||
# distribution the "Copyright Notice" refers to the following language:
|
||||
# "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
#
|
||||
# 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
# derived from this Software without specific prior written approval of
|
||||
# JPNIC.
|
||||
#
|
||||
# 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
#
|
||||
# 6. Indemnification by Licensee
|
||||
# Any person or entities using and/or redistributing this Software under
|
||||
# this License Terms and Conditions shall defend indemnify and hold
|
||||
# harmless JPNIC from and against any and all judgements damages,
|
||||
# expenses, settlement liabilities, cost and other liabilities of any
|
||||
# kind as a result of use and redistribution of this Software or any
|
||||
# claim, suite, action, litigation or proceeding by any third party
|
||||
# arising out of or relates to this License Terms and Conditions.
|
||||
#
|
||||
# 7. Governing Law, Jurisdiction and Venue
|
||||
# This License Terms and Conditions shall be governed by and and
|
||||
# construed in accordance with the law of Japan. Any person or entities
|
||||
# using and/or redistributing this Software under this License Terms and
|
||||
# Conditions hereby agrees and consent to the personal and exclusive
|
||||
# jurisdiction and venue of Tokyo District Court of Japan.
|
||||
|
||||
top_builddir = ..
|
||||
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
prefix = @prefix@
|
||||
exec_prefix = @exec_prefix@
|
||||
|
||||
SBINDIR = @sbindir@
|
||||
ETCDIR = @sysconfdir@
|
||||
CONFIG_PATH = $(ETCDIR)
|
||||
MANDIR = @mandir@
|
||||
|
||||
CC = @CC@
|
||||
PURIFY = purify
|
||||
INSTALL = @INSTALL@
|
||||
INSTALL_PROGRAM = @INSTALL_PROGRAM@
|
||||
INSTALL_DATA = @INSTALL_DATA@
|
||||
SHELL = @SHELL@
|
||||
LIBTOOL = @LIBTOOL@
|
||||
|
||||
OPTS =
|
||||
INCS = -I$(srcdir)/../include -I../include
|
||||
DEFS = -DUNIX -DCONFIG_PATH="\"$(CONFIG_PATH)/\""
|
||||
CFLAGS = $(OPTS) $(INCS) $(DEFS) @CFLAGS@
|
||||
LDFLAGS = $(OPTS) @LDFLAGS@
|
||||
|
||||
LIBS = ../lib/libmdn.la
|
||||
SYSLIBS = @LIBS@ @ICONVLIB@
|
||||
|
||||
#
|
||||
# Files to build mDNS Proxy
|
||||
#
|
||||
|
||||
SRCS = unxmain.c server.c message.c logging.c proxycnf.c translate.c
|
||||
OBJS = unxmain.o server.o message.o logging.o proxycnf.o translate.o
|
||||
|
||||
#
|
||||
# Target to build
|
||||
#
|
||||
|
||||
TARGETS = dnsproxy dnsproxy.8
|
||||
|
||||
all : $(TARGETS)
|
||||
|
||||
dnsproxy : $(OBJS) $(LIBS)
|
||||
$(LIBTOOL) --mode=link $(CC) $(LDFLAGS) -o $@ \
|
||||
$(OBJS) $(LIBS) $(SYSLIBS)
|
||||
|
||||
dnsproxy.purify : $(OBJS) $(LIBS)
|
||||
$(LIBTOOL) --mode=link $(PURIFY) $(CC) $(LDFLAGS) -o $@ \
|
||||
$(OBJS) $(LIBS) $(SYSLIBS)
|
||||
|
||||
#
|
||||
# Installation
|
||||
#
|
||||
|
||||
install: install-program install-config install-man
|
||||
|
||||
install-program: dnsproxy
|
||||
[ -d $(SBINDIR) ] || mkdir $(SBINDIR)
|
||||
$(LIBTOOL) --mode=install $(INSTALL_PROGRAM) dnsproxy $(SBINDIR)
|
||||
|
||||
# Do not overwrite existing configuration file.
|
||||
install-config:
|
||||
[ -d $(ETCDIR) ] || mkdir $(ETCDIR)
|
||||
@if [ -f $(ETCDIR)/dnsproxy.conf ]; then \
|
||||
echo '** dnsproxy.conf already exists in the install directory.'; \
|
||||
echo '** install as dnsproxy.conf.sample.'; \
|
||||
$(INSTALL_DATA) $(srcdir)/dnsproxy.conf.sample $(ETCDIR)/; \
|
||||
else \
|
||||
echo installing sample configuration file.; \
|
||||
$(INSTALL_DATA) $(srcdir)/dnsproxy.conf.sample \
|
||||
$(ETCDIR)/dnsproxy.conf; fi
|
||||
|
||||
install-man: dnsproxy.8
|
||||
[ -d $(MANDIR) ] || mkdir $(MANDIR)
|
||||
[ -d $(MANDIR)/man8 ] || mkdir $(MANDIR)/man8
|
||||
$(INSTALL_DATA) dnsproxy.8 $(MANDIR)/man8
|
||||
|
||||
dnsproxy.8: dnsproxy.8.in
|
||||
sed 's%@ETCDIR@%$(ETCDIR)%' < $(srcdir)/dnsproxy.8.in > $@
|
||||
|
||||
clean:
|
||||
rm -f $(TARGETS) *.o core *.core *~
|
||||
|
||||
#
|
||||
# Dependecnies
|
||||
#
|
||||
|
||||
unxmain.o : unxmain.c dnsproxy.h
|
||||
|
||||
server.o : server.c dnsproxy.h
|
||||
|
||||
message.o : message.c dnsproxy.h
|
||||
|
||||
logging.o : logging.c dnsproxy.h
|
||||
|
||||
proxycnf.o : proxycnf.c dnsproxy.h proxycnf.h
|
||||
282
contrib/idn/mdnkit/dnsproxy/dnsproxy.8.in
Normal file
282
contrib/idn/mdnkit/dnsproxy/dnsproxy.8.in
Normal file
|
|
@ -0,0 +1,282 @@
|
|||
.\" $Id: dnsproxy.8.in,v 1.10 2000/11/17 07:36:37 ishisone 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
.\" Tokyo, Japan.
|
||||
.\"
|
||||
.\" 1. Use, Modification and Redistribution (including distribution of any
|
||||
.\" modified or derived work) in source and/or binary forms is permitted
|
||||
.\" under this License Terms and Conditions.
|
||||
.\"
|
||||
.\" 2. Redistribution of source code must retain the copyright notices as they
|
||||
.\" appear in each source code file, this License Terms and Conditions.
|
||||
.\"
|
||||
.\" 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
.\" this License Terms and Conditions, in the documentation and/or other
|
||||
.\" materials provided with the distribution. For the purposes of binary
|
||||
.\" distribution the "Copyright Notice" refers to the following language:
|
||||
.\" "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
.\"
|
||||
.\" 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
.\" derived from this Software without specific prior written approval of
|
||||
.\" JPNIC.
|
||||
.\"
|
||||
.\" 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
.\" "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
.\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
.\" PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
.\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
.\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
.\"
|
||||
.\" 6. Indemnification by Licensee
|
||||
.\" Any person or entities using and/or redistributing this Software under
|
||||
.\" this License Terms and Conditions shall defend indemnify and hold
|
||||
.\" harmless JPNIC from and against any and all judgements damages,
|
||||
.\" expenses, settlement liabilities, cost and other liabilities of any
|
||||
.\" kind as a result of use and redistribution of this Software or any
|
||||
.\" claim, suite, action, litigation or proceeding by any third party
|
||||
.\" arising out of or relates to this License Terms and Conditions.
|
||||
.\"
|
||||
.\" 7. Governing Law, Jurisdiction and Venue
|
||||
.\" This License Terms and Conditions shall be governed by and and
|
||||
.\" construed in accordance with the law of Japan. Any person or entities
|
||||
.\" using and/or redistributing this Software under this License Terms and
|
||||
.\" Conditions hereby agrees and consent to the personal and exclusive
|
||||
.\" jurisdiction and venue of Tokyo District Court of Japan.
|
||||
.TH DNSPROXY 8
|
||||
.SH NAME
|
||||
dnsproxy \- DNS proxy server for multi-lingual DNS
|
||||
|
||||
.SH SYNOPSIS
|
||||
.B dnsproxy
|
||||
[ \-daemon ] [ \-config <config\-file> ] [ \-logfile <log\-file> ]
|
||||
|
||||
.SH DESCRIPTION
|
||||
.B dnsproxy
|
||||
resides between application (resolver) and DNS server.
|
||||
.PP
|
||||
It accepts DNS requests from application (resolver) and converting
|
||||
domain names in those requests into DNS server's acceptable encoding,
|
||||
and forward those converted requests. It also accepts responses from
|
||||
DNS server and converting domain names in those resopnses into
|
||||
application's acceptable encoding and forward those responses to
|
||||
applications.
|
||||
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
.B \-daemon
|
||||
Run dnsproxy as daemon. Otherwise, dnsproxy will run as normal
|
||||
console program.
|
||||
.TP
|
||||
.B \-config <config\-file>
|
||||
Specifies configuration file (see later). If not specified,
|
||||
dnsproxy uses default configuration file.
|
||||
See
|
||||
.B FILES
|
||||
section for default configuration file.
|
||||
.TP
|
||||
.B \-logfile <log\-file>
|
||||
Specifies logging file. If not specified.
|
||||
dnsproxy uses default logging file.
|
||||
See
|
||||
.B FILES
|
||||
section for default configuration file.
|
||||
|
||||
.SH CONFIGURATION
|
||||
Configuration file is simple text file which defines several
|
||||
configuration data.
|
||||
.IP "listen <address>"
|
||||
.RS
|
||||
Defines listening port (both TCP and UDP). <address> is one of
|
||||
.RS
|
||||
.PP
|
||||
<IP address>:<port number>
|
||||
.br
|
||||
:<port number>
|
||||
.br
|
||||
<IP address>
|
||||
.PP
|
||||
.RE
|
||||
If omitted, dnsproxy uses default value shown below.
|
||||
.RS
|
||||
.PP
|
||||
IP Address INADDR_ANY (0.0.0.0)
|
||||
.br
|
||||
port number 53
|
||||
.PP
|
||||
.RE
|
||||
.RE
|
||||
.IP "forward <address> [ bind4compat ]"
|
||||
.RS
|
||||
Defines forwarding server's address. Format is same as 'listen'.
|
||||
.PP
|
||||
example:
|
||||
.RS
|
||||
forward 10.1.2.3
|
||||
.RE
|
||||
.PP
|
||||
If "bind4compat" was given, dnsproxy uses above listen port
|
||||
as forwading UDP's source address. If not given, dnsproxy uses
|
||||
port > 1024 as forwading UDP's source.
|
||||
.RE
|
||||
.IP "log-file <path>"
|
||||
.RS
|
||||
Defines log file name. It may be overridden with command line
|
||||
option '-logfile <path>'. If no log file given, dnsproxy writes
|
||||
log data into "/tmp/dnsproxy.log".
|
||||
Sending SIGHUP causes dnsproxy to close the log file and then reopen it.
|
||||
.RE
|
||||
.IP "client-translation <ZLD> <Encoding>"
|
||||
.RS
|
||||
Defines client side character encoding scheme. Some clients
|
||||
locally encode domain name and add <ZLD> (Zero Level Domain) to
|
||||
it. In those cases, use <ZLD> and specify corresponding encoding.
|
||||
Usually, no mDNS'nized client passes domain name in client's
|
||||
local encoding. For those case, use '.' as ZLD. You may
|
||||
specify several 'client-translation's if client uses several
|
||||
encoding with different ZLD.
|
||||
.PP
|
||||
example:
|
||||
.RS
|
||||
.nf
|
||||
client-translation .i-dns.net UTF-5 # accept ZLDs
|
||||
client-translation . Shift_JIS
|
||||
.fi
|
||||
.RE
|
||||
.PP
|
||||
Acceptable ZLD will depend on client programs. Also acceptable
|
||||
encodings depend on client and the implementation of `iconv()' function,
|
||||
which dnsproxy uses internally for encoding conversion.
|
||||
Check the document on `iconv()' for acceptable encoding names.
|
||||
.RE
|
||||
.IP "alternate-encoding <Encoding>"
|
||||
.RS
|
||||
Defines client side alternative encoding scheme. The alternative
|
||||
encoding will be used when the conversion from server-side encoding
|
||||
to the default local encoding is failed due to the lack of mapping
|
||||
some certain characters to the local character set.
|
||||
.PP
|
||||
example:
|
||||
.RS
|
||||
alternate-encoding\ \ RACE
|
||||
.RE
|
||||
.PP
|
||||
The alternative encoding must be an ASCII compatible encoding, such as RACE.
|
||||
.RE
|
||||
.IP "normalize <Normalization Scheme> ..."
|
||||
.RS
|
||||
Defines domain name normalization schemes. You can specify
|
||||
several normalizations and they are applied left to right.
|
||||
.PP
|
||||
example:
|
||||
.RS
|
||||
normalize ja-fullwidth unicode-form-c
|
||||
.RE
|
||||
.PP
|
||||
Acceptable normalizations depend on 'libmdn' library. Check
|
||||
documents for 'libmdn' for more detail.
|
||||
.RE
|
||||
.IP "server-translation <Encoding>"
|
||||
.RS
|
||||
Defines server side character encoding scheme. Finally, domain
|
||||
names in DNS request from clients are converted to this encoding
|
||||
and forwarded to mDNS'nized DNS server.
|
||||
.PP
|
||||
example:
|
||||
.RS
|
||||
server-translation . UTF-8
|
||||
.RE
|
||||
.RE
|
||||
.IP "user-id <Name-or-ID>"
|
||||
.RS
|
||||
Defines a user ID in which dnsproxy operates.
|
||||
Dnsproxy tries to change the user ID of its process to the specified one,
|
||||
soon after initialization.
|
||||
.PP
|
||||
example:
|
||||
.RS
|
||||
.nf
|
||||
user-id\ \ nobody
|
||||
user-id\ \ 9999
|
||||
.fi
|
||||
.RE
|
||||
.PP
|
||||
It is strongly recommended to use this option for security reasons.
|
||||
.RE
|
||||
.IP "group-id <Name-or-ID>"
|
||||
.RS
|
||||
Defines a group ID in which dnsproxy operates.
|
||||
Dnsproxy tries to change the group ID of its process to the specified one,
|
||||
soon after initialization.
|
||||
.PP
|
||||
example:
|
||||
.RS
|
||||
.nf
|
||||
group-id\ \ nobody
|
||||
group-id\ \ 9999
|
||||
.fi
|
||||
.RE
|
||||
.RE
|
||||
.IP "root-directory <Directory>"
|
||||
.RS
|
||||
Defines the pathname of the root directory for the dnsproxy process.
|
||||
Dnsproxy performs chroot() to set the specified directory as the
|
||||
root directory for the process after initialization.
|
||||
.PP
|
||||
example:
|
||||
.RS
|
||||
.nf
|
||||
root-directory /var/dnsproxy
|
||||
.fi
|
||||
.RE
|
||||
.RE
|
||||
.IP "log-level <Level>"
|
||||
.RS
|
||||
Sets the log level. Available levels are ``none'' (no logging at all),
|
||||
``fatal'' (only logs fatal errors), ``warn'' (also logs warning messages)
|
||||
and ``trace'' (also includes trace level messages). The default level is
|
||||
``warn''. Please note that if you set the level to ``trace'', the size of
|
||||
the log file grows quickly.
|
||||
.RE
|
||||
|
||||
.SH NOTES
|
||||
Some applications locally mangles domain names. In those cases,
|
||||
dnsproxy cannot works correctly.
|
||||
.PP
|
||||
For 'nslookup', it generally reject non-ascii domain names.
|
||||
You need 8bit through patched version of nslookup.
|
||||
.PP
|
||||
For UNIX resolver generally rejects domain names using non-ascii characters.
|
||||
You need 8bit through patched version of resolver.
|
||||
.PP
|
||||
For Windows, NS works well with dnsproxy. For IE, turn off "use UTF-8"
|
||||
setting, and generally works. But for IE, embedded URL's in page will
|
||||
converted by IE (to page's original encoding),
|
||||
and they conflict with dnsproxy.
|
||||
|
||||
.SH FILES
|
||||
.PD 0
|
||||
.TP 30
|
||||
.B @ETCDIR@/dnsproxy.conf
|
||||
Default configuration file.
|
||||
.TP
|
||||
.B /tmp/dnsproxy.log
|
||||
Default logging file.
|
||||
.PD
|
||||
|
||||
.SH SLL ALSO
|
||||
.BR named(8),
|
||||
.BR libmdn(3),
|
||||
.BR iconv(3)
|
||||
170
contrib/idn/mdnkit/dnsproxy/dnsproxy.conf.sample
Executable file
170
contrib/idn/mdnkit/dnsproxy/dnsproxy.conf.sample
Executable file
|
|
@ -0,0 +1,170 @@
|
|||
# $Id: dnsproxy.conf.sample,v 1.6 2000/11/22 06:57:30 ishisone Exp $
|
||||
#
|
||||
# Sample dnsproxy configuration file 'dnsproxy.conf'.
|
||||
#
|
||||
|
||||
#
|
||||
# 'listen' entry specifies the dnsproxy's listening port.
|
||||
# The default is to use address 0.0.0.0 (INADDR_ANY) and port 53.
|
||||
#
|
||||
# syntax)
|
||||
# listen [<IP address>][:<port number>]
|
||||
#
|
||||
# ex) listen 127.0.0.1 -- only accept loopback connections
|
||||
# listen :1053 -- port number can be specified
|
||||
# listen 127.0.0.1:1053 -- combination of above
|
||||
#
|
||||
#listen 127.0.0.1
|
||||
|
||||
#
|
||||
# 'forward' entry specifies the name server's port to which dnsproxy
|
||||
# forwards requests. This entry MUST be specified.
|
||||
#
|
||||
# Normally dnsproxy uses unspecified local port number for sending
|
||||
# queries to the server, but if 'bind4compat' option is specified,
|
||||
# dnsproxy uses the same port number as the listening port specified
|
||||
# by the 'listen' entry.
|
||||
#
|
||||
# syntax)
|
||||
# forward <IP address>[:<port number>] [bind4compat]
|
||||
#
|
||||
# ex) forward 10.0.0.2 -- forward 10.0.0.2 port 53
|
||||
# forward 10.0.0.2:1053 -- port number can be specified
|
||||
# forward 10.0.0.2 bind4compat -- use fixed port number.
|
||||
forward xxx.xxx.xxx.xxx
|
||||
|
||||
#
|
||||
# 'client-tranlation' entries specify the codeset (encoding) of domain
|
||||
# names in the messages sent by the clients. If you configure mDNkit
|
||||
# with '--enable-zld' option, ZLD (zero level domain) can be specified.
|
||||
# In this case multiple entries are permitted as long as each entry has
|
||||
# different ZLD.
|
||||
#
|
||||
# If ZLD is not enabled (this is the default), ZLD part is ignored.
|
||||
#
|
||||
# syntax)
|
||||
# client-translation <ZLD> <codeset>
|
||||
#
|
||||
# ex) client-translation .xyz UTF-5
|
||||
# -- If the domain name ends with '.xyz', the client encoding
|
||||
# is assumed to be UTF-5. The ZLD part (.xyz) will be removed
|
||||
# from the domain name before converting to the server
|
||||
# encoding.
|
||||
# client-translation . Shift_JIS
|
||||
# -- '.' denotes absence of ZLD. If the given domain name
|
||||
# doesn't match any of other ZLDs, this entry matches
|
||||
# and codeset Shift_JIS is assumed.
|
||||
#
|
||||
#client-translation .i-dns.net UTF-5 # ZLD is .i-dns.net, codeset is UTF-5
|
||||
client-translation . Shift_JIS
|
||||
|
||||
#
|
||||
# Normally domain names in the DNS reply messages from the (real) name
|
||||
# server are translated back to the client codeset determined by the
|
||||
# above 'client-translation' entries.
|
||||
#
|
||||
# 'alternate-encoding' entry specifies the alternative codeset which
|
||||
# is used instead of the client codeset when the translation to the
|
||||
# client codeset fails. This alternative codeset must be an ASCII-
|
||||
# compatible encoding, such as RACE.
|
||||
#
|
||||
# syntax)
|
||||
# alternate-encoding <codeset>
|
||||
#
|
||||
alternate-encoding RACE
|
||||
|
||||
#
|
||||
#
|
||||
# 'normalize' entry specifies the normalization. You can specify any of
|
||||
# these normalization schemes:
|
||||
# ascii-lowercase -- ASCII uppercase letters to lowercase
|
||||
# ascii-uppercase -- ASCII lowercase letters to uppercase
|
||||
# unicode-lowercase -- Unicode uppercase letters to lowercase
|
||||
# unicode-uppercase -- Unicode lowercase letters to uppercase
|
||||
# unicode-form-c -- Unicode normalization form C
|
||||
# unicode-form-kc -- Unicode normalization form KC
|
||||
# ja-kana-fullwidth -- Japanese halfwidth kana letters to fullwidth
|
||||
# ja-alnum-halfwidth -- Fullwidth alphabets, digits and minus sign
|
||||
# to halfwidth
|
||||
# ja-compose-voiced-sound -- Combine Japanese fullwidth kana and the
|
||||
# following (semi) voiced sound mark
|
||||
# ja-minus-hack -- Japanse fullwidth minus sign to '-'
|
||||
#
|
||||
# If more than one schemes are specified, they are applied in turn.
|
||||
#
|
||||
# syntax)
|
||||
# normalize <normalization scheme>...
|
||||
#
|
||||
# ex) normalize unicode-form-kc unicode-lowercase
|
||||
# -- first 'unicode-form-kc', then 'unicode-lowercase'
|
||||
#
|
||||
normalize unicode-lowercase unicode-form-kc
|
||||
|
||||
#
|
||||
# 'server-translation' entry specifies the codeset (encoding) of domain
|
||||
# names used by the (real) name servers. Also ZLD can be specified if
|
||||
# configured with '--enable-zld' option.
|
||||
#
|
||||
# syntax)
|
||||
# server-translation <ZLD> <encoding>
|
||||
#
|
||||
# ex) server-translation . UTF-8 -- use UTF-8 without ZLD
|
||||
#
|
||||
server-translation . RACE
|
||||
|
||||
#
|
||||
# 'log-file' entry specifies the pathname of the log file. If it is
|
||||
# not specified, default log file (/tmp/dnsproxy.log) will be used.
|
||||
#
|
||||
# syntax)
|
||||
# log-file <pathname>
|
||||
#
|
||||
log-file /var/log/dnsproxy.log
|
||||
|
||||
#
|
||||
# 'user-id' entry and 'group-id' entry specify the user/group ID
|
||||
# in which privilege dnsproxy operates. dnsproxy tries to switch
|
||||
# to the specified user/group after initialization process is finished.
|
||||
#
|
||||
# syntax)
|
||||
# user-id <name-or-number>
|
||||
# group-id <name-or-number>
|
||||
#
|
||||
# ex) user-id nobody -- specify by name,
|
||||
# group-id 1000 -- or by number
|
||||
#
|
||||
user-id nobody
|
||||
#group-id nobody
|
||||
|
||||
#
|
||||
# 'root-directory' entry specifies the root directory of dnsproxy
|
||||
# process. dnsproxy performs chroot() to this directory after
|
||||
# initialization. Note that chroot() is allowed only for super-users.
|
||||
#
|
||||
# syntax)
|
||||
# root-directory <path>
|
||||
#
|
||||
root-directory /var/dnsproxy
|
||||
|
||||
#
|
||||
# 'log-level' entry specifies the logging level for dnsproxy.
|
||||
# Valid levels are 'none' (no logging at all, not recommended),
|
||||
# 'fatal' (only logs fatal errors), 'warn' (also logs warning messages)
|
||||
# and 'trace' (also includes trace messages). The default level is 'warn'.
|
||||
# 'trace' level is useful for debugging dnsproxy itself, but it makes
|
||||
# the log file grow rather quickly.
|
||||
#
|
||||
# syntax)
|
||||
# log-level <level>
|
||||
#
|
||||
log-level warn
|
||||
|
||||
#
|
||||
# 'mdn-log-level' entry specifies the logging level for libmdn, the
|
||||
# library responsible for most of the MDN processing for dnsproxy.
|
||||
# Unless you are debugging mDNkit, you should keep this entry unspecified.
|
||||
#
|
||||
# syntax)
|
||||
# mdn-log-level <number>
|
||||
#
|
||||
# mdn-log-level 1
|
||||
3
contrib/idn/mdnkit/dnsproxy/dnsproxy.def
Normal file
3
contrib/idn/mdnkit/dnsproxy/dnsproxy.def
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
NAME dnsproxy WINDOWCOMPAT NEWFILES
|
||||
EXETYPE OS2
|
||||
STACKSIZE 32768
|
||||
192
contrib/idn/mdnkit/dnsproxy/dnsproxy.h
Normal file
192
contrib/idn/mdnkit/dnsproxy/dnsproxy.h
Normal file
|
|
@ -0,0 +1,192 @@
|
|||
/*
|
||||
* dnsproxy.h - mDNS Proxy, Common Definitions
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
/* $Id: dnsproxy.h,v 1.13 2000/11/17 05:57:56 ishisone Exp $ */
|
||||
|
||||
#ifndef DNSPROXY_H
|
||||
#define DNSPROXY_H 1
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#include <winsock.h>
|
||||
#else /* for normal systems */
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Redefine TRUE and FALSE.
|
||||
*/
|
||||
#undef TRUE
|
||||
#undef FALSE
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
|
||||
/*
|
||||
* Macro for Error Logging
|
||||
*/
|
||||
|
||||
enum {
|
||||
LOGLEVEL_NONE = 0,
|
||||
LOGLEVEL_FATAL = 1,
|
||||
LOGLEVEL_WARN = 2,
|
||||
LOGLEVEL_TRACE = 3
|
||||
};
|
||||
|
||||
void log_configure(int ac, char *av[]) ;
|
||||
void log_terminate(void) ;
|
||||
void log_turnover_request(void) ;
|
||||
void log_turnover(void) ;
|
||||
void log_setlevel(int level) ;
|
||||
int log_strtolevel(char *s) ;
|
||||
void log_fatal_printf(char *fmt, ...) ;
|
||||
void log_warn_printf(char *fmt, ...) ;
|
||||
void log_trace_printf(char *fmt, ...) ;
|
||||
|
||||
#define TRACE log_trace_printf
|
||||
#define WARN log_warn_printf
|
||||
#define FATAL log_fatal_printf
|
||||
|
||||
/*
|
||||
* Server's Control Entries
|
||||
*/
|
||||
|
||||
BOOL server_init(int ac, char *av[]) ;
|
||||
void server_stop(void) ;
|
||||
void server_loop(void) ;
|
||||
void server_done(void) ;
|
||||
|
||||
/*
|
||||
* Server calls following callback when received message
|
||||
*/
|
||||
|
||||
void notify_message(struct sockaddr *from, int proto,
|
||||
u_char *msg, int len) ;
|
||||
|
||||
void notify_timer(void) ;
|
||||
|
||||
/*
|
||||
* To send messages, call following entires in server module
|
||||
*/
|
||||
|
||||
void server_forward(struct sockaddr *to, int proto,
|
||||
u_char *msg, int len) ;
|
||||
void server_response(struct sockaddr *to, int proto,
|
||||
u_char *msg, int len) ;
|
||||
|
||||
/*
|
||||
* load/dump/dispose configuration data
|
||||
*/
|
||||
|
||||
BOOL config_load(int ac, char *av[]) ;
|
||||
void config_free(void) ;
|
||||
void config_dump(FILE *ofp) ;
|
||||
|
||||
/*
|
||||
* query configuration data
|
||||
*/
|
||||
|
||||
BOOL config_query_value(char *key, int *count, char ***array) ;
|
||||
BOOL config_query_listen(struct sockaddr *addr) ;
|
||||
BOOL config_query_forward(struct sockaddr *addr) ;
|
||||
BOOL config_query_restrict(BOOL *restrict) ;
|
||||
|
||||
/*
|
||||
* Message (domain name) translation
|
||||
*/
|
||||
|
||||
typedef struct translation_context {
|
||||
struct sockaddr *client; /* address family/IP address/port */
|
||||
int protocol; /* IPPROTO_TCP or IPPROTO_UDP */
|
||||
unsigned int old_id; /* original message ID */
|
||||
unsigned int new_id; /* new message ID */
|
||||
char *zld; /* ZLD */
|
||||
void *converter; /* encoding: actual type is mdn_converter_t */
|
||||
} translation_context_t;
|
||||
|
||||
BOOL translate_initialize(void) ;
|
||||
int translate_request(translation_context_t *ctx,
|
||||
const char *msg, size_t msglen,
|
||||
char *translated, size_t bufsize, size_t *translatedlenp) ;
|
||||
int translate_reply(translation_context_t *ctx,
|
||||
const char *msg, size_t msglen,
|
||||
char *translated, size_t bufsize, size_t *translatedlenp) ;
|
||||
|
||||
/*
|
||||
* query configuration having multiple entries (with same key)
|
||||
*
|
||||
* ctx = config_query_open(key, ...) ;
|
||||
* while (ctx != NULL) {
|
||||
* ctx = config_query_more(ctx, ...) ;
|
||||
* }
|
||||
* config_query_close(ctx) ;
|
||||
*/
|
||||
|
||||
typedef void *config_ctx_t ; /* opaque pointer to lookup context */
|
||||
|
||||
config_ctx_t config_query_open(char *key, int *count, char ***array) ;
|
||||
config_ctx_t config_query_more(config_ctx_t ctx, int *count, char ***array) ;
|
||||
void config_query_close(config_ctx_t ctx) ;
|
||||
|
||||
#endif /* DNSPROXY_H */
|
||||
294
contrib/idn/mdnkit/dnsproxy/logging.c
Normal file
294
contrib/idn/mdnkit/dnsproxy/logging.c
Normal file
|
|
@ -0,0 +1,294 @@
|
|||
/*
|
||||
* logging.c - logging support
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char *rcsid = "$Id: logging.c,v 1.13 2000/11/17 05:46:23 ishisone Exp $";
|
||||
#endif
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "dnsproxy.h"
|
||||
|
||||
#define DEFAULT_LOGFILE "dnsproxy.log"
|
||||
|
||||
#ifdef DEBUG
|
||||
#define DEFAULT_LOG_LEVEL LOGLEVEL_TRACE
|
||||
#else
|
||||
#define DEFAULT_LOG_LEVEL LOGLEVEL_WARN
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Logging Control Variables
|
||||
*/
|
||||
|
||||
static char logFname[256] = { 0 } ;
|
||||
static FILE *logFptr = NULL ;
|
||||
static int logLevel = DEFAULT_LOG_LEVEL ;
|
||||
static int timeToTurnOver = 0 ;
|
||||
|
||||
/*
|
||||
* log_default_path -- get default log file pathname
|
||||
*/
|
||||
|
||||
static void log_default_path(void)
|
||||
{
|
||||
#ifdef UNIX
|
||||
(void)strcpy(logFname, "/tmp/") ;
|
||||
(void)strcat(logFname, DEFAULT_LOGFILE) ;
|
||||
#endif
|
||||
#if defined(WIN32) || defined(OS2)
|
||||
{
|
||||
char *env;
|
||||
if ((env = getenv("TEMP")) == NULL)
|
||||
env = getenv("TMP");
|
||||
if (env != NULL &&
|
||||
strlen(env) + strlen(DEFAULT_LOGFILE) + 1 < sizeof(logFname)) {
|
||||
(void)strcpy(logFname, env);
|
||||
(void)strcat(logFname, "\\");
|
||||
(void)strcat(logFname, DEFAULT_LOGFILE);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* log_configure - configure logging (must be called after 'config_load')
|
||||
*/
|
||||
|
||||
void log_configure(int ac, char *av[])
|
||||
{
|
||||
int i, nArgs ;
|
||||
char **aArgs ;
|
||||
char *fn = NULL ;
|
||||
|
||||
if (config_query_value("log-file", &nArgs, &aArgs) == TRUE) {
|
||||
if (nArgs >= 2) {
|
||||
fn = aArgs[1] ;
|
||||
}
|
||||
}
|
||||
for (i = 1 ; i < ac ; i++) {
|
||||
if (strcmp(av[i], "-logfile") == 0) {
|
||||
fn = av[i+=1] ;
|
||||
}
|
||||
}
|
||||
if (fn != NULL && strlen(fn) < sizeof(logFname)) {
|
||||
strcpy(logFname, fn) ;
|
||||
} else {
|
||||
log_default_path();
|
||||
}
|
||||
|
||||
if (config_query_value("log-level", &nArgs, &aArgs) == TRUE) {
|
||||
int level ;
|
||||
|
||||
if (nArgs != 2) {
|
||||
WARN("syntax error at log-level line\n");
|
||||
} else if ((level = log_strtolevel(aArgs[1])) < 0) {
|
||||
WARN("invalid log level %s\n", aArgs[1]);
|
||||
} else {
|
||||
log_setlevel(level);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* log_terminate - terminate logging
|
||||
*/
|
||||
|
||||
void log_terminate(void)
|
||||
{
|
||||
if (logFptr != NULL) {
|
||||
fclose(logFptr) ;
|
||||
logFptr = NULL ;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* log_turnover_request - request turning over log
|
||||
* this function is intended for calling from singnal handler.
|
||||
*/
|
||||
|
||||
void log_turnover_request(void)
|
||||
{
|
||||
timeToTurnOver = 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* log_turnover - turn over log if requested
|
||||
*/
|
||||
|
||||
void log_turnover(void)
|
||||
{
|
||||
if (timeToTurnOver) {
|
||||
timeToTurnOver = 0;
|
||||
log_trace_printf("--- log file turned over\n");
|
||||
log_terminate() ;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* log_setlevel - set log level
|
||||
*/
|
||||
void log_setlevel(int level)
|
||||
{
|
||||
logLevel = level;
|
||||
}
|
||||
|
||||
/*
|
||||
* log_strtolevel - string to log level
|
||||
*/
|
||||
int log_strtolevel(char *s)
|
||||
{
|
||||
if ('0' <= s[0] && s[0] <= '9') {
|
||||
return atoi(s) ;
|
||||
} else if (!strcmp(s, "none")) {
|
||||
return LOGLEVEL_NONE;
|
||||
} else if (!strcmp(s, "fatal")) {
|
||||
return LOGLEVEL_FATAL;
|
||||
} else if (!strcmp(s, "warn") || !strcmp(s, "warning")) {
|
||||
return LOGLEVEL_WARN;
|
||||
} else if (!strcmp(s, "trace")) {
|
||||
return LOGLEVEL_TRACE;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* log_vprintf - as name describes
|
||||
*/
|
||||
|
||||
static void log_vprintf(int level, char *fmt, va_list arg_ptr)
|
||||
{
|
||||
char buff[512] ;
|
||||
|
||||
if (logLevel < level) {
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* format message
|
||||
*/
|
||||
|
||||
vsprintf(buff, fmt, arg_ptr) ;
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("%s", buff) ;
|
||||
fflush(stdout) ;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* log to file
|
||||
*/
|
||||
|
||||
if (*logFname == '\0') {
|
||||
return ; /* no logging file specified */
|
||||
}
|
||||
if (logFptr == NULL) {
|
||||
logFptr = fopen(logFname, "a") ;
|
||||
}
|
||||
if (logFptr != NULL) {
|
||||
fputs(buff, logFptr) ;
|
||||
fflush(logFptr) ;
|
||||
}
|
||||
#ifdef WIN32 /* For NT, having trouble with */
|
||||
fclose(logFptr) ; /* reading open'd logging file */
|
||||
logFptr = NULL ; /* so, close and re-open it */
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* log_fatal_printf, log_warn_printf, log_trace_printf - write out
|
||||
* fatal/warning/trace log to the log file
|
||||
*/
|
||||
|
||||
void log_fatal_printf(char *fmt, ...)
|
||||
{
|
||||
va_list arg_ptr ;
|
||||
|
||||
va_start(arg_ptr, fmt) ;
|
||||
log_vprintf(LOGLEVEL_FATAL, fmt, arg_ptr) ;
|
||||
va_end(arg_ptr) ;
|
||||
}
|
||||
|
||||
void log_warn_printf(char *fmt, ...)
|
||||
{
|
||||
va_list arg_ptr ;
|
||||
|
||||
va_start(arg_ptr, fmt) ;
|
||||
log_vprintf(LOGLEVEL_WARN, fmt, arg_ptr) ;
|
||||
va_end(arg_ptr) ;
|
||||
}
|
||||
|
||||
void log_trace_printf(char *fmt, ...)
|
||||
{
|
||||
va_list arg_ptr ;
|
||||
|
||||
va_start(arg_ptr, fmt) ;
|
||||
log_vprintf(LOGLEVEL_TRACE, fmt, arg_ptr) ;
|
||||
va_end(arg_ptr) ;
|
||||
}
|
||||
113
contrib/idn/mdnkit/dnsproxy/make.os2
Normal file
113
contrib/idn/mdnkit/dnsproxy/make.os2
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
#
|
||||
# Makefile for mDNS Proxy Server, OS2 version (for EMX/GCC)
|
||||
#
|
||||
# $Id: make.os2,v 1.1 2000/12/07 00:52:19 tale 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
# Tokyo, Japan.
|
||||
#
|
||||
# 1. Use, Modification and Redistribution (including distribution of any
|
||||
# modified or derived work) in source and/or binary forms is permitted
|
||||
# under this License Terms and Conditions.
|
||||
#
|
||||
# 2. Redistribution of source code must retain the copyright notices as they
|
||||
# appear in each source code file, this License Terms and Conditions.
|
||||
#
|
||||
# 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
# this License Terms and Conditions, in the documentation and/or other
|
||||
# materials provided with the distribution. For the purposes of binary
|
||||
# distribution the "Copyright Notice" refers to the following language:
|
||||
# "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
#
|
||||
# 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
# derived from this Software without specific prior written approval of
|
||||
# JPNIC.
|
||||
#
|
||||
# 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
#
|
||||
# 6. Indemnification by Licensee
|
||||
# Any person or entities using and/or redistributing this Software under
|
||||
# this License Terms and Conditions shall defend indemnify and hold
|
||||
# harmless JPNIC from and against any and all judgements damages,
|
||||
# expenses, settlement liabilities, cost and other liabilities of any
|
||||
# kind as a result of use and redistribution of this Software or any
|
||||
# claim, suite, action, litigation or proceeding by any third party
|
||||
# arising out of or relates to this License Terms and Conditions.
|
||||
#
|
||||
# 7. Governing Law, Jurisdiction and Venue
|
||||
# This License Terms and Conditions shall be governed by and and
|
||||
# construed in accordance with the law of Japan. Any person or entities
|
||||
# using and/or redistributing this Software under this License Terms and
|
||||
# Conditions hereby agrees and consent to the personal and exclusive
|
||||
# jurisdiction and venue of Tokyo District Court of Japan.
|
||||
#
|
||||
|
||||
ICONVDIR = ../os2
|
||||
MDNDIR = ../lib
|
||||
BINDIR = ../../bin/os2
|
||||
|
||||
CC = gcc -c
|
||||
CFLAGS = -Wall -Zmtd -I../include -I$(ICONVDIR) -DOS2 -DHAVE_UNISTD_H -DDEBUG
|
||||
LD = gcc
|
||||
LDFLAGS = -Zmtd
|
||||
|
||||
LIBS = $(MDNDIR)/libmdn.a $(ICONVDIR)/iconv.a
|
||||
SYSLIBS = -lsocket
|
||||
|
||||
#
|
||||
# Files to build mDNS Proxy
|
||||
#
|
||||
|
||||
SRCS = os2main.c server.c message.c translate.c logging.c proxycnf.c
|
||||
OBJS = os2main.o server.o message.o translate.o logging.o proxycnf.o
|
||||
|
||||
#
|
||||
# Target to build
|
||||
#
|
||||
|
||||
TARGETS = dnsproxy.exe $(ICONVDIR)/iconv.dll
|
||||
|
||||
all : $(TARGETS)
|
||||
|
||||
install : $(TARGETS)
|
||||
cp -p $(TARGETS) $(BINDIR)
|
||||
|
||||
dnsproxy.exe : $(OBJS) $(LIBS) dnsproxy.def
|
||||
$(LD) $(LDFLAGS) -o dnsproxy.exe dnsproxy.def $(OBJS) $(LIBS) $(SYSLIBS)
|
||||
|
||||
#
|
||||
# Dependecnies
|
||||
#
|
||||
|
||||
.c.o :
|
||||
$(CC) $(CFLAGS) $*.c
|
||||
|
||||
os2main.o : os2main.c dnsproxy.h
|
||||
|
||||
server.o : server.c dnsproxy.h
|
||||
|
||||
message.o : message.c dnsproxy.h
|
||||
|
||||
traslate.o : translate.c dnsproxy.h
|
||||
|
||||
logging.o : logging.c dnsproxy.h
|
||||
|
||||
proxycnf.o : proxycnf.c dnsproxy.h proxycnf.h
|
||||
125
contrib/idn/mdnkit/dnsproxy/make.wnt
Normal file
125
contrib/idn/mdnkit/dnsproxy/make.wnt
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
#
|
||||
# Makefile for mDNS Proxy Server, WINNT version
|
||||
#
|
||||
# $Id: make.wnt,v 1.1 2000/12/07 00:52:19 tale 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
# Tokyo, Japan.
|
||||
#
|
||||
# 1. Use, Modification and Redistribution (including distribution of any
|
||||
# modified or derived work) in source and/or binary forms is permitted
|
||||
# under this License Terms and Conditions.
|
||||
#
|
||||
# 2. Redistribution of source code must retain the copyright notices as they
|
||||
# appear in each source code file, this License Terms and Conditions.
|
||||
#
|
||||
# 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
# this License Terms and Conditions, in the documentation and/or other
|
||||
# materials provided with the distribution. For the purposes of binary
|
||||
# distribution the "Copyright Notice" refers to the following language:
|
||||
# "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
#
|
||||
# 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
# derived from this Software without specific prior written approval of
|
||||
# JPNIC.
|
||||
#
|
||||
# 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
#
|
||||
# 6. Indemnification by Licensee
|
||||
# Any person or entities using and/or redistributing this Software under
|
||||
# this License Terms and Conditions shall defend indemnify and hold
|
||||
# harmless JPNIC from and against any and all judgements damages,
|
||||
# expenses, settlement liabilities, cost and other liabilities of any
|
||||
# kind as a result of use and redistribution of this Software or any
|
||||
# claim, suite, action, litigation or proceeding by any third party
|
||||
# arising out of or relates to this License Terms and Conditions.
|
||||
#
|
||||
# 7. Governing Law, Jurisdiction and Venue
|
||||
# This License Terms and Conditions shall be governed by and and
|
||||
# construed in accordance with the law of Japan. Any person or entities
|
||||
# using and/or redistributing this Software under this License Terms and
|
||||
# Conditions hereby agrees and consent to the personal and exclusive
|
||||
# jurisdiction and venue of Tokyo District Court of Japan.
|
||||
#
|
||||
|
||||
!include <ntwin32.mak>
|
||||
|
||||
ICONVDIR = ..\win
|
||||
MDNDIR = ..\lib
|
||||
BINDIR = ..\..\bin\win
|
||||
|
||||
INCDIR = ..\include
|
||||
LIBS = $(MDNDIR)\libmdn.lib $(ICONVDIR)\iconv.lib
|
||||
SYSLIBS = $(conlibsdll)
|
||||
|
||||
#
|
||||
# Files to build mDNS Proxy
|
||||
#
|
||||
|
||||
HDRS = dnsproxy.h winserv.h
|
||||
|
||||
SRCS = winmain.c winserv.c server.c message.c translate.c \
|
||||
logging.c proxycnf.c
|
||||
OBJS = winmain.obj winserv.obj server.obj message.obj translate.obj \
|
||||
logging.obj proxycnf.obj
|
||||
|
||||
#
|
||||
# Target to build
|
||||
#
|
||||
|
||||
TARGETS = dnsproxy.exe $(ICONVDIR)\iconv.dll
|
||||
|
||||
all : $(TARGETS)
|
||||
|
||||
install : $(TARGETS)
|
||||
copy dnsproxy.exe $(BINDIR)
|
||||
copy $(ICONVDIR)\iconv.dll $(BINDIR)
|
||||
|
||||
dnsproxy.exe : $(OBJS) $(LIBS)
|
||||
$(link) $(conflags) -out:dnsproxy.exe $(OBJS) $(LIBS) $(SYSLIBS)
|
||||
|
||||
clean:
|
||||
del *.exe *.obj *.lib core *.core *~
|
||||
|
||||
#
|
||||
# Dependecnies
|
||||
#
|
||||
|
||||
winmain.obj : winmain.c $(HDRS)
|
||||
$(cc) $(cflags) $(cvarsdll) -I$(INCDIR) -DDEBUG $*.c
|
||||
|
||||
winserv.obj : winserv.c $(HDRS)
|
||||
$(cc) $(cflags) $(cvarsdll) -I$(INCDIR) -DDEBUG $*.c
|
||||
|
||||
server.obj : server.c $(HDRS)
|
||||
$(cc) $(cflags) $(cvarsdll) -I$(INCDIR) -DDEBUG $*.c
|
||||
|
||||
message.obj : message.c $(HDRS)
|
||||
$(cc) $(cflags) $(cvarsdll) -I$(INCDIR) -DDEBUG $*.c
|
||||
|
||||
translate.obj : translate.c $(HDRS)
|
||||
$(cc) $(cflags) $(cvarsdll) -I$(INCDIR) -DDEBUG $*.c
|
||||
|
||||
logging.obj : logging.c $(HDRS)
|
||||
$(cc) $(cflags) $(cvarsdll) -I$(INCDIR) -DDEBUG $*.c
|
||||
|
||||
proxycnf.obj : proxycnf.c $(HDRS)
|
||||
$(cc) $(cflags) $(cvarsdll) -I$(INCDIR) -DDEBUG $*.c
|
||||
627
contrib/idn/mdnkit/dnsproxy/message.c
Normal file
627
contrib/idn/mdnkit/dnsproxy/message.c
Normal file
|
|
@ -0,0 +1,627 @@
|
|||
/*
|
||||
* message.c - mDNS Proxy, message handling
|
||||
*
|
||||
* message will passed with callback 'notify_message'.
|
||||
* this module parse received message and forward request,
|
||||
* or reply to originator
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char *rcsid = "$Id: message.c,v 1.18 2000/11/17 05:46:23 ishisone Exp $";
|
||||
#endif
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#include <winsock.h>
|
||||
#else /* for normal systems */
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
|
||||
#include "dnsproxy.h"
|
||||
|
||||
/*
|
||||
* address handling utilities
|
||||
*
|
||||
* addrEq check same addresses
|
||||
* addrFmt format address, port & protocol
|
||||
*
|
||||
* these functions are same with those in 'server.c'.
|
||||
* may be put in another 'utility' module.
|
||||
*/
|
||||
|
||||
static BOOL addrEq(struct sockaddr *a1, struct sockaddr *a2)
|
||||
{
|
||||
struct sockaddr_in *ip1 = (struct sockaddr_in *) a1 ;
|
||||
struct sockaddr_in *ip2 = (struct sockaddr_in *) a2 ;
|
||||
|
||||
if (ip1->sin_addr.s_addr != ip2->sin_addr.s_addr) {
|
||||
return FALSE ;
|
||||
}
|
||||
if (ip1->sin_port != ip2->sin_port) {
|
||||
return FALSE ;
|
||||
}
|
||||
return TRUE ;
|
||||
}
|
||||
|
||||
static u_char fmtbuff[64] ;
|
||||
|
||||
static u_char *addrFmt(struct sockaddr *addr, int proto)
|
||||
{
|
||||
struct sockaddr_in *iaddr = (struct sockaddr_in *) addr ;
|
||||
u_char *ap ;
|
||||
u_char *pp ;
|
||||
|
||||
ap = (u_char *) &iaddr->sin_addr ;
|
||||
pp = (u_char *) &iaddr->sin_port ;
|
||||
|
||||
sprintf(fmtbuff, "%s:%d.%d.%d.%d:%d",
|
||||
(proto == SOCK_STREAM ? "TCP" : "UDP"),
|
||||
(ap[0] & 0xff), (ap[1] & 0xff), (ap[2] & 0xff), (ap[3] & 0xff),
|
||||
((pp[0] & 0xff) * 256 + (pp[1] & 0xff)) ) ;
|
||||
|
||||
return fmtbuff ;
|
||||
}
|
||||
|
||||
/*
|
||||
* Managing Message ID
|
||||
*/
|
||||
|
||||
static u_short msgidLast = 0xffff ;
|
||||
static u_short msgidMap[4096] = { 0 } ;
|
||||
|
||||
#define ID_INDEX(x) (((x) & 0xfff0) >> 4)
|
||||
#define ID_MASK(x) (1 << ((x) & 0x000f))
|
||||
|
||||
#define ID_CHECK(x) (msgidMap[ID_INDEX((x))] & ID_MASK((x)))
|
||||
#define ID_USEIT(x) (msgidMap[ID_INDEX((x))] |= ID_MASK((x)))
|
||||
#define ID_CLEAR(x) (msgidMap[ID_INDEX((x))] &= ~ID_MASK((x)))
|
||||
|
||||
static BOOL idAlloc(u_short *id)
|
||||
{
|
||||
u_short newid ;
|
||||
|
||||
for (newid = (msgidLast + 1) & 0xffff ;
|
||||
newid != msgidLast ;
|
||||
newid = (newid + 1) & 0xffff) {
|
||||
if (ID_CHECK(newid) == 0) {
|
||||
ID_USEIT(newid) ;
|
||||
msgidLast = newid ;
|
||||
*id = newid ;
|
||||
return TRUE ;
|
||||
}
|
||||
}
|
||||
WARN("idAlloc - no more ID\n") ;
|
||||
return FALSE ;
|
||||
}
|
||||
|
||||
static void idFree(u_short id)
|
||||
{
|
||||
if (ID_CHECK(id) == 0) {
|
||||
WARN("idAlloc - %04x is not in use\n", id) ;
|
||||
return ;
|
||||
}
|
||||
ID_CLEAR(id) ;
|
||||
}
|
||||
|
||||
/*
|
||||
* Message Managements
|
||||
*
|
||||
* Request from client is identified with its ID word. It is unique
|
||||
* on one client, but proxy accepts requests from multiple clients,
|
||||
* proxy cannot distinguish request with ID only, and cannot forward
|
||||
* request with such ID word.
|
||||
*
|
||||
* So, proxy will identify requests with combination of address, port,
|
||||
* (which identified client) and ID word. Then forwarding request,
|
||||
* proxy allocate unique ID, and change request's ID with new one.
|
||||
*
|
||||
* Response from DNS server will identified with newly allocated ID.
|
||||
* For responding such response to originator, replace response's
|
||||
* ID with original one, and send response to marked address/port.
|
||||
*/
|
||||
|
||||
typedef struct _MSG *MSGPTR ;
|
||||
|
||||
typedef struct _MSG {
|
||||
MSGPTR prev ;
|
||||
MSGPTR next ;
|
||||
time_t last ;
|
||||
struct sockaddr from ;
|
||||
int proto ;
|
||||
u_short orgId ;
|
||||
u_short newId ;
|
||||
translation_context_t trctx ;
|
||||
} MSGREC ;
|
||||
|
||||
static MSGREC listMsg = { 0 } ;
|
||||
|
||||
/*
|
||||
* searchReq - search request in message list, search on original ID
|
||||
*/
|
||||
|
||||
static MSGPTR searchReq(u_short id, int proto, struct sockaddr *addr)
|
||||
{
|
||||
MSGPTR p ;
|
||||
|
||||
if (listMsg.prev == NULL || listMsg.next == NULL) {
|
||||
listMsg.prev = &listMsg ;
|
||||
listMsg.next = &listMsg ;
|
||||
}
|
||||
for (p = listMsg.next ; p != &listMsg ; p = p->next) {
|
||||
if (p->orgId != id || p->proto != proto) {
|
||||
continue ;
|
||||
}
|
||||
if (addrEq(&p->from, addr) != TRUE) {
|
||||
continue ;
|
||||
}
|
||||
p->last = time(NULL) ;
|
||||
return p ;
|
||||
}
|
||||
return NULL ;
|
||||
}
|
||||
|
||||
/*
|
||||
* searchOrg - search original request matching to new ID
|
||||
*/
|
||||
|
||||
static MSGPTR searchOrg(u_short id, int proto)
|
||||
{
|
||||
MSGPTR p ;
|
||||
|
||||
if (listMsg.prev == NULL || listMsg.next == NULL) {
|
||||
listMsg.prev = &listMsg ;
|
||||
listMsg.next = &listMsg ;
|
||||
}
|
||||
for (p = listMsg.next ; p != &listMsg ; p = p->next) {
|
||||
if (p->newId != id || p->proto != proto) {
|
||||
continue ;
|
||||
}
|
||||
p->last = time(NULL) ;
|
||||
return p ;
|
||||
}
|
||||
return NULL ;
|
||||
}
|
||||
|
||||
/*
|
||||
* createReq - create new message record for new request
|
||||
*
|
||||
* it also allocate new ID for this request, used for
|
||||
* forwarding this request
|
||||
*/
|
||||
|
||||
static MSGPTR createReq(u_short id, int proto, struct sockaddr *addr)
|
||||
{
|
||||
u_short newid ;
|
||||
MSGPTR pMsg, prev, next ;
|
||||
|
||||
if (listMsg.prev == NULL || listMsg.next == NULL) {
|
||||
listMsg.prev = &listMsg ;
|
||||
listMsg.next = &listMsg ;
|
||||
}
|
||||
|
||||
if (idAlloc(&newid) != TRUE) {
|
||||
WARN("createReq - no more ID\n") ;
|
||||
return NULL ;
|
||||
}
|
||||
if ((pMsg = (MSGPTR) malloc(sizeof(MSGREC))) == NULL) {
|
||||
WARN("createReq - cannot allocate message record\n") ;
|
||||
idFree(newid) ;
|
||||
return NULL ;
|
||||
}
|
||||
|
||||
memset(pMsg, 0, sizeof(MSGREC)) ;
|
||||
|
||||
memcpy(&pMsg->from, addr, sizeof(struct sockaddr)) ;
|
||||
pMsg->proto = proto ;
|
||||
pMsg->orgId = id ;
|
||||
pMsg->newId = newid ;
|
||||
pMsg->last = time(NULL) ;
|
||||
|
||||
pMsg->trctx.client = &pMsg->from ;
|
||||
pMsg->trctx.protocol = pMsg->proto ;
|
||||
pMsg->trctx.old_id = pMsg->orgId ;
|
||||
pMsg->trctx.new_id = pMsg->newId ;
|
||||
|
||||
prev = listMsg.prev ;
|
||||
next = prev->next ;
|
||||
|
||||
prev->next = pMsg ;
|
||||
next->prev = pMsg ;
|
||||
pMsg->prev = prev ;
|
||||
pMsg->next = next ;
|
||||
|
||||
return pMsg ;
|
||||
}
|
||||
|
||||
/*
|
||||
* disposeReq - dispose message record
|
||||
*/
|
||||
|
||||
static void disposeReq(MSGPTR pMsg)
|
||||
{
|
||||
MSGPTR p ;
|
||||
|
||||
if (listMsg.prev == NULL || listMsg.next == NULL) {
|
||||
listMsg.prev = &listMsg ;
|
||||
listMsg.next = &listMsg ;
|
||||
}
|
||||
|
||||
for (p = listMsg.next ; p != &listMsg ; p = p->next) {
|
||||
if (p == pMsg) {
|
||||
break ;
|
||||
}
|
||||
}
|
||||
if (p == pMsg) { /* safe to unlink it */
|
||||
pMsg->prev->next = pMsg->next ;
|
||||
pMsg->next->prev = pMsg->prev ;
|
||||
}
|
||||
idFree(pMsg->newId) ;
|
||||
free(pMsg) ;
|
||||
}
|
||||
|
||||
/*
|
||||
* messageForward - forward the request
|
||||
*/
|
||||
|
||||
static void errorOnRequest(MSGPTR pMsg, u_char *msg, int len, size_t err)
|
||||
{
|
||||
u_short errmsg[6] ;
|
||||
u_short flags ;
|
||||
u_short *ps ;
|
||||
|
||||
TRACE("errorOnRequest %d\n", err) ;
|
||||
|
||||
ps = (u_short *) msg ;
|
||||
flags = ntohs(ps[1]) ;
|
||||
flags = ((flags & 0x7fff) | 0x8000) ; /* QR to response */
|
||||
flags = ((flags & 0xfff8) | (err & 0x0007)) ; /* set RCODE */
|
||||
|
||||
memset(errmsg, 0, sizeof(errmsg)) ;
|
||||
errmsg[0] = htons(pMsg->orgId) ;
|
||||
errmsg[1] = htons(flags) ;
|
||||
|
||||
server_response(&pMsg->from, pMsg->proto, (u_char *) errmsg, sizeof(errmsg)) ;
|
||||
}
|
||||
|
||||
static void messageForward(MSGPTR pMsg, u_char *msg, int len)
|
||||
{
|
||||
u_short *p ;
|
||||
u_char buff[1024] ;
|
||||
u_char *bbase ;
|
||||
size_t bleng ;
|
||||
size_t cleng = 0 ; /* avoid un-expected length on xlate error */
|
||||
size_t cstat = 0 ; /* avoid un-expected status on xlate error */
|
||||
|
||||
TRACE("messageForward - %04x -> %04x\n", pMsg->orgId, pMsg->newId) ;
|
||||
|
||||
/*
|
||||
* prepare conversion buffer
|
||||
*/
|
||||
|
||||
if (len < sizeof(buff) / 2) {
|
||||
bbase = buff ;
|
||||
bleng = sizeof(buff) ;
|
||||
} else {
|
||||
bbase = malloc(len * 2) ;
|
||||
bleng = len * 2 ;
|
||||
}
|
||||
if (bbase == NULL) {
|
||||
WARN("messageForward - cannot prepare conversion buffer\n") ;
|
||||
return ;
|
||||
}
|
||||
|
||||
/*
|
||||
* translate message (domain names)
|
||||
*/
|
||||
|
||||
TRACE("messageForward - translate request\n") ;
|
||||
|
||||
cstat = translate_request(&pMsg->trctx, msg, len, bbase, bleng, &cleng) ;
|
||||
|
||||
TRACE("messageForward - translated status %d length %d\n", cstat, cleng) ;
|
||||
|
||||
if (cstat != 0) { /* error on conversion */
|
||||
WARN("messageForward - translation error %d\n", cstat) ;
|
||||
errorOnRequest(pMsg, msg, len, cstat) ;
|
||||
return ;
|
||||
}
|
||||
if (pMsg->proto == SOCK_DGRAM && cleng > 512) {
|
||||
WARN("messageForward - translation overflow %d\n", cleng) ;
|
||||
errorOnRequest(pMsg, msg, len, 2) ;
|
||||
return ;
|
||||
}
|
||||
|
||||
/*
|
||||
* forward the request
|
||||
*/
|
||||
|
||||
p = (u_short *) bbase ;
|
||||
p[0] = htons(pMsg->newId) ;
|
||||
|
||||
server_forward(NULL, pMsg->proto, bbase, cleng) ;
|
||||
|
||||
/*
|
||||
* cleanup buffer
|
||||
*/
|
||||
|
||||
if (bbase != buff) {
|
||||
free(bbase) ;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* messageResponse - response to originating client
|
||||
*/
|
||||
|
||||
static void errorOnResponse(MSGPTR pMsg, u_char *msg, int len, size_t err)
|
||||
{
|
||||
u_short errmsg[6] ;
|
||||
u_short flags ;
|
||||
u_short *ps ;
|
||||
|
||||
TRACE("errorOnResponse %d\n", err) ;
|
||||
|
||||
ps = (u_short *) msg ;
|
||||
flags = ntohs(ps[1]) ;
|
||||
flags = ((flags & 0x7fff) | 0x8000) ; /* QR to response */
|
||||
flags = ((flags & 0xfff8) | (err & 0x0007)) ; /* set RCODE */
|
||||
|
||||
memset(errmsg, 0, sizeof(errmsg)) ;
|
||||
errmsg[0] = htons(pMsg->orgId) ;
|
||||
errmsg[1] = htons(flags) ;
|
||||
|
||||
server_response(&pMsg->from, pMsg->proto, (u_char *) errmsg, sizeof(errmsg)) ;
|
||||
}
|
||||
|
||||
static void messageResponse(MSGPTR pMsg, u_char *msg, int len)
|
||||
{
|
||||
u_short *p ;
|
||||
u_char buff[1024] ;
|
||||
u_char *bbase ;
|
||||
size_t bleng ;
|
||||
size_t cleng ;
|
||||
size_t cstat ;
|
||||
|
||||
TRACE("messageResponse - %04x <- %04x\n", pMsg->orgId, pMsg->newId) ;
|
||||
|
||||
/*
|
||||
* prepare conversion buffer
|
||||
*/
|
||||
|
||||
if (len < sizeof(buff) / 2) {
|
||||
bbase = buff ;
|
||||
bleng = sizeof(buff) ;
|
||||
} else {
|
||||
bbase = malloc(len * 2) ;
|
||||
bleng = len * 2 ;
|
||||
}
|
||||
if (bbase == NULL) {
|
||||
WARN("messageResponse - cannot prepare conversion buffer\n") ;
|
||||
return ;
|
||||
}
|
||||
|
||||
/*
|
||||
* translate message (domain names)
|
||||
*/
|
||||
|
||||
TRACE("messageResponse - translate response\n") ;
|
||||
|
||||
cstat = translate_reply(&pMsg->trctx, msg, len, bbase, bleng, &cleng) ;
|
||||
|
||||
TRACE("messageResponse - translated status %d length %d\n", cstat, cleng) ;
|
||||
|
||||
if (cstat != 0) { /* error on conversion */
|
||||
WARN("messageResponse - translation error %d\n", cstat) ;
|
||||
errorOnResponse(pMsg, msg, len, cstat) ;
|
||||
return ;
|
||||
}
|
||||
if (pMsg->proto == SOCK_DGRAM && cleng > 512) {
|
||||
WARN("messageResponse - translation overflow %d\n", cleng) ;
|
||||
errorOnResponse(pMsg, msg, len, 2) ;
|
||||
return ;
|
||||
}
|
||||
|
||||
/*
|
||||
* reply back to requester
|
||||
*/
|
||||
|
||||
p = (u_short *) bbase ;
|
||||
p[0] = htons(pMsg->orgId) ;
|
||||
|
||||
server_response(&pMsg->from, pMsg->proto, bbase, cleng) ;
|
||||
|
||||
/*
|
||||
* cleanup buffer
|
||||
*/
|
||||
|
||||
if (bbase != buff) {
|
||||
free(bbase) ;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* notify_message - callback from server loop
|
||||
*/
|
||||
|
||||
void notify_message(struct sockaddr *from, int proto, u_char *msg, int len)
|
||||
{
|
||||
u_short *p = (u_short *) msg ;
|
||||
u_short msgid, flags ;
|
||||
MSGPTR pMsg ;
|
||||
#ifdef DEBUG
|
||||
char logbuf[256] ;
|
||||
#endif
|
||||
|
||||
msgid = ntohs(p[0]) ;
|
||||
flags = ntohs(p[1]) ;
|
||||
|
||||
#ifdef DEBUG
|
||||
if ((flags & 0x8000) == 0) {
|
||||
sprintf(logbuf, "Request %04x (%04x) from %s, %d bytes",
|
||||
msgid, flags, addrFmt(from, proto), len) ;
|
||||
} else {
|
||||
sprintf(logbuf, "Response %04x (%04x) from %s %d bytes",
|
||||
msgid, flags, addrFmt(from, proto), len) ;
|
||||
}
|
||||
TRACE("%s\n", logbuf) ;
|
||||
|
||||
strcpy(logbuf, " ") ;
|
||||
|
||||
switch ((flags & 0x7800) >> 11) {
|
||||
case 0 : strcat(logbuf, "QUERY ") ; break ;
|
||||
case 1 : strcat(logbuf, "IQUERY ") ; break ;
|
||||
case 2 : strcat(logbuf, "STATUS ") ; break ;
|
||||
default : strcat(logbuf, "UNKNOWN") ; break ;
|
||||
}
|
||||
if ((flags & 0x0400) != 0) {
|
||||
strcat(logbuf, ",AA") ;
|
||||
}
|
||||
if ((flags & 0x0200) != 0) {
|
||||
strcat(logbuf, ",TC") ;
|
||||
}
|
||||
if ((flags & 0x0100) != 0) {
|
||||
strcat(logbuf, ",RD") ;
|
||||
}
|
||||
if ((flags & 0x0080) != 0) {
|
||||
strcat(logbuf, ",RA") ;
|
||||
}
|
||||
switch (flags & 0x00f) {
|
||||
case 0 : strcat(logbuf, ",No Error ") ; break ;
|
||||
case 1 : strcat(logbuf, ",Format Error ") ; break ;
|
||||
case 2 : strcat(logbuf, ",Server Failure ") ; break ;
|
||||
case 3 : strcat(logbuf, ",Name Error ") ; break ;
|
||||
case 4 : strcat(logbuf, ",Not Implemented") ; break ;
|
||||
case 5 : strcat(logbuf, ",Refused ") ; break ;
|
||||
default : strcat(logbuf, ",Unknown Error ") ; break ;
|
||||
}
|
||||
TRACE("%s\n", logbuf) ;
|
||||
#endif
|
||||
|
||||
if ((flags & 0x8000) == 0) { /* request from client */
|
||||
|
||||
if ((pMsg = searchReq(msgid, proto, from)) == NULL) {
|
||||
pMsg = createReq(msgid, proto, from) ;
|
||||
}
|
||||
if (pMsg == NULL) {
|
||||
WARN("notify_message - cannot create message record\n") ;
|
||||
return ;
|
||||
}
|
||||
messageForward(pMsg, msg, len) ;
|
||||
|
||||
} else { /* response from server */
|
||||
|
||||
if ((pMsg = searchOrg(msgid, proto)) == NULL) {
|
||||
WARN("notify_message - no corresponding request\n") ;
|
||||
return ;
|
||||
}
|
||||
messageResponse(pMsg, msg, len) ;
|
||||
disposeReq(pMsg);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* notify_timer - timer callback
|
||||
*/
|
||||
|
||||
static time_t timeLastCheck = 0 ;
|
||||
static time_t timeInterval = 60 ;
|
||||
static time_t timeTimeout = (60 * 10) ;
|
||||
|
||||
void notify_timer(void)
|
||||
{
|
||||
time_t t = time(NULL) ;
|
||||
MSGPTR p, np ;
|
||||
#ifdef DEBUG
|
||||
int ndiscarded = 0;
|
||||
#endif
|
||||
|
||||
if (listMsg.prev == NULL || listMsg.next == NULL) {
|
||||
listMsg.prev = &listMsg ;
|
||||
listMsg.next = &listMsg ;
|
||||
}
|
||||
|
||||
if ((t - timeLastCheck) < timeInterval) {
|
||||
return ;
|
||||
}
|
||||
for (p = listMsg.next ; p != &listMsg ; p = np) {
|
||||
np = p->next ;
|
||||
if ((t - p->last) > timeTimeout) {
|
||||
disposeReq(p) ;
|
||||
#ifdef DEBUG
|
||||
ndiscarded++;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#ifdef DEBUG
|
||||
TRACE("notify_timer: %d discarded\n", ndiscarded);
|
||||
#endif
|
||||
timeLastCheck = t;
|
||||
}
|
||||
138
contrib/idn/mdnkit/dnsproxy/os2main.c
Normal file
138
contrib/idn/mdnkit/dnsproxy/os2main.c
Normal file
|
|
@ -0,0 +1,138 @@
|
|||
/*
|
||||
* os2main.c - mDNS Proxy, entry for OS2
|
||||
*
|
||||
* For OS/2, there are no daemon, nor service. Simply
|
||||
* start server program with
|
||||
*
|
||||
* RUN in config.sys
|
||||
* START in startup.cmd
|
||||
* put server program (object) into startup folder
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char *rcsid = "$Id: os2main.c,v 1.12 2000/07/04 03:52:28 ishisone Exp $";
|
||||
#endif
|
||||
|
||||
#ifdef OS2
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "dnsproxy.h" /* Common definitions for mDNS proxy */
|
||||
|
||||
/*
|
||||
* signal handler to catch signal to terminate server
|
||||
*/
|
||||
|
||||
static void handler(int signo)
|
||||
{
|
||||
server_stop() ;
|
||||
signal(signo, SIG_DFL) ;
|
||||
}
|
||||
|
||||
/*
|
||||
* main - entry of os2 version
|
||||
*/
|
||||
|
||||
int main(int ac, char *av[])
|
||||
{
|
||||
if (config_load(ac, av) != TRUE) {
|
||||
printf("cannot load configurations\n") ;
|
||||
return 1 ;
|
||||
}
|
||||
log_configure(ac, av) ;
|
||||
|
||||
if (server_init(ac, av) != TRUE) {
|
||||
printf("cannot initialize server\n") ;
|
||||
log_terminate() ;
|
||||
return 1 ;
|
||||
}
|
||||
|
||||
signal(SIGINT, handler) ;
|
||||
signal(SIGKILL, handler) ;
|
||||
signal(SIGTERM, handler) ;
|
||||
signal(SIGBREAK, handler) ;
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("Service Started\n") ;
|
||||
#endif
|
||||
|
||||
server_loop() ;
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("Service Termiating...\n") ;
|
||||
#endif
|
||||
|
||||
server_done() ;
|
||||
|
||||
log_terminate() ;
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("Service Terminated\n") ;
|
||||
#endif
|
||||
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
#endif /* OS2 */
|
||||
|
||||
776
contrib/idn/mdnkit/dnsproxy/proxycnf.c
Normal file
776
contrib/idn/mdnkit/dnsproxy/proxycnf.c
Normal file
|
|
@ -0,0 +1,776 @@
|
|||
/*
|
||||
* proxycnf.c - mDNS Proxy, configuration
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char *rcsid = "$Id: proxycnf.c,v 1.16 2000/11/17 05:46:23 ishisone Exp $";
|
||||
#endif
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#include <winsock.h>
|
||||
#else /* for normal systems */
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
#include "dnsproxy.h" /* Common definitions for mDNS proxy */
|
||||
#include "proxycnf.h" /* Machine/Env specific configuration */
|
||||
|
||||
/*
|
||||
* Note that logging macros (FATAL, WARN and TRACE) cannot be used
|
||||
* until logging file is configured, i.e. log_configure() is called.
|
||||
* Be careful.
|
||||
*/
|
||||
|
||||
/*
|
||||
* default config file (path & basename), depend on MACHINE
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_PATH
|
||||
#warning "no \"CONFIG_PATH\", use "\"./\" as default"
|
||||
#define CONFIG_PATH "./"
|
||||
#endif
|
||||
#ifndef CONFIG_FILE
|
||||
#warning "no \"CONFIG_FILE\", use "dnsproxy.ini" as default"
|
||||
#define CONFIG_FILE "dnsproxy.ini"
|
||||
#endif
|
||||
#ifndef CONFIG_HOME
|
||||
#warning "no \"CONFIG_HOME\", use "\"./\" as default"
|
||||
#define CONFIG_HOME "./"
|
||||
#endif
|
||||
|
||||
static u_char *confFile = CONFIG_FILE ;
|
||||
|
||||
static u_char *confPath[] = {
|
||||
#ifdef DEBUG
|
||||
"./",
|
||||
CONFIG_HOME,
|
||||
#endif
|
||||
CONFIG_PATH,
|
||||
NULL
|
||||
} ;
|
||||
|
||||
static u_char *expandName(u_char *name, u_char *buff)
|
||||
{
|
||||
int inEnv = FALSE ;
|
||||
u_char *bp, *ep ;
|
||||
u_char env[512] ;
|
||||
|
||||
for (bp = buff, ep = env ; *name != '\0' ; name++) {
|
||||
if (inEnv == FALSE) {
|
||||
if (*name == '$') {
|
||||
inEnv = TRUE ;
|
||||
ep = env ;
|
||||
} else {
|
||||
*bp++ = *name ;
|
||||
*bp = '\0' ;
|
||||
}
|
||||
} else {
|
||||
if (*name == '(') {
|
||||
/* skip this */
|
||||
} else if (*name != ')') {
|
||||
*ep++ = *name ;
|
||||
*ep = '\0' ;
|
||||
} else if ((ep = getenv(env)) == NULL) {
|
||||
return NULL ;
|
||||
} else {
|
||||
while (*ep != '\0') {
|
||||
*bp++ = *ep++ ;
|
||||
}
|
||||
*bp = '\0' ;
|
||||
inEnv = FALSE ;
|
||||
}
|
||||
}
|
||||
}
|
||||
return buff ;
|
||||
}
|
||||
|
||||
static FILE *openConfig(u_char *fname)
|
||||
{
|
||||
int i ;
|
||||
FILE *fp = NULL ;
|
||||
u_char path[512] ;
|
||||
u_char name[512] ;
|
||||
|
||||
/*
|
||||
* if coinfiguration file specified, open it
|
||||
*/
|
||||
|
||||
if (fname != NULL) {
|
||||
if (expandName(fname, name) == NULL) {
|
||||
return NULL ;
|
||||
}
|
||||
if ((fp = fopen(name, "r")) == NULL) {
|
||||
return NULL ;
|
||||
}
|
||||
return fp ;
|
||||
}
|
||||
|
||||
/*
|
||||
* otherwise, look for configuration file in search path
|
||||
*/
|
||||
|
||||
for (i = 0 ; confPath[i] != NULL ; i++) {
|
||||
|
||||
if (expandName(confPath[i], path) == NULL) {
|
||||
continue ;
|
||||
}
|
||||
|
||||
sprintf(name, "%s%s", path, confFile) ;
|
||||
|
||||
if ((fp = fopen(name, "r")) != NULL) {
|
||||
return fp ;
|
||||
}
|
||||
}
|
||||
return NULL ;
|
||||
}
|
||||
|
||||
/*
|
||||
* configuration data in file consists of
|
||||
*
|
||||
* key value ...
|
||||
*
|
||||
* lines. This module hold them as following list.
|
||||
*/
|
||||
|
||||
typedef struct _CONF *CNFPTR ;
|
||||
|
||||
typedef struct _CONF {
|
||||
CNFPTR prev ;
|
||||
CNFPTR next ;
|
||||
u_char *key ; /* really, buffer for key & val */
|
||||
int nVal ;
|
||||
u_char *aVal[1] ; /* really, follows 'nVal' entries */
|
||||
} CNFREC ;
|
||||
|
||||
static CNFREC confList = { 0 } ;
|
||||
|
||||
static void disposeData(void)
|
||||
{
|
||||
CNFPTR p ;
|
||||
|
||||
if (confList.prev == NULL || confList.next == NULL) {
|
||||
return ;
|
||||
}
|
||||
while ((p = confList.next) != &confList) {
|
||||
confList.next = p->next ;
|
||||
free(p->key) ;
|
||||
free(p) ;
|
||||
}
|
||||
}
|
||||
|
||||
static u_char *getString(u_char *p, CNFPTR pCnf)
|
||||
{
|
||||
/*
|
||||
* mark start of value string
|
||||
*/
|
||||
|
||||
pCnf->aVal[pCnf->nVal++] = p ;
|
||||
|
||||
/*
|
||||
* look for end of string, any space
|
||||
*/
|
||||
|
||||
for ( ; *p != '\0' ; p++) {
|
||||
if (isspace(*p)) {
|
||||
break ;
|
||||
}
|
||||
}
|
||||
if (*p != '\0') {
|
||||
*p++ = '\0' ;
|
||||
}
|
||||
return p ;
|
||||
}
|
||||
|
||||
static u_char *getQuoted(u_char *p, CNFPTR pCnf)
|
||||
{
|
||||
if (*p != '"') { /* Oh, something wrong !! */
|
||||
return p ;
|
||||
}
|
||||
p++ ; /* skip leading '"' */
|
||||
|
||||
/*
|
||||
* mark start of value string
|
||||
*/
|
||||
|
||||
pCnf->aVal[pCnf->nVal++] = p ;
|
||||
|
||||
/*
|
||||
* look for terminating '"', may be escaped with '\'
|
||||
*/
|
||||
|
||||
while (*p != '\0' && *p != '\n' && *p != '\r') {
|
||||
if (*p == '"') {
|
||||
break ;
|
||||
} else if (*p == '\\') { /* quoted pair */
|
||||
p += 2 ;
|
||||
} else {
|
||||
p += 1 ;
|
||||
}
|
||||
}
|
||||
if (*p != '\0') {
|
||||
*p++ = '\0' ;
|
||||
}
|
||||
return p ;
|
||||
}
|
||||
|
||||
static BOOL appendData(u_char *line)
|
||||
{
|
||||
int len ;
|
||||
u_char *pStr, *p ;
|
||||
CNFPTR pCnf, pNew ;
|
||||
CNFPTR prev, next ;
|
||||
|
||||
/*
|
||||
* list is not initialized, initialize it
|
||||
*/
|
||||
|
||||
if (confList.prev == NULL || confList.next == NULL) {
|
||||
confList.prev = &confList ;
|
||||
confList.next = &confList ;
|
||||
}
|
||||
|
||||
/*
|
||||
* prepare buffers
|
||||
*/
|
||||
|
||||
len = strlen(line) ;
|
||||
|
||||
pCnf = (CNFPTR) malloc(sizeof(CNFREC) + sizeof(u_char *) * len) ;
|
||||
pStr = malloc(len + 2) ;
|
||||
|
||||
if (pStr == NULL || pCnf == NULL) {
|
||||
fprintf(stderr, "configure - cannot allocate parsing buffer\n") ;
|
||||
if (pStr != NULL) free(pStr) ;
|
||||
if (pCnf != NULL) free(pCnf) ;
|
||||
return FALSE ;
|
||||
}
|
||||
|
||||
memset(pCnf, 0, sizeof(CNFREC)) ;
|
||||
|
||||
for (p = pStr ; *line != '\0' ; ) {
|
||||
if (*line == '\n' || *line == '\r') {
|
||||
break ;
|
||||
}
|
||||
*p++ = *line++ ;
|
||||
}
|
||||
*p = '\0' ;
|
||||
|
||||
/*
|
||||
* parse line (save results into pCnf)
|
||||
*
|
||||
* term may be string or quoted-string
|
||||
*/
|
||||
|
||||
for (p = pStr ; *p != '\0' ; ) {
|
||||
if (isspace(*p)) {
|
||||
p += 1 ;
|
||||
} else if (*p == '#') {
|
||||
break ;
|
||||
} else if (*p == '"') {
|
||||
p = getQuoted(p, pCnf) ;
|
||||
} else {
|
||||
p = getString(p, pCnf) ;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* if no term found, skip the line
|
||||
*/
|
||||
|
||||
if (pCnf->nVal == 0) {
|
||||
free(pStr) ;
|
||||
free(pCnf) ;
|
||||
return TRUE ;
|
||||
}
|
||||
|
||||
/*
|
||||
* create resulting CNF record
|
||||
*/
|
||||
|
||||
pNew = (CNFPTR) malloc(sizeof(CNFREC) + sizeof(u_char *) * pCnf->nVal) ;
|
||||
|
||||
if (pNew == NULL) {
|
||||
fprintf(stderr, "configure - cannot allocate parsed record\n") ;
|
||||
free(pStr) ;
|
||||
free(pCnf) ;
|
||||
return FALSE ;
|
||||
}
|
||||
|
||||
memset(pNew, 0, sizeof(CNFREC)) ;
|
||||
|
||||
pNew->key = pStr ;
|
||||
pNew->nVal = pCnf->nVal ;
|
||||
memcpy(pNew->aVal, pCnf->aVal, sizeof(u_char *) * pCnf->nVal) ;
|
||||
|
||||
free(pCnf) ;
|
||||
|
||||
/*
|
||||
* link to list
|
||||
*/
|
||||
|
||||
prev = confList.prev ;
|
||||
next = prev->next ;
|
||||
pNew->prev = confList.prev ;
|
||||
pNew->next = &confList ;
|
||||
prev->next = pNew ;
|
||||
next->prev = pNew ;
|
||||
|
||||
return TRUE ;
|
||||
}
|
||||
|
||||
/*
|
||||
* config_load - load mDNS Proxy configuration data
|
||||
*/
|
||||
|
||||
BOOL config_load(int ac, char *av[])
|
||||
{
|
||||
int i ;
|
||||
u_char *conf ;
|
||||
FILE *fp ;
|
||||
u_char line[512] ;
|
||||
|
||||
/*
|
||||
* check if alternate config file specified
|
||||
*/
|
||||
|
||||
for (i = 1, conf = NULL ; i < ac ; i++) {
|
||||
if (strcmp(av[i], "-config") == 0) {
|
||||
if ((i + 1) < ac) {
|
||||
conf = av[i+=1] ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* open configuration file
|
||||
*/
|
||||
|
||||
if ((fp = openConfig(conf)) == NULL) {
|
||||
fprintf(stderr, "config - cannot locate config file\n") ;
|
||||
return FALSE ;
|
||||
}
|
||||
|
||||
/*
|
||||
* read and parse configuration data (per line)
|
||||
*/
|
||||
|
||||
while (fgets(line, 512, fp) != NULL) {
|
||||
if (appendData(line) != TRUE) {
|
||||
fprintf(stderr, "config - cannot load data %s\n", line) ;
|
||||
fclose(fp) ;
|
||||
return FALSE ;
|
||||
}
|
||||
}
|
||||
|
||||
fclose(fp) ;
|
||||
return TRUE ;
|
||||
}
|
||||
|
||||
/*
|
||||
* config_dump - dump contents of mDNS Proxy configuration data
|
||||
*/
|
||||
|
||||
static BOOL haveSpace(u_char *str)
|
||||
{
|
||||
for ( ; *str != '\0' ; str++) {
|
||||
if (isspace(*str)) {
|
||||
return TRUE ;
|
||||
}
|
||||
}
|
||||
return FALSE ;
|
||||
}
|
||||
|
||||
void config_dump(FILE *ofp)
|
||||
{
|
||||
CNFPTR p ;
|
||||
int i ;
|
||||
|
||||
if (confList.next == NULL || confList.prev == NULL) {
|
||||
return ;
|
||||
}
|
||||
for (p = confList.next ; p != &confList ; p = p->next) {
|
||||
if (haveSpace(p->key)) {
|
||||
fprintf(ofp, "<%s>", p->key) ;
|
||||
} else {
|
||||
fprintf(ofp, "<%s>", p->key) ;
|
||||
}
|
||||
for (i = 0 ; i < p->nVal ; i++) {
|
||||
if (haveSpace(p->aVal[i])) {
|
||||
fprintf(ofp, " \"%s\"", p->aVal[i]) ;
|
||||
} else {
|
||||
fprintf(ofp, " %s", p->aVal[i]) ;
|
||||
}
|
||||
}
|
||||
fprintf(ofp, "\n") ;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* config_free - dispose mDNS configuration data
|
||||
*/
|
||||
|
||||
void config_free(void)
|
||||
{
|
||||
disposeData() ;
|
||||
}
|
||||
|
||||
/*
|
||||
* config_query_value - query configuration data
|
||||
*
|
||||
* this is generic interface to access configuration data
|
||||
* but note, this function cannot work with multiple
|
||||
* configuration data, such as client-translation
|
||||
*/
|
||||
|
||||
BOOL config_query_value(char *key, int *count, char ***array)
|
||||
{
|
||||
CNFPTR p ;
|
||||
|
||||
for (p = confList.next ; p != &confList ; p = p->next) {
|
||||
if (strcmp(p->key, key) != 0) {
|
||||
continue ;
|
||||
}
|
||||
*count = p->nVal ;
|
||||
*array = (char **) p->aVal ;
|
||||
return TRUE ;
|
||||
}
|
||||
return FALSE ;
|
||||
}
|
||||
|
||||
/*
|
||||
* config_query_listen, config_query_forward
|
||||
*
|
||||
* queries sockaddr (really sockaddr_in) of proxy to listen,
|
||||
* and DNS server to which proxy forwards the requests.
|
||||
* These function set
|
||||
*
|
||||
* addr->sin_family <- AF_INET
|
||||
* addr->sin_addr <- specified/default
|
||||
* addr->sin_port <- specified/default
|
||||
*
|
||||
* for 'listen' address, both sin_addr/sin_port have default values,
|
||||
* but for 'forward' address, there is no default for 'sin_addr',
|
||||
* and result error on such case.
|
||||
*
|
||||
* NOTE: for DNS proxy, both listen/forward address should be
|
||||
* specified with xx.xx.xx.xx notation, never be host name
|
||||
*/
|
||||
|
||||
#define DEFAULT_ADDR INADDR_ANY
|
||||
#define DEFAULT_PORT 53
|
||||
|
||||
static CNFPTR queryData(u_char *key)
|
||||
{
|
||||
CNFPTR p ;
|
||||
|
||||
for (p = confList.next ; p != &confList ; p = p->next) {
|
||||
if (strcmp(p->key, key) == 0) {
|
||||
return p ;
|
||||
}
|
||||
}
|
||||
return NULL ;
|
||||
}
|
||||
|
||||
static void getHostPort(u_char *arg, u_char *host, u_char *port)
|
||||
{
|
||||
for (*host = '\0' ; *arg != '\0' ; arg++) {
|
||||
if (*arg == ':') {
|
||||
arg += 1 ;
|
||||
break ;
|
||||
}
|
||||
*host++ = *arg ;
|
||||
*host = '\0' ;
|
||||
}
|
||||
for (*port = '\0' ; *arg != '\0' ; arg++) {
|
||||
*port++ = *arg ;
|
||||
*port = '\0' ;
|
||||
}
|
||||
}
|
||||
|
||||
BOOL config_query_listen(struct sockaddr *addr)
|
||||
{
|
||||
CNFPTR pListen ;
|
||||
u_char host[64], port[64] ;
|
||||
struct sockaddr_in *iaddr ;
|
||||
|
||||
memset(addr, 0, sizeof(struct sockaddr)) ;
|
||||
iaddr = (struct sockaddr_in *) addr ;
|
||||
|
||||
iaddr->sin_family = AF_INET ;
|
||||
|
||||
if ((pListen = queryData("listen")) == NULL) {
|
||||
iaddr->sin_addr.s_addr = htonl(DEFAULT_ADDR) ;
|
||||
iaddr->sin_port = htons(DEFAULT_PORT) ;
|
||||
return TRUE ;
|
||||
}
|
||||
if (pListen->nVal < 2) {
|
||||
iaddr->sin_addr.s_addr = htonl(DEFAULT_ADDR) ;
|
||||
iaddr->sin_port = htons(DEFAULT_PORT) ;
|
||||
return TRUE ;
|
||||
}
|
||||
|
||||
getHostPort(pListen->aVal[1], host, port) ;
|
||||
|
||||
if (isdigit(*host)) {
|
||||
iaddr->sin_addr.s_addr = inet_addr(host) ;
|
||||
} else {
|
||||
iaddr->sin_addr.s_addr = htonl(DEFAULT_ADDR) ;
|
||||
}
|
||||
if (isdigit(*port)) {
|
||||
iaddr->sin_port = htons(atoi(port)) ;
|
||||
} else {
|
||||
iaddr->sin_port = htons(DEFAULT_PORT) ;
|
||||
}
|
||||
return TRUE ;
|
||||
}
|
||||
|
||||
BOOL config_query_forward(struct sockaddr *addr)
|
||||
{
|
||||
CNFPTR pForward ;
|
||||
u_char host[64], port[64] ;
|
||||
struct sockaddr_in *iaddr ;
|
||||
|
||||
memset(addr, 0, sizeof(struct sockaddr)) ;
|
||||
iaddr = (struct sockaddr_in *) addr ;
|
||||
|
||||
if ((pForward = queryData("forward")) == NULL) {
|
||||
WARN("config - no \"forward\" record\n") ;
|
||||
return FALSE ;
|
||||
}
|
||||
if (pForward->nVal < 2) {
|
||||
WARN("config - no \"forward\" value\n") ;
|
||||
return FALSE ;
|
||||
}
|
||||
|
||||
getHostPort(pForward->aVal[1], host, port) ;
|
||||
|
||||
if (isdigit(*host)) {
|
||||
iaddr->sin_addr.s_addr = inet_addr(host) ;
|
||||
} else {
|
||||
WARN("config - no \"forward\" address\n") ;
|
||||
return FALSE ;
|
||||
}
|
||||
if (isdigit(*port)) {
|
||||
iaddr->sin_port = htons(atoi(port)) ;
|
||||
} else {
|
||||
iaddr->sin_port = htons(DEFAULT_PORT) ;
|
||||
}
|
||||
iaddr->sin_family = AF_INET ;
|
||||
|
||||
return TRUE ;
|
||||
}
|
||||
|
||||
/*
|
||||
* config_query_restrict - query 'source-restrict' flag
|
||||
*/
|
||||
|
||||
BOOL config_query_restrict(BOOL *restrict)
|
||||
{
|
||||
CNFPTR pForward ;
|
||||
|
||||
if ((pForward = queryData("forward")) == NULL) {
|
||||
*restrict = FALSE ;
|
||||
} else if (pForward->nVal < 3) {
|
||||
*restrict = FALSE ;
|
||||
} else if (strcmp(pForward->aVal[2], "bind4compat") != 0) {
|
||||
*restrict = FALSE ;
|
||||
} else {
|
||||
*restrict = TRUE ;
|
||||
}
|
||||
return TRUE ;
|
||||
}
|
||||
|
||||
/*
|
||||
* config_query_open, config_query_more, config_query_close
|
||||
*
|
||||
* this is generic interface to access configuration data
|
||||
* for multiple entires for same key value.
|
||||
*/
|
||||
|
||||
config_ctx_t config_query_open(char *key, int *count, char ***array)
|
||||
{
|
||||
CNFPTR p ;
|
||||
|
||||
for (p = confList.next ; p != &confList ; p = p->next) {
|
||||
if (strcmp(p->key, key) != 0) {
|
||||
continue ;
|
||||
}
|
||||
*count = p->nVal ;
|
||||
*array = (char **) p->aVal ;
|
||||
return (config_ctx_t) p ;
|
||||
}
|
||||
return NULL ;
|
||||
}
|
||||
|
||||
config_ctx_t config_query_more(config_ctx_t ctx, int *count, char ***array)
|
||||
{
|
||||
CNFPTR p = (CNFPTR) ctx ;
|
||||
CNFPTR np ;
|
||||
|
||||
for (np = p->next ; np != &confList ; np = np->next) {
|
||||
if (strcmp(np->key, p->key) != 0) {
|
||||
continue ;
|
||||
}
|
||||
*count = np->nVal ;
|
||||
*array = (char **) np->aVal ;
|
||||
return (config_ctx_t) np ;
|
||||
}
|
||||
return NULL ;
|
||||
}
|
||||
|
||||
void config_query_close(config_ctx_t ctx)
|
||||
{
|
||||
/* nothing to do */
|
||||
}
|
||||
|
||||
#ifdef TEST
|
||||
/*
|
||||
* test driver for 'config' module
|
||||
*/
|
||||
|
||||
static void dumpaddr(u_char *str, struct sockaddr *addr)
|
||||
{
|
||||
u_char *p ;
|
||||
struct sockaddr_in *iaddr = (struct sockaddr_in *) addr ;
|
||||
|
||||
printf("%s ", str) ;
|
||||
|
||||
p = (u_char *) &iaddr->sin_addr ;
|
||||
printf("address %d.%d.%d.%d",
|
||||
(p[0] & 0xff), (p[1] & 0xff), (p[2] & 0xff), (p[3] & 0xff)) ;
|
||||
|
||||
p = (u_char *) &iaddr->sin_port ;
|
||||
printf(" port %d", ((p[0] & 0xff) * 256 + (p[1] & 0xff))) ;
|
||||
|
||||
printf("\n") ;
|
||||
}
|
||||
|
||||
static void dumpvalue(char *key, int count, char **array)
|
||||
{
|
||||
int i ;
|
||||
|
||||
for (i = 0 ; i < count ; i++) {
|
||||
printf("%s ", array[i]) ;
|
||||
}
|
||||
printf("\n") ; fflush(stdout) ;
|
||||
}
|
||||
|
||||
int main(int ac, char *av[])
|
||||
{
|
||||
int stat ;
|
||||
struct sockaddr addr ;
|
||||
int count ;
|
||||
char **array ;
|
||||
config_ctx_t ctx ;
|
||||
|
||||
if ((stat = config_load(ac, av)) != TRUE) {
|
||||
printf("config_load failed %d\n", stat) ;
|
||||
return 1 ;
|
||||
}
|
||||
config_dump(stdout) ;
|
||||
|
||||
if (config_query_value("listen", &count, &array) == TRUE) {
|
||||
dumpvalue("listen", count, array) ;
|
||||
}
|
||||
if (config_query_value("forward", &count, &array) == TRUE) {
|
||||
dumpvalue("forward", count, array) ;
|
||||
}
|
||||
if (config_query_value("normalize", &count, &array) == TRUE) {
|
||||
dumpvalue("normalize", count, array) ;
|
||||
}
|
||||
if (config_query_value("server-translation", &count, &array) == TRUE) {
|
||||
dumpvalue("server-translation", count, array) ;
|
||||
}
|
||||
|
||||
ctx = config_query_open("client-translation", &count, &array) ;
|
||||
while (ctx != NULL) {
|
||||
dumpvalue("client-translation", count, array) ;
|
||||
ctx = config_query_more(ctx, &count, &array) ;
|
||||
}
|
||||
config_query_close(ctx) ;
|
||||
|
||||
if (config_query_listen(&addr) != TRUE) {
|
||||
printf("no \"listen\" data\n") ;
|
||||
} else {
|
||||
dumpaddr("listen", &addr) ;
|
||||
}
|
||||
|
||||
if (config_query_forward(&addr) != TRUE) {
|
||||
printf("no \"forward\" data\n") ;
|
||||
} else {
|
||||
dumpaddr("forward", &addr) ;
|
||||
}
|
||||
|
||||
config_free() ;
|
||||
return 0 ;
|
||||
}
|
||||
#endif /* TEST */
|
||||
119
contrib/idn/mdnkit/dnsproxy/proxycnf.h
Normal file
119
contrib/idn/mdnkit/dnsproxy/proxycnf.h
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
/*
|
||||
* proxycnf.h - mDNS Proxy, Configure Proxy Server
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
/* $Id: proxycnf.h,v 1.9 2000/11/17 05:42:09 ishisone Exp $ */
|
||||
|
||||
#ifndef PROXYCNF_H
|
||||
#define PROXYCNF_H 1
|
||||
|
||||
/*
|
||||
* CONFIG_PATH
|
||||
* where configuration file placed
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_PATH
|
||||
#ifdef UNIX
|
||||
#define CONFIG_PATH "/usr/local/etc/"
|
||||
#endif
|
||||
#ifdef WIN32
|
||||
#define CONFIG_PATH "$(SystemRoot)/"
|
||||
#endif
|
||||
#ifdef OS2
|
||||
#define CONFIG_PATH "$(ETC)/"
|
||||
#endif
|
||||
#endif /* CONFIG_PATH */
|
||||
|
||||
/*
|
||||
* CONFIG_FILE
|
||||
* name of configuration file
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_FILE
|
||||
#ifdef UNIX
|
||||
#define CONFIG_FILE "dnsproxy.conf"
|
||||
#endif
|
||||
#ifdef WIN32
|
||||
#define CONFIG_FILE "dnsproxy.cnf"
|
||||
#endif
|
||||
#ifdef OS2
|
||||
#define CONFIG_FILE "dnsproxy.cnf"
|
||||
#endif
|
||||
#endif /* CONFIG_FILE */
|
||||
|
||||
/*
|
||||
* CONFIG_HOME
|
||||
* debugging support, $HOME environment name
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_HOME
|
||||
#ifdef UNIX
|
||||
#define CONFIG_HOME "$(HOME)/"
|
||||
#endif
|
||||
#ifdef WIN32
|
||||
#define CONFIG_HOME "$(HOMEPATH)/"
|
||||
#endif
|
||||
#ifdef OS2
|
||||
#define CONFIG_HOME "$(HOME)/"
|
||||
#endif
|
||||
#endif /* CONFIG_HOME */
|
||||
|
||||
#endif /* PROXYCNF_H */
|
||||
1409
contrib/idn/mdnkit/dnsproxy/server.c
Normal file
1409
contrib/idn/mdnkit/dnsproxy/server.c
Normal file
File diff suppressed because it is too large
Load diff
521
contrib/idn/mdnkit/dnsproxy/translate.c
Normal file
521
contrib/idn/mdnkit/dnsproxy/translate.c
Normal file
|
|
@ -0,0 +1,521 @@
|
|||
/*
|
||||
* 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char *rcsid = "$Id: translate.c,v 1.22 2000/11/21 02:09:02 ishisone Exp $";
|
||||
#endif
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#include <winsock.h>
|
||||
#else /* for normal systems */
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
#include <mdn/result.h>
|
||||
#include <mdn/log.h>
|
||||
#include <mdn/converter.h>
|
||||
#include <mdn/normalizer.h>
|
||||
#include <mdn/translator.h>
|
||||
#include <mdn/zldrule.h>
|
||||
#include <mdn/msgtrans.h>
|
||||
|
||||
#include "dnsproxy.h"
|
||||
|
||||
/*
|
||||
* Configuration file keywords.
|
||||
*/
|
||||
#define KW_LOG_LEVEL "mdn-log-level" /* tentative */
|
||||
#define KW_ALIAS_FILE "encoding-alias-file"
|
||||
#define KW_CLIENT_TRANSLATION "client-translation"
|
||||
#define KW_ALTERNATE_ENCODING "alternate-encoding"
|
||||
#define KW_NORMALIZATION "normalize"
|
||||
#define KW_SERVER_TRANSLATION "server-translation"
|
||||
|
||||
/*
|
||||
* DNS message rcode.
|
||||
*/
|
||||
enum {
|
||||
RCODE_NO_ERROR = 0,
|
||||
RCODE_FORMAT_ERROR = 1,
|
||||
RCODE_SERVER_FAILURE = 2,
|
||||
RCODE_NAME_ERROR = 3,
|
||||
RCODE_NOT_IMPLEMENTED = 4,
|
||||
RCODE_REFUSED = 5
|
||||
};
|
||||
|
||||
typedef struct translation {
|
||||
mdn_zldrule_t rule;
|
||||
char *server_zld;
|
||||
mdn_converter_t server_converter;
|
||||
mdn_normalizer_t normalizer;
|
||||
mdn_converter_t alternate_converter;
|
||||
} translation_t;
|
||||
|
||||
static translation_t trans;
|
||||
|
||||
static int result_to_rcode(mdn_result_t r);
|
||||
static char *address_to_string(struct sockaddr *sa);
|
||||
static int string_to_loglevel(char *s);
|
||||
static void config_required(char *keyword);
|
||||
static void mdnerror(int code, char *fmt, ...);
|
||||
static void translate_log_handler(int level, const char *msg);
|
||||
|
||||
|
||||
BOOL
|
||||
translate_initialize(void)
|
||||
{
|
||||
mdn_result_t r;
|
||||
config_ctx_t cctx;
|
||||
int ac;
|
||||
char **av;
|
||||
int i;
|
||||
|
||||
TRACE("translate_initialize()\n");
|
||||
|
||||
/*
|
||||
* Set MDN library log handler.
|
||||
*/
|
||||
mdn_log_setproc(translate_log_handler);
|
||||
|
||||
/*
|
||||
* Set log level before calling any other functions in
|
||||
* MDN library.
|
||||
*/
|
||||
if (config_query_value(KW_LOG_LEVEL, &ac, &av)) {
|
||||
int level;
|
||||
|
||||
if (ac != 2) {
|
||||
WARN("syntax error at %s line\n", KW_LOG_LEVEL);
|
||||
return FALSE;
|
||||
}
|
||||
if ((level = string_to_loglevel(av[1])) >= 0) {
|
||||
mdn_log_setlevel(level);
|
||||
} else {
|
||||
WARN("unknown log level %.100s -- ignored\n", av[1]);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize modules.
|
||||
*/
|
||||
mdn_converter_initialize();
|
||||
mdn_normalizer_initialize();
|
||||
|
||||
/*
|
||||
* Create context.
|
||||
*/
|
||||
if ((r = mdn_zldrule_create(&trans.rule)) != mdn_success) {
|
||||
mdnerror(r, "initializing ZLD rules");
|
||||
return FALSE;
|
||||
}
|
||||
if ((r = mdn_normalizer_create(&trans.normalizer)) != mdn_success) {
|
||||
mdnerror(r, "initializing normalization");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Load configuration data other than log level.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Encoding alias file.
|
||||
*/
|
||||
if (config_query_value(KW_ALIAS_FILE, &ac, &av)) {
|
||||
if (ac != 2) {
|
||||
WARN("syntax error at %s line\n", KW_ALIAS_FILE);
|
||||
return FALSE;
|
||||
}
|
||||
if ((r = mdn_converter_aliasfile(av[1])) != mdn_success) {
|
||||
mdnerror(r, "reading codeset alias file %.200s", av[1]);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Client-side translation rule.
|
||||
*/
|
||||
if ((cctx = config_query_open(KW_CLIENT_TRANSLATION, &ac, &av)) == NULL) {
|
||||
config_required(KW_CLIENT_TRANSLATION);
|
||||
return FALSE;
|
||||
}
|
||||
do {
|
||||
if (ac < 3) {
|
||||
WARN("syntax error at %s line\n", KW_ALIAS_FILE);
|
||||
return FALSE;
|
||||
}
|
||||
#ifndef MDN_SUPPORT_ZLD
|
||||
if (strcmp(av[1], "") != 0 && strcmp(av[1], ".") != 0) {
|
||||
WARN("ignore ZLD %s\n", av[1]);
|
||||
}
|
||||
#endif
|
||||
r = mdn_zldrule_add(trans.rule, av[1], (const char **)&av[2], ac - 2);
|
||||
if (r != mdn_success) {
|
||||
mdnerror(r, "adding ZLD rules for %s", av[1]);
|
||||
return FALSE;
|
||||
}
|
||||
} while ((cctx = config_query_more(cctx, &ac, &av)) != NULL);
|
||||
config_query_close(cctx);
|
||||
|
||||
/*
|
||||
* Client-side alternate encoding.
|
||||
*/
|
||||
if (config_query_value(KW_ALTERNATE_ENCODING, &ac, &av)) {
|
||||
if (ac != 2) {
|
||||
WARN("syntax error at %s line\n", KW_ALTERNATE_ENCODING);
|
||||
return FALSE;
|
||||
}
|
||||
if ((r = mdn_converter_create(av[1], &trans.alternate_converter, 0))
|
||||
!= mdn_success) {
|
||||
mdnerror(r, "alternate encoding %s", av[2]);
|
||||
return FALSE;
|
||||
}
|
||||
if (!mdn_converter_isasciicompatible(trans.alternate_converter)) {
|
||||
WARN("alternate encoding must be ASCII-compatible\n");
|
||||
return FALSE;
|
||||
}
|
||||
} else {
|
||||
trans.alternate_converter = NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Normalization.
|
||||
*/
|
||||
if (!config_query_value(KW_NORMALIZATION, &ac, &av)) {
|
||||
config_required(KW_NORMALIZATION);
|
||||
return FALSE;
|
||||
}
|
||||
for (i = 1; i < ac; i++) {
|
||||
if ((r = mdn_normalizer_add(trans.normalizer, av[i])) != mdn_success) {
|
||||
mdnerror(r, "adding normalization scheme %s", av[i]);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Server-side translation.
|
||||
*/
|
||||
if (!config_query_value(KW_SERVER_TRANSLATION, &ac, &av)) {
|
||||
config_required(KW_SERVER_TRANSLATION);
|
||||
return FALSE;
|
||||
}
|
||||
if (ac != 3) {
|
||||
WARN("syntax error at %s line\n", KW_SERVER_TRANSLATION);
|
||||
return FALSE;
|
||||
}
|
||||
if ((r = mdn_translator_canonicalzld(av[1], &trans.server_zld))
|
||||
!= mdn_success) {
|
||||
mdnerror(r, "server-side ZLD %s", av[2]);
|
||||
return FALSE;
|
||||
}
|
||||
#ifndef MDN_SUPPORT_ZLD
|
||||
if (trans.server_zld != NULL) {
|
||||
WARN("ignore ZLD %s\n", av[1]);
|
||||
free(trans.server_zld);
|
||||
trans.server_zld = NULL;
|
||||
}
|
||||
#endif
|
||||
if ((r = mdn_converter_create(av[2], &trans.server_converter, 0))
|
||||
!= mdn_success) {
|
||||
mdnerror(r, "server-side encoding %s", av[2]);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
translate_finish(void)
|
||||
{
|
||||
if (trans.rule != NULL) {
|
||||
mdn_zldrule_destroy(trans.rule);
|
||||
trans.rule = NULL;
|
||||
}
|
||||
if (trans.server_zld != NULL) {
|
||||
free(trans.server_zld);
|
||||
trans.server_zld = NULL;
|
||||
}
|
||||
if (trans.server_converter != NULL) {
|
||||
mdn_converter_destroy(trans.server_converter);
|
||||
trans.server_converter = NULL;
|
||||
}
|
||||
if (trans.normalizer != NULL) {
|
||||
mdn_normalizer_destroy(trans.normalizer);
|
||||
trans.normalizer = NULL;
|
||||
}
|
||||
if (trans.alternate_converter != NULL) {
|
||||
mdn_converter_destroy(trans.alternate_converter);
|
||||
trans.alternate_converter = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
translate_request(translation_context_t *ctx,
|
||||
const char *msg, size_t msglen,
|
||||
char *translated, size_t bufsize, size_t *translatedlenp)
|
||||
{
|
||||
mdn_msgtrans_param_t param;
|
||||
mdn_result_t r;
|
||||
|
||||
TRACE("translate_request()\n");
|
||||
|
||||
ctx->zld = NULL;
|
||||
ctx->converter = NULL;
|
||||
|
||||
/*
|
||||
* Initialize translation parameters.
|
||||
*/
|
||||
param.use_local_rule = 1;
|
||||
param.local_rule = trans.rule;
|
||||
param.local_converter = NULL;
|
||||
param.local_zld = NULL;
|
||||
param.local_alt_converter = trans.alternate_converter;
|
||||
param.target_converter = trans.server_converter;
|
||||
param.target_alt_converter = NULL;
|
||||
param.target_zld = trans.server_zld;
|
||||
param.normalizer = trans.normalizer;
|
||||
|
||||
r = mdn_msgtrans_translate(¶m, msg, msglen,
|
||||
translated, bufsize, translatedlenp);
|
||||
|
||||
if (r != mdn_success) {
|
||||
mdnerror(r, "translating request message from %s(%s)",
|
||||
address_to_string(ctx->client),
|
||||
ctx->protocol == SOCK_STREAM ? "tcp" : "udp");
|
||||
} else {
|
||||
ctx->zld = param.local_zld;
|
||||
ctx->converter = param.local_converter;
|
||||
}
|
||||
|
||||
return result_to_rcode(r);
|
||||
}
|
||||
|
||||
int
|
||||
translate_reply(translation_context_t *ctx,
|
||||
const char *msg, size_t msglen,
|
||||
char *translated, size_t bufsize, size_t *translatedlenp)
|
||||
{
|
||||
mdn_msgtrans_param_t param;
|
||||
mdn_result_t r;
|
||||
|
||||
TRACE("translate_reply()\n");
|
||||
|
||||
if (ctx->converter == NULL) {
|
||||
/*
|
||||
* No translation required.
|
||||
*/
|
||||
TRACE("translate_reply: pass through message (old_id=%d,new_id=%d)\n",
|
||||
ctx->old_id, ctx->new_id);
|
||||
if (bufsize < msglen)
|
||||
return (RCODE_SERVER_FAILURE);
|
||||
(void)memcpy(translated, msg, msglen);
|
||||
*translatedlenp = msglen;
|
||||
return RCODE_NO_ERROR;
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize translation parameters.
|
||||
*/
|
||||
param.use_local_rule = 0;
|
||||
param.local_rule = NULL;
|
||||
param.local_converter = trans.server_converter;
|
||||
param.local_zld = trans.server_zld;
|
||||
param.local_alt_converter = NULL;
|
||||
param.target_converter = ctx->converter;
|
||||
param.target_alt_converter = trans.alternate_converter;
|
||||
param.target_zld = ctx->zld;
|
||||
param.normalizer = NULL;
|
||||
|
||||
r = mdn_msgtrans_translate(¶m, msg, msglen,
|
||||
translated, bufsize, translatedlenp);
|
||||
|
||||
if (r != mdn_success) {
|
||||
mdnerror(r, "translating reply message from %s",
|
||||
address_to_string(ctx->client));
|
||||
}
|
||||
|
||||
return result_to_rcode(r);
|
||||
}
|
||||
|
||||
static int
|
||||
result_to_rcode(mdn_result_t r)
|
||||
{
|
||||
int rcode;
|
||||
|
||||
switch (r) {
|
||||
case mdn_success:
|
||||
rcode = RCODE_NO_ERROR;
|
||||
break;
|
||||
case mdn_buffer_overflow:
|
||||
case mdn_nomemory:
|
||||
rcode = RCODE_SERVER_FAILURE;
|
||||
break;
|
||||
case mdn_invalid_message:
|
||||
case mdn_invalid_encoding:
|
||||
rcode = RCODE_FORMAT_ERROR;
|
||||
break;
|
||||
default:
|
||||
rcode = RCODE_SERVER_FAILURE;
|
||||
break;
|
||||
}
|
||||
return rcode;
|
||||
}
|
||||
|
||||
static char *
|
||||
address_to_string(struct sockaddr *sa)
|
||||
{
|
||||
static char tmp[200];
|
||||
|
||||
switch (sa->sa_family) {
|
||||
case AF_INET:
|
||||
{
|
||||
struct sockaddr_in *sin = (struct sockaddr_in *)sa;
|
||||
|
||||
sprintf(tmp, "%s/%d", inet_ntoa(sin->sin_addr),
|
||||
ntohs(sin->sin_port));
|
||||
break;
|
||||
}
|
||||
#if 0
|
||||
#ifdef AF_INET6
|
||||
case AF_INET6:
|
||||
{
|
||||
char buf[INET6_ADDRSTRLEN];
|
||||
|
||||
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa;
|
||||
|
||||
sprintf(tmp, "%s/%d",
|
||||
inet_ntop(AF_INET6, &sin6->sin6_addr, buf, sizeof(buf)),
|
||||
ntohs(sin6->sin6_port));
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
default:
|
||||
sprintf(tmp, "unknown address family %d", sa->sa_family);
|
||||
break;
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
|
||||
static int
|
||||
string_to_loglevel(char *s)
|
||||
{
|
||||
if ('0' <= s[0] && s[0] <= '9')
|
||||
return atoi(s);
|
||||
else if (!strcmp(s, "fatal"))
|
||||
return mdn_log_level_fatal;
|
||||
else if (!strcmp(s, "error"))
|
||||
return mdn_log_level_error;
|
||||
else if (!strcmp(s, "warning"))
|
||||
return mdn_log_level_warning;
|
||||
else if (!strcmp(s, "info"))
|
||||
return mdn_log_level_info;
|
||||
else if (!strcmp(s, "trace"))
|
||||
return mdn_log_level_trace;
|
||||
else if (!strcmp(s, "dump"))
|
||||
return mdn_log_level_dump;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void
|
||||
config_required(char *keyword)
|
||||
{
|
||||
WARN("%s line required in the configuration file\n", keyword);
|
||||
}
|
||||
|
||||
static void
|
||||
mdnerror(int code, char *fmt, ...)
|
||||
{
|
||||
char buf[1024];
|
||||
va_list args;
|
||||
|
||||
va_start(args, fmt);
|
||||
vsprintf(buf, fmt, args);
|
||||
va_end(args);
|
||||
|
||||
sprintf(buf + strlen(buf), ": %s", mdn_result_tostring(code));
|
||||
WARN("%s\n", buf);
|
||||
}
|
||||
|
||||
static void
|
||||
translate_log_handler(int level, const char *msg)
|
||||
{
|
||||
switch (level) {
|
||||
case mdn_log_level_fatal:
|
||||
FATAL((char *)msg);
|
||||
break;
|
||||
case mdn_log_level_warning:
|
||||
case mdn_log_level_info:
|
||||
WARN((char *)msg);
|
||||
break;
|
||||
case mdn_log_level_trace:
|
||||
case mdn_log_level_dump:
|
||||
TRACE((char *)msg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
288
contrib/idn/mdnkit/dnsproxy/unxmain.c
Normal file
288
contrib/idn/mdnkit/dnsproxy/unxmain.c
Normal file
|
|
@ -0,0 +1,288 @@
|
|||
/*
|
||||
* unxmain.c - mDNS Proxy, entry for UNIX
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char *rcsid = "$Id: unxmain.c,v 1.16 2000/11/17 05:46:23 ishisone Exp $";
|
||||
#endif
|
||||
|
||||
#ifdef UNIX
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <signal.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <sys/types.h>
|
||||
#include <pwd.h>
|
||||
#include <grp.h>
|
||||
#include "dnsproxy.h" /* Common definitions for mDNS proxy */
|
||||
|
||||
#define KW_ROOT_DIR "root-directory"
|
||||
#define KW_USER_ID "user-id"
|
||||
#define KW_GROUP_ID "group-id"
|
||||
|
||||
static uid_t uid;
|
||||
static gid_t gid;
|
||||
static char *root_dir;
|
||||
static BOOL uid_specified = FALSE;
|
||||
static BOOL gid_specified = FALSE;
|
||||
|
||||
/*
|
||||
* signal handler to catch signal to terminate server
|
||||
*/
|
||||
|
||||
static void handler(int signo)
|
||||
{
|
||||
server_stop() ;
|
||||
signal(signo, SIG_DFL) ;
|
||||
}
|
||||
|
||||
/*
|
||||
* signal handler to turn over the log file
|
||||
*/
|
||||
|
||||
static void hup_handler(int signo)
|
||||
{
|
||||
log_turnover_request();
|
||||
signal(signo, hup_handler) ;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set root directory.
|
||||
*/
|
||||
|
||||
static void change_root(void)
|
||||
{
|
||||
int err;
|
||||
|
||||
if (root_dir != NULL && chroot(root_dir) < 0) {
|
||||
err = errno;
|
||||
FATAL("cannot change root directory: %s\n", strerror(err));
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Set user/group ID.
|
||||
*/
|
||||
|
||||
static void set_id(void)
|
||||
{
|
||||
int err;
|
||||
|
||||
if (uid_specified && setuid(uid) < 0) {
|
||||
err = errno;
|
||||
FATAL("cannot set user ID: %s\n", strerror(err));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (gid_specified && setgid(gid) < 0) {
|
||||
err = errno;
|
||||
FATAL("cannot set group ID: %s\n", strerror(err));
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Load configuration parameter related to security.
|
||||
*/
|
||||
|
||||
static void get_security_conf(void)
|
||||
{
|
||||
int ac;
|
||||
char **av;
|
||||
|
||||
if (config_query_value(KW_ROOT_DIR, &ac, &av)) {
|
||||
if (ac != 2) {
|
||||
WARN("syntax error at %s line\n", KW_ROOT_DIR);
|
||||
exit(1);
|
||||
}
|
||||
root_dir = malloc(strlen(av[1]) + 1);
|
||||
if (root_dir == NULL) {
|
||||
FATAL("malloc failed\n");
|
||||
exit(1);
|
||||
}
|
||||
(void)strcpy(root_dir, av[1]);
|
||||
}
|
||||
|
||||
if (config_query_value(KW_USER_ID, &ac, &av)) {
|
||||
struct passwd *pwd;
|
||||
|
||||
if (ac != 2) {
|
||||
WARN("syntax error at %s line\n", KW_USER_ID);
|
||||
exit(1);
|
||||
} else if ((pwd = getpwnam(av[1])) != NULL) {
|
||||
uid = pwd->pw_uid;
|
||||
uid_specified = TRUE;
|
||||
} else if (isdigit((unsigned char)(av[1][0]))) {
|
||||
uid = atoi(av[1]);
|
||||
uid_specified = TRUE;
|
||||
} else {
|
||||
FATAL("unknown user %s\n", av[1]);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
if (config_query_value(KW_GROUP_ID, &ac, &av)) {
|
||||
struct group *gr;
|
||||
|
||||
if (ac != 2) {
|
||||
WARN("syntax error at %s line\n", KW_GROUP_ID);
|
||||
exit(1);
|
||||
} else if ((gr = getgrnam(av[1])) != NULL) {
|
||||
gid = gr->gr_gid;
|
||||
gid_specified = TRUE;
|
||||
} else if (isdigit((unsigned char)(av[1][0]))) {
|
||||
gid = atoi(av[1]);
|
||||
gid_specified = TRUE;
|
||||
} else {
|
||||
FATAL("unknown group %s\n", av[1]);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* main - entry of UNIX version
|
||||
*/
|
||||
|
||||
int main(int ac, char *av[])
|
||||
{
|
||||
int i, pid ;
|
||||
BOOL as_daemon = FALSE ;
|
||||
|
||||
for (i = 1 ; i < ac ; i++) {
|
||||
if (strcmp(av[i], "-daemon") == 0) {
|
||||
as_daemon = TRUE ;
|
||||
}
|
||||
}
|
||||
if (config_load(ac, av) != TRUE) {
|
||||
printf("cannot load configurations\n") ;
|
||||
return 1 ;
|
||||
}
|
||||
log_configure(ac, av) ;
|
||||
|
||||
get_security_conf();
|
||||
|
||||
if (server_init(ac, av) != TRUE) {
|
||||
printf("cannot initialize server\n") ;
|
||||
log_terminate() ;
|
||||
return 1 ;
|
||||
}
|
||||
|
||||
if (as_daemon) {
|
||||
switch (pid = fork()) {
|
||||
case -1 :
|
||||
printf("cannot start daemon %d\n", errno) ;
|
||||
server_done() ;
|
||||
log_terminate() ;
|
||||
return 2 ;
|
||||
case 0 : /* children, as daemon */
|
||||
setsid() ;
|
||||
close(0) ;
|
||||
close(1) ;
|
||||
close(2) ;
|
||||
break ;
|
||||
default :
|
||||
printf("start daemon PID %d\n", pid) ;
|
||||
return 0 ;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Change root directory/user ID/group ID if specified.
|
||||
*/
|
||||
change_root();
|
||||
set_id();
|
||||
|
||||
signal(SIGHUP, hup_handler) ;
|
||||
signal(SIGINT, handler) ;
|
||||
signal(SIGKILL, handler) ;
|
||||
signal(SIGTERM, handler) ;
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("Service Started\n") ;
|
||||
#endif
|
||||
|
||||
server_loop() ;
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("Service Terminating...\n") ;
|
||||
#endif
|
||||
|
||||
server_done() ;
|
||||
|
||||
log_terminate() ;
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("Service Terminated\n") ;
|
||||
#endif
|
||||
|
||||
return 0 ;
|
||||
}
|
||||
#endif /* UNIX */
|
||||
174
contrib/idn/mdnkit/dnsproxy/winmain.c
Normal file
174
contrib/idn/mdnkit/dnsproxy/winmain.c
Normal file
|
|
@ -0,0 +1,174 @@
|
|||
/*
|
||||
* winmain.c - mDNS Proxy, entry for WIN32
|
||||
*
|
||||
* Windows version works as
|
||||
*
|
||||
* Service Program, as mDNS Proxy Server
|
||||
* Service Configuration Program, Install/Remove mDNS Proxy
|
||||
*
|
||||
* or simply as
|
||||
*
|
||||
* Application Program, for debugging
|
||||
*
|
||||
* with single executable, switched with first option
|
||||
*
|
||||
* -service as Service Program
|
||||
* -install as Configuration, install serivce
|
||||
* -remove as Configuration, remove service
|
||||
*
|
||||
* Otherwise, it runs as simple console apllication.
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char *rcsid = "$Id: winmain.c,v 1.10 2000/07/04 03:52:29 ishisone Exp $";
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "dnsproxy.h" /* Common definitions for mDNS proxy */
|
||||
#include "winserv.h" /* WIN32 Service Related Functions */
|
||||
|
||||
/*
|
||||
* signal handler to catch signal to terminate server
|
||||
*/
|
||||
|
||||
static void handler(int signo)
|
||||
{
|
||||
server_stop() ;
|
||||
signal(signo, SIG_DFL) ;
|
||||
}
|
||||
|
||||
/*
|
||||
* main - entry of windows version
|
||||
*/
|
||||
|
||||
int main(int ac, char *av[])
|
||||
{
|
||||
WORD version = MAKEWORD(2, 0) ;
|
||||
WSADATA wsaData ;
|
||||
|
||||
/*
|
||||
* check 1st option
|
||||
*/
|
||||
|
||||
if (ac >= 2) {
|
||||
if (strcmp(av[1], "-service") == 0) {
|
||||
serviceRun(ac, av) ;
|
||||
return 0 ;
|
||||
}
|
||||
if (strcmp(av[1], "-install") == 0) {
|
||||
serviceInstall(ac, av) ;
|
||||
return 0 ;
|
||||
}
|
||||
if (strcmp(av[1], "-remove") == 0) {
|
||||
serviceRemove(ac, av) ;
|
||||
return 0 ;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* otherwise run as normal application
|
||||
*/
|
||||
|
||||
if (config_load(ac, av) != TRUE) {
|
||||
printf("cannot load configration\n") ;
|
||||
return 1 ;
|
||||
}
|
||||
log_configure(ac, av) ;
|
||||
|
||||
if (WSAStartup(version, &wsaData) != 0) {
|
||||
printf("cannot startup WinSock\n") ;
|
||||
return FALSE ;
|
||||
}
|
||||
if (server_init(ac, av) != TRUE) {
|
||||
printf("cannot initialize server\n") ;
|
||||
WSACleanup() ;
|
||||
return 1 ;
|
||||
}
|
||||
|
||||
signal(SIGINT, handler) ;
|
||||
signal(SIGTERM, handler) ;
|
||||
signal(SIGBREAK, handler) ;
|
||||
|
||||
printf("Service Started\n") ;
|
||||
|
||||
server_loop() ;
|
||||
|
||||
printf("Service Termiating...\n") ;
|
||||
|
||||
server_done() ;
|
||||
|
||||
printf("Service Terminated\n") ;
|
||||
|
||||
WSACleanup() ;
|
||||
|
||||
log_terminate() ;
|
||||
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
#endif /* WIN32 */
|
||||
446
contrib/idn/mdnkit/dnsproxy/winserv.c
Normal file
446
contrib/idn/mdnkit/dnsproxy/winserv.c
Normal file
|
|
@ -0,0 +1,446 @@
|
|||
/*
|
||||
* winserv.c - mDNS Proxy, WIN32 Service Specific Functions
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char *rcsid = "$Id: winserv.c,v 1.10 2000/10/27 03:09:58 ishisone Exp $";
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <tchar.h>
|
||||
|
||||
#include "dnsproxy.h" /* Common definitions for mDNS proxy */
|
||||
#include "winserv.h" /* Windows's Service Specific */
|
||||
|
||||
/*
|
||||
* Parameters for WIN32 Service
|
||||
*/
|
||||
|
||||
#define SERVICENAME "dnsproxy"
|
||||
#define DISPLAYNAME "mDNS Proxy"
|
||||
|
||||
static UCHAR pathService[1024] ;
|
||||
|
||||
/*
|
||||
* getFileName - get fullpath and split it
|
||||
*/
|
||||
|
||||
static UCHAR p_ful[256] ;
|
||||
static UCHAR p_drv[256] ;
|
||||
static UCHAR p_dir[256] ;
|
||||
static UCHAR p_nam[256] ;
|
||||
static UCHAR p_ext[256] ;
|
||||
|
||||
static void getFileName(void)
|
||||
{
|
||||
GetModuleFileName(NULL, p_ful, 256) ;
|
||||
_splitpath(p_ful, p_drv, p_dir, p_nam, p_ext) ;
|
||||
}
|
||||
|
||||
/*
|
||||
* Service management Varibales
|
||||
*/
|
||||
|
||||
SERVICE_STATUS_HANDLE ServiceStatusHandle = 0 ;
|
||||
SERVICE_STATUS ServiceStatusRecord = { 0 } ;
|
||||
int ServiceErrorCode = 0 ;
|
||||
|
||||
void serviceLogTrace(PUCHAR msg)
|
||||
{
|
||||
char msgbuff[256] ;
|
||||
HANDLE hEventSrc ;
|
||||
char *strings[2] ;
|
||||
|
||||
ServiceErrorCode = GetLastError() ;
|
||||
|
||||
sprintf(msgbuff, "%s trace: %d", SERVICENAME, ServiceErrorCode) ;
|
||||
strings[0] = msgbuff ;
|
||||
strings[1] = msg ;
|
||||
|
||||
hEventSrc = RegisterEventSource(NULL, TEXT(SERVICENAME)) ;
|
||||
|
||||
if (hEventSrc != NULL) {
|
||||
ReportEvent(
|
||||
hEventSrc,
|
||||
EVENTLOG_INFORMATION_TYPE,
|
||||
0,
|
||||
0,
|
||||
NULL,
|
||||
2,
|
||||
0,
|
||||
(const char **) strings,
|
||||
NULL) ;
|
||||
DeregisterEventSource(hEventSrc) ;
|
||||
}
|
||||
/* TRACE("%s %s\n", msgbuff, msg) ; */
|
||||
}
|
||||
|
||||
void serviceLogError(PUCHAR msg)
|
||||
{
|
||||
char msgbuff[256] ;
|
||||
HANDLE hEventSrc ;
|
||||
char *strings[2] ;
|
||||
|
||||
ServiceErrorCode = GetLastError() ;
|
||||
|
||||
sprintf(msgbuff, "%s error: %d", SERVICENAME, ServiceErrorCode) ;
|
||||
strings[0] = msgbuff ;
|
||||
strings[1] = msg ;
|
||||
|
||||
hEventSrc = RegisterEventSource(NULL, TEXT(SERVICENAME)) ;
|
||||
|
||||
if (hEventSrc != NULL) {
|
||||
ReportEvent(
|
||||
hEventSrc,
|
||||
EVENTLOG_ERROR_TYPE,
|
||||
0,
|
||||
0,
|
||||
NULL,
|
||||
2,
|
||||
0,
|
||||
(const char **) strings,
|
||||
NULL) ;
|
||||
DeregisterEventSource(hEventSrc) ;
|
||||
}
|
||||
/* FATAL("%s %s\n", msgbuff, msg) ; */
|
||||
}
|
||||
|
||||
/*
|
||||
* serviceReport - report service status
|
||||
*/
|
||||
|
||||
VOID serviceReport(DWORD state, DWORD exitcode, DWORD waithint)
|
||||
{
|
||||
static DWORD checkpoint = 1 ;
|
||||
|
||||
if (state == SERVICE_START_PENDING) {
|
||||
ServiceStatusRecord.dwControlsAccepted = 0 ;
|
||||
} else {
|
||||
ServiceStatusRecord.dwControlsAccepted = SERVICE_ACCEPT_STOP ;
|
||||
}
|
||||
ServiceStatusRecord.dwCurrentState = state ;
|
||||
ServiceStatusRecord.dwWin32ExitCode = exitcode ;
|
||||
ServiceStatusRecord.dwWaitHint = waithint ;
|
||||
|
||||
if (state == SERVICE_RUNNING || state == SERVICE_STOPPED) {
|
||||
ServiceStatusRecord.dwCheckPoint = 0 ;
|
||||
} else {
|
||||
ServiceStatusRecord.dwCheckPoint = checkpoint++ ;
|
||||
}
|
||||
|
||||
SetServiceStatus(ServiceStatusHandle, &ServiceStatusRecord) ;
|
||||
}
|
||||
|
||||
/*
|
||||
* ServiceCtrl - service control handler
|
||||
*/
|
||||
|
||||
VOID ServiceCtrl(DWORD opcode)
|
||||
{
|
||||
switch (opcode) {
|
||||
|
||||
case SERVICE_CONTROL_STOP :
|
||||
serviceLogTrace("ServiceCtrl STOP") ;
|
||||
ServiceStatusRecord.dwCurrentState = SERVICE_STOP_PENDING ;
|
||||
/* nofity later, so set status only */
|
||||
server_stop() ; /* stop server loop */
|
||||
break ;
|
||||
|
||||
case SERVICE_CONTROL_INTERROGATE :
|
||||
/* query, report later */
|
||||
serviceLogTrace("ServiceCtrl INTERROGATE") ;
|
||||
break ;
|
||||
|
||||
default :
|
||||
break ;
|
||||
}
|
||||
serviceReport(ServiceStatusRecord.dwCurrentState, NO_ERROR, 0) ;
|
||||
}
|
||||
|
||||
/*
|
||||
* ServiceMain - as name describes
|
||||
*/
|
||||
|
||||
static UCHAR cmdline[1024] ;
|
||||
|
||||
VOID ServiceMain(DWORD dwArgc, LPTSTR *lpszArgv)
|
||||
{
|
||||
WORD version = MAKEWORD(2, 0) ;
|
||||
WSADATA wsaData ;
|
||||
|
||||
/*
|
||||
* initialize service status
|
||||
*/
|
||||
|
||||
ServiceStatusRecord.dwServiceType = SERVICE_WIN32 | SERVICE_INTERACTIVE_PROCESS ;
|
||||
ServiceStatusRecord.dwServiceSpecificExitCode = 0 ;
|
||||
|
||||
/*
|
||||
* register Service Control Handler
|
||||
*/
|
||||
|
||||
ServiceStatusHandle = RegisterServiceCtrlHandler(
|
||||
TEXT(SERVICENAME),
|
||||
(LPHANDLER_FUNCTION) ServiceCtrl) ;
|
||||
if (ServiceStatusHandle == (SERVICE_STATUS_HANDLE) 0) {
|
||||
serviceLogError("RegisterServiceCtrlHandler failed") ;
|
||||
return ;
|
||||
}
|
||||
|
||||
serviceReport(SERVICE_START_PENDING, NO_ERROR, (30 * 1000)) ;
|
||||
|
||||
/*
|
||||
* Initialize & Run service
|
||||
*/
|
||||
|
||||
serviceLogTrace("start initializing") ;
|
||||
|
||||
if (config_load((int) dwArgc, (char **) lpszArgv) != TRUE) {
|
||||
serviceLogError("cannot initialize server") ;
|
||||
serviceReport(SERVICE_STOPPED, 0, 0) ;
|
||||
return ;
|
||||
}
|
||||
log_configure((int) dwArgc, (char **) lpszArgv) ;
|
||||
|
||||
if (WSAStartup(version, &wsaData) != 0) {
|
||||
serviceLogError("cannot initialize WinSock") ;
|
||||
serviceReport(SERVICE_STOPPED, 0, 0) ;
|
||||
return ;
|
||||
}
|
||||
if (server_init((int) dwArgc, (char **) lpszArgv) != TRUE) {
|
||||
serviceLogError("cannot initialize server") ;
|
||||
serviceReport(SERVICE_STOPPED, 0, 0) ;
|
||||
WSACleanup() ;
|
||||
return ;
|
||||
}
|
||||
|
||||
serviceReport(SERVICE_RUNNING, NO_ERROR, 0) ;
|
||||
|
||||
serviceLogTrace("initialization done, running now") ;
|
||||
|
||||
server_loop() ; /* do service here */
|
||||
|
||||
serviceLogTrace("service loop finished, closing") ;
|
||||
|
||||
serviceReport(SERVICE_STOP_PENDING, NO_ERROR, (10 * 1000)) ;
|
||||
|
||||
server_done() ; /* cleaup */
|
||||
WSACleanup() ;
|
||||
|
||||
serviceLogTrace("service finised") ;
|
||||
|
||||
serviceReport(SERVICE_STOPPED, NO_ERROR, 0) ;
|
||||
|
||||
log_terminate() ;
|
||||
}
|
||||
|
||||
/*
|
||||
* serviceRun - run Service
|
||||
*/
|
||||
|
||||
static SERVICE_TABLE_ENTRY ServiceTable[] = {
|
||||
{ TEXT(SERVICENAME), (LPSERVICE_MAIN_FUNCTION) ServiceMain } ,
|
||||
{ NULL, NULL }
|
||||
} ;
|
||||
|
||||
void serviceRun(int ac, char *av[])
|
||||
{
|
||||
serviceLogTrace("serviceRun - start") ;
|
||||
|
||||
if (StartServiceCtrlDispatcher(ServiceTable) == 0) {
|
||||
serviceLogError("StartServiceCtrlDispatcher failed") ;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* serviceInstall - install service
|
||||
*/
|
||||
|
||||
void serviceInstall(int ac, char *av[])
|
||||
{
|
||||
SC_HANDLE hSCManager = NULL ;
|
||||
SC_HANDLE hService = NULL ;
|
||||
|
||||
getFileName() ;
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("Install Service %s \"%s\"\n", SERVICENAME, p_ful) ;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* open Service Manager
|
||||
*/
|
||||
|
||||
hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS) ;
|
||||
|
||||
if (hSCManager == NULL) {
|
||||
printf("cannot open SCManager %d\n", GetLastError()) ;
|
||||
return ;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("open SCManager\n") ; fflush(stdout) ;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* prepare service path (exe path with arguments)
|
||||
*/
|
||||
|
||||
sprintf(pathService, "\"%s\" -service", p_ful) ;
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("Installing %s\n", pathService) ;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* create service entry
|
||||
*/
|
||||
|
||||
hService = CreateService(
|
||||
hSCManager, /* SCManager database */
|
||||
TEXT(SERVICENAME), /* name of service */
|
||||
TEXT(DISPLAYNAME), /* its display name */
|
||||
SERVICE_ALL_ACCESS, /* desired access */
|
||||
SERVICE_WIN32_OWN_PROCESS, /* service type */
|
||||
SERVICE_DEMAND_START, /* start type */
|
||||
SERVICE_ERROR_IGNORE, /* error control type */
|
||||
TEXT(pathService), /* service image */
|
||||
NULL, /* no load order */
|
||||
NULL, /* no tag identifier */
|
||||
NULL, /* no dependencies */
|
||||
NULL, /* LocalSystem account */
|
||||
NULL) ; /* no password */
|
||||
|
||||
CloseServiceHandle(hSCManager) ;
|
||||
|
||||
if (hService == NULL) {
|
||||
printf("cannot create service %d\n", GetLastError()) ;
|
||||
return ;
|
||||
}
|
||||
|
||||
CloseServiceHandle(hSCManager) ;
|
||||
|
||||
printf("Installed Service %s\n", pathService) ;
|
||||
}
|
||||
|
||||
/*
|
||||
* serviceRemove - remove service
|
||||
*/
|
||||
|
||||
void serviceRemove(int ac, char *av[])
|
||||
{
|
||||
SC_HANDLE hSCManager = NULL ;
|
||||
SC_HANDLE hService = NULL ;
|
||||
|
||||
getFileName() ;
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("Removing Service %s\n", SERVICENAME) ;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* open Service Manager
|
||||
*/
|
||||
|
||||
hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS) ;
|
||||
|
||||
if (hSCManager == NULL) {
|
||||
printf("cannot open SCManager %d\n", GetLastError()) ;
|
||||
return ;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("open SCManager\n") ; fflush(stdout) ;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* delete service
|
||||
*/
|
||||
|
||||
hService = OpenService(
|
||||
hSCManager, /* SCManager database */
|
||||
TEXT(SERVICENAME), /* name of service */
|
||||
DELETE) ; /* type of access */
|
||||
|
||||
if (hService == NULL) {
|
||||
printf("cannot open service %s %d\n", SERVICENAME, GetLastError()) ;
|
||||
CloseServiceHandle(hSCManager) ;
|
||||
return ;
|
||||
}
|
||||
if (DeleteService(hService) == 0) {
|
||||
printf("cannot remove service %s %d\n", SERVICENAME, GetLastError()) ;
|
||||
CloseServiceHandle(hService) ;
|
||||
CloseServiceHandle(hSCManager) ;
|
||||
return ;
|
||||
}
|
||||
|
||||
CloseServiceHandle(hService) ;
|
||||
CloseServiceHandle(hSCManager) ;
|
||||
|
||||
printf("Removed Service %s\n", SERVICENAME) ;
|
||||
}
|
||||
|
||||
#endif /* WIN32 */
|
||||
72
contrib/idn/mdnkit/dnsproxy/winserv.h
Normal file
72
contrib/idn/mdnkit/dnsproxy/winserv.h
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* winserv.h - mDNS Proxy, WIN32 Service Specific Functions
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
/* $Id: winserv.h,v 1.6 2000/07/04 03:52:29 ishisone Exp $ */
|
||||
|
||||
#ifndef WINSERV_H
|
||||
#define WINSERV_H 1
|
||||
|
||||
void serviceRun(int ac, char *av[]) ;
|
||||
void serviceInstall(int ac, char *av[]) ;
|
||||
void serviceRemove(int ac, char *av[]) ;
|
||||
|
||||
#endif /* WINSERV_H */
|
||||
73
contrib/idn/mdnkit/include/Makefile.in
Normal file
73
contrib/idn/mdnkit/include/Makefile.in
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
# $Id: Makefile.in,v 1.1 2000/08/09 07:10:31 ishisone 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
# Tokyo, Japan.
|
||||
#
|
||||
# 1. Use, Modification and Redistribution (including distribution of any
|
||||
# modified or derived work) in source and/or binary forms is permitted
|
||||
# under this License Terms and Conditions.
|
||||
#
|
||||
# 2. Redistribution of source code must retain the copyright notices as they
|
||||
# appear in each source code file, this License Terms and Conditions.
|
||||
#
|
||||
# 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
# this License Terms and Conditions, in the documentation and/or other
|
||||
# materials provided with the distribution. For the purposes of binary
|
||||
# distribution the "Copyright Notice" refers to the following language:
|
||||
# "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
#
|
||||
# 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
# derived from this Software without specific prior written approval of
|
||||
# JPNIC.
|
||||
#
|
||||
# 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
#
|
||||
# 6. Indemnification by Licensee
|
||||
# Any person or entities using and/or redistributing this Software under
|
||||
# this License Terms and Conditions shall defend indemnify and hold
|
||||
# harmless JPNIC from and against any and all judgements damages,
|
||||
# expenses, settlement liabilities, cost and other liabilities of any
|
||||
# kind as a result of use and redistribution of this Software or any
|
||||
# claim, suite, action, litigation or proceeding by any third party
|
||||
# arising out of or relates to this License Terms and Conditions.
|
||||
#
|
||||
# 7. Governing Law, Jurisdiction and Venue
|
||||
# This License Terms and Conditions shall be governed by and and
|
||||
# construed in accordance with the law of Japan. Any person or entities
|
||||
# using and/or redistributing this Software under this License Terms and
|
||||
# Conditions hereby agrees and consent to the personal and exclusive
|
||||
# jurisdiction and venue of Tokyo District Court of Japan.
|
||||
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
prefix = @prefix@
|
||||
exec_prefix = @exec_prefix@
|
||||
|
||||
SUBDIRS = mdn
|
||||
|
||||
all:
|
||||
for d in $(SUBDIRS); do (cd $$d; $(MAKE) all); done
|
||||
|
||||
install:
|
||||
for d in $(SUBDIRS); do (cd $$d; $(MAKE) install); done
|
||||
|
||||
clean:
|
||||
for d in $(SUBDIRS); do (cd $$d; $(MAKE) clean); done
|
||||
123
contrib/idn/mdnkit/include/config.h
Normal file
123
contrib/idn/mdnkit/include/config.h
Normal file
|
|
@ -0,0 +1,123 @@
|
|||
/* include/config.h. Generated automatically by configure. */
|
||||
/* include/config.h.in. Generated automatically from configure.in by autoheader. */
|
||||
/* $Id: config.h.in,v 1.16 2000/11/17 06:51:36 ishisone 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
/* Define to `int' if <sys/types.h> doesn't define. */
|
||||
/* #undef gid_t */
|
||||
|
||||
/* Define if you have the ANSI C header files. */
|
||||
#define STDC_HEADERS 1
|
||||
|
||||
/* Define to `int' if <sys/types.h> doesn't define. */
|
||||
/* #undef uid_t */
|
||||
|
||||
/* Define if your iconv() does not accept "UTF-8" as the codeset name for utf-8. */
|
||||
/* #undef MDN_UTF8_ENCODING_NAME */
|
||||
|
||||
/* Define if you want ZLD feature compiled in. */
|
||||
/* #undef MDN_SUPPORT_ZLD */
|
||||
|
||||
/* Define if the prefix of RACE encoding differs from 'bq--'. */
|
||||
/* #undef MDN_RACE_PREFIX */
|
||||
|
||||
/* Define if the suffix of BRACE encoding differs from '-8q9'. */
|
||||
/* #undef MDN_BRACE_SUFFIX */
|
||||
|
||||
/* Define if the prefix of LACE encoding differs from 'bq--'. */
|
||||
/* #undef MDN_LACE_PREFIX */
|
||||
|
||||
/* Define as an appropriate type (ex. int) if your system doesn't have. */
|
||||
#define BOOL int
|
||||
|
||||
/* Define if you have the bcopy function. */
|
||||
#define HAVE_BCOPY 1
|
||||
|
||||
/* Define if you have the memmove function. */
|
||||
#define HAVE_MEMMOVE 1
|
||||
|
||||
/* Define if you have the nl_langinfo function. */
|
||||
#define HAVE_NL_LANGINFO 1
|
||||
|
||||
/* Define if you have the setlocale function. */
|
||||
#define HAVE_SETLOCALE 1
|
||||
|
||||
/* Define if you have the setvbuf function. */
|
||||
#define HAVE_SETVBUF 1
|
||||
|
||||
/* Define if you have the vsnprintf function. */
|
||||
#define HAVE_VSNPRINTF 1
|
||||
|
||||
/* Define if you have the <langinfo.h> header file. */
|
||||
#define HAVE_LANGINFO_H 1
|
||||
|
||||
/* Define if you have the <locale.h> header file. */
|
||||
#define HAVE_LOCALE_H 1
|
||||
|
||||
/* Define if you have the <sys/select.h> header file. */
|
||||
#define HAVE_SYS_SELECT_H 1
|
||||
|
||||
/* Define if you have the <unistd.h> header file. */
|
||||
#define HAVE_UNISTD_H 1
|
||||
|
||||
/* Define if you have the nsl library (-lnsl). */
|
||||
/* #undef HAVE_LIBNSL */
|
||||
|
||||
/* Define if you have the socket library (-lsocket). */
|
||||
/* #undef HAVE_LIBSOCKET */
|
||||
122
contrib/idn/mdnkit/include/config.h.in
Normal file
122
contrib/idn/mdnkit/include/config.h.in
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
/* include/config.h.in. Generated automatically from configure.in by autoheader. */
|
||||
/* $Id: config.h.in,v 1.16 2000/11/17 06:51:36 ishisone 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
/* Define to `int' if <sys/types.h> doesn't define. */
|
||||
#undef gid_t
|
||||
|
||||
/* Define if you have the ANSI C header files. */
|
||||
#undef STDC_HEADERS
|
||||
|
||||
/* Define to `int' if <sys/types.h> doesn't define. */
|
||||
#undef uid_t
|
||||
|
||||
/* Define if your iconv() does not accept "UTF-8" as the codeset name for utf-8. */
|
||||
#undef MDN_UTF8_ENCODING_NAME
|
||||
|
||||
/* Define if you want ZLD feature compiled in. */
|
||||
#undef MDN_SUPPORT_ZLD
|
||||
|
||||
/* Define if the prefix of RACE encoding differs from 'bq--'. */
|
||||
#undef MDN_RACE_PREFIX
|
||||
|
||||
/* Define if the suffix of BRACE encoding differs from '-8q9'. */
|
||||
#undef MDN_BRACE_SUFFIX
|
||||
|
||||
/* Define if the prefix of LACE encoding differs from 'bq--'. */
|
||||
#undef MDN_LACE_PREFIX
|
||||
|
||||
/* Define as an appropriate type (ex. int) if your system doesn't have. */
|
||||
#undef BOOL
|
||||
|
||||
/* Define if you have the bcopy function. */
|
||||
#undef HAVE_BCOPY
|
||||
|
||||
/* Define if you have the memmove function. */
|
||||
#undef HAVE_MEMMOVE
|
||||
|
||||
/* Define if you have the nl_langinfo function. */
|
||||
#undef HAVE_NL_LANGINFO
|
||||
|
||||
/* Define if you have the setlocale function. */
|
||||
#undef HAVE_SETLOCALE
|
||||
|
||||
/* Define if you have the setvbuf function. */
|
||||
#undef HAVE_SETVBUF
|
||||
|
||||
/* Define if you have the vsnprintf function. */
|
||||
#undef HAVE_VSNPRINTF
|
||||
|
||||
/* Define if you have the <langinfo.h> header file. */
|
||||
#undef HAVE_LANGINFO_H
|
||||
|
||||
/* Define if you have the <locale.h> header file. */
|
||||
#undef HAVE_LOCALE_H
|
||||
|
||||
/* Define if you have the <sys/select.h> header file. */
|
||||
#undef HAVE_SYS_SELECT_H
|
||||
|
||||
/* Define if you have the <unistd.h> header file. */
|
||||
#undef HAVE_UNISTD_H
|
||||
|
||||
/* Define if you have the nsl library (-lnsl). */
|
||||
#undef HAVE_LIBNSL
|
||||
|
||||
/* Define if you have the socket library (-lsocket). */
|
||||
#undef HAVE_LIBSOCKET
|
||||
85
contrib/idn/mdnkit/include/config.h.os2
Normal file
85
contrib/idn/mdnkit/include/config.h.os2
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
/* $Id: config.h.os2,v 1.3 2000/08/07 08:20:40 ishisone 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
/* Define if you have the vsnprintf function. */
|
||||
#undef HAVE_VSNPRINTF
|
||||
|
||||
/* Define if you have the setvbuf function. */
|
||||
#undef HAVE_SETVBUF
|
||||
|
||||
/* Define if you have the setlocale function. */
|
||||
#undef HAVE_SETLOCALE
|
||||
|
||||
/* Define if you have the nl_langinfo function. */
|
||||
#undef HAVE_NL_LANGINFO
|
||||
|
||||
/* Define if you have the <langinfo.h> header file. */
|
||||
#undef HAVE_LANGINFO_H
|
||||
|
||||
/* Define if you have the <locale.h> header file. */
|
||||
#undef HAVE_LOCALE_H
|
||||
|
||||
/* Define if you have the <unistd.h> header file. */
|
||||
#undef HAVE_UNISTD_H
|
||||
|
||||
/* Define if your iconv() does not accept "UTF-8" as the codeset name for utf-8. */
|
||||
#undef MDN_UTF8_ENCODING_NAME
|
||||
|
||||
/* Define if you want ZLD feature compiled in. */
|
||||
#undef MDN_SUPPORT_ZLD
|
||||
85
contrib/idn/mdnkit/include/config.h.win
Normal file
85
contrib/idn/mdnkit/include/config.h.win
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
/* $Id: config.h.win,v 1.3 2000/08/07 08:20:40 ishisone 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
/* Define if you have the vsnprintf function. */
|
||||
#undef HAVE_VSNPRINTF
|
||||
|
||||
/* Define if you have the setvbuf function. */
|
||||
#undef HAVE_SETVBUF
|
||||
|
||||
/* Define if you have the setlocale function. */
|
||||
#undef HAVE_SETLOCALE
|
||||
|
||||
/* Define if you have the nl_langinfo function. */
|
||||
#undef HAVE_NL_LANGINFO
|
||||
|
||||
/* Define if you have the <langinfo.h> header file. */
|
||||
#undef HAVE_LANGINFO_H
|
||||
|
||||
/* Define if you have the <locale.h> header file. */
|
||||
#undef HAVE_LOCALE_H
|
||||
|
||||
/* Define if you have the <unistd.h> header file. */
|
||||
#undef HAVE_UNISTD_H
|
||||
|
||||
/* Define if your iconv() does not accept "UTF-8" as the codeset name for utf-8. */
|
||||
#undef MDN_UTF8_ENCODING_NAME
|
||||
|
||||
/* Define if you want ZLD feature compiled in. */
|
||||
#undef MDN_SUPPORT_ZLD
|
||||
110
contrib/idn/mdnkit/include/mdn/Makefile.in
Normal file
110
contrib/idn/mdnkit/include/mdn/Makefile.in
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
# $Id: Makefile.in,v 1.4 2000/11/14 00:13:29 ishisone 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
# Tokyo, Japan.
|
||||
#
|
||||
# 1. Use, Modification and Redistribution (including distribution of any
|
||||
# modified or derived work) in source and/or binary forms is permitted
|
||||
# under this License Terms and Conditions.
|
||||
#
|
||||
# 2. Redistribution of source code must retain the copyright notices as they
|
||||
# appear in each source code file, this License Terms and Conditions.
|
||||
#
|
||||
# 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
# this License Terms and Conditions, in the documentation and/or other
|
||||
# materials provided with the distribution. For the purposes of binary
|
||||
# distribution the "Copyright Notice" refers to the following language:
|
||||
# "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
#
|
||||
# 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
# derived from this Software without specific prior written approval of
|
||||
# JPNIC.
|
||||
#
|
||||
# 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
#
|
||||
# 6. Indemnification by Licensee
|
||||
# Any person or entities using and/or redistributing this Software under
|
||||
# this License Terms and Conditions shall defend indemnify and hold
|
||||
# harmless JPNIC from and against any and all judgements damages,
|
||||
# expenses, settlement liabilities, cost and other liabilities of any
|
||||
# kind as a result of use and redistribution of this Software or any
|
||||
# claim, suite, action, litigation or proceeding by any third party
|
||||
# arising out of or relates to this License Terms and Conditions.
|
||||
#
|
||||
# 7. Governing Law, Jurisdiction and Venue
|
||||
# This License Terms and Conditions shall be governed by and and
|
||||
# construed in accordance with the law of Japan. Any person or entities
|
||||
# using and/or redistributing this Software under this License Terms and
|
||||
# Conditions hereby agrees and consent to the personal and exclusive
|
||||
# jurisdiction and venue of Tokyo District Court of Japan.
|
||||
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
prefix = @prefix@
|
||||
exec_prefix = @exec_prefix@
|
||||
|
||||
BINDIR = @bindir@
|
||||
LIBDIR = @libdir@
|
||||
INCDIR = @includedir@
|
||||
MDNINCDIR = $(INCDIR)/mdn
|
||||
|
||||
INSTALL = @INSTALL@
|
||||
INSTALL_PROGRAM = @INSTALL_PROGRAM@
|
||||
INSTALL_DATA = @INSTALL_DATA@
|
||||
|
||||
HDRS = \
|
||||
assert.h \
|
||||
brace.h \
|
||||
converter.h \
|
||||
debug.h \
|
||||
dn.h \
|
||||
lace.h \
|
||||
localencoding.h \
|
||||
log.h \
|
||||
logmacro.h \
|
||||
msgheader.h \
|
||||
msgtrans.h \
|
||||
normalizer.h \
|
||||
race.h \
|
||||
res.h \
|
||||
resconf.h \
|
||||
result.h \
|
||||
selectiveencode.h \
|
||||
strhash.h \
|
||||
translator.h \
|
||||
unicode.h \
|
||||
unormalize.h \
|
||||
utf5.h \
|
||||
utf8.h \
|
||||
util.h \
|
||||
zldrule.h
|
||||
|
||||
all:
|
||||
|
||||
install:
|
||||
[ -d $(INCDIR) ] || mkdir $(INCDIR)
|
||||
[ -d $(MDNINCDIR) ] || mkdir $(MDNINCDIR)
|
||||
for hdr in $(HDRS); \
|
||||
do $(INSTALL_DATA) $(srcdir)/$$hdr $(MDNINCDIR); done
|
||||
|
||||
clean:
|
||||
rm -f *~
|
||||
|
||||
69
contrib/idn/mdnkit/include/mdn/assert.h
Normal file
69
contrib/idn/mdnkit/include/mdn/assert.h
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
/* $Id: assert.h,v 1.5 2000/07/04 03:52:31 ishisone 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
#ifndef MDN_ASSERT_H
|
||||
#define MDN_ASSERT_H 1
|
||||
|
||||
#ifndef DEBUG
|
||||
#define NDEBUG
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
# endif /* MDN_ASSERT_H */
|
||||
82
contrib/idn/mdnkit/include/mdn/brace.h
Normal file
82
contrib/idn/mdnkit/include/mdn/brace.h
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
/* $Id: brace.h,v 1.1 2000/11/14 00:13:29 ishisone 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
#ifndef MDN_BRACE_H
|
||||
#define MDN_BRACE_H 1
|
||||
|
||||
/*
|
||||
* BRACE Converter.
|
||||
*
|
||||
* See Internet Draft draft-ietf-idn-brace-00.txt for details.
|
||||
*/
|
||||
|
||||
#include <mdn/result.h>
|
||||
#include <mdn/converter.h>
|
||||
|
||||
extern mdn_result_t
|
||||
mdn__brace_open(mdn_converter_t ctx, mdn_converter_dir_t dir);
|
||||
|
||||
extern mdn_result_t
|
||||
mdn__brace_close(mdn_converter_t ctx, mdn_converter_dir_t dir);
|
||||
|
||||
extern mdn_result_t
|
||||
mdn__brace_convert(mdn_converter_t ctx, mdn_converter_dir_t dir,
|
||||
const char *from, char *to, size_t tolen);
|
||||
|
||||
#endif /* MDN_BRACE_H */
|
||||
234
contrib/idn/mdnkit/include/mdn/converter.h
Normal file
234
contrib/idn/mdnkit/include/mdn/converter.h
Normal file
|
|
@ -0,0 +1,234 @@
|
|||
/* $Id: converter.h,v 1.13 2000/08/02 02:06:40 ishisone 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
#ifndef MDN_CONVERTER_H
|
||||
#define MDN_CONVERTER_H 1
|
||||
|
||||
/*
|
||||
* Codeset converter.
|
||||
*
|
||||
* This module provides conversions from some local codeset to UTF-8
|
||||
* and vice versa.
|
||||
*/
|
||||
|
||||
#include <mdn/result.h>
|
||||
|
||||
/*
|
||||
* Converter context type (opaque).
|
||||
*/
|
||||
typedef struct mdn_converter *mdn_converter_t;
|
||||
|
||||
/*
|
||||
* Conversion direction (local codeset -> UTF-8 or the opposite)
|
||||
*/
|
||||
typedef enum {
|
||||
mdn_converter_l2u, /* local-to-utf8 */
|
||||
mdn_converter_u2l /* utf8-to-local */
|
||||
} mdn_converter_dir_t;
|
||||
|
||||
/*
|
||||
* Conversion flags.
|
||||
*/
|
||||
#define MDN_CONVERTER_DELAYEDOPEN 1
|
||||
#define MDN_CONVERTER_RTCHECK 2
|
||||
|
||||
/*
|
||||
* Initialize module. Must be called before any other calls of
|
||||
* the functions of this module.
|
||||
*
|
||||
* Returns:
|
||||
* mdn_success -- ok.
|
||||
* mdn_nomemory -- malloc failed.
|
||||
*/
|
||||
extern mdn_result_t
|
||||
mdn_converter_initialize(void);
|
||||
|
||||
/*
|
||||
* Create a conversion context.
|
||||
*
|
||||
* Returns:
|
||||
* mdn_success -- ok.
|
||||
* mdn_invalid_name -- specified codeset is not supported.
|
||||
* mdn_nomemory -- malloc failed.
|
||||
* mdn_failure -- other failure (unknown cause).
|
||||
*/
|
||||
extern mdn_result_t
|
||||
mdn_converter_create(const char *name, mdn_converter_t *ctxp,
|
||||
int flags);
|
||||
|
||||
/*
|
||||
* Destroy the conversion context created by mdn_converter_create.
|
||||
*/
|
||||
extern void
|
||||
mdn_converter_destroy(mdn_converter_t ctx);
|
||||
|
||||
/*
|
||||
* Convert between local codeset and UTF-8. Note that each conversion
|
||||
* is started with initial state.
|
||||
*
|
||||
* Returns:
|
||||
* mdn_success -- ok.
|
||||
* mdn_buffer_overflow -- output buffer is too small.
|
||||
* mdn_invalid_encoding -- the input string has invalid/illegal
|
||||
* byte sequence.
|
||||
* mdn_invalid_name -- codeset is not supported (this error
|
||||
* should happen only if 'delayedopen'
|
||||
* flag was set when mdn_converter_create
|
||||
* was called)
|
||||
* mdn_failure -- other failure.
|
||||
*/
|
||||
extern mdn_result_t
|
||||
mdn_converter_convert(mdn_converter_t ctx, mdn_converter_dir_t dir,
|
||||
const char *from, char *to, size_t tolen);
|
||||
|
||||
/*
|
||||
* Macros for convenience.
|
||||
*/
|
||||
#define mdn_converter_localtoutf8(ctx, from, to, tolen) \
|
||||
mdn_converter_convert((ctx), mdn_converter_l2u, (from), (to), (tolen))
|
||||
|
||||
#define mdn_converter_utf8tolocal(ctx, from, to, tolen) \
|
||||
mdn_converter_convert((ctx), mdn_converter_u2l, (from), (to), (tolen))
|
||||
|
||||
/*
|
||||
* Get the name of local codeset. The returned name may be different from
|
||||
* the one specified to mdn_converter_create, if the specified one was an
|
||||
* alias.
|
||||
*
|
||||
* Returns:
|
||||
* the local codeset name.
|
||||
*/
|
||||
extern char *
|
||||
mdn_converter_localencoding(mdn_converter_t ctx);
|
||||
|
||||
/*
|
||||
* Return if this local encoding is a special one that a string in this
|
||||
* encoding just looks like an ordinary ASCII string.
|
||||
* A few types of encoding designed specially for domain name conversion
|
||||
* (such as UTF-5) fall into this category.
|
||||
*
|
||||
* Returns:
|
||||
* 1 -- yes, it is special.
|
||||
* 0 -- no.
|
||||
*/
|
||||
extern int
|
||||
mdn_converter_isasciicompatible(mdn_converter_t ctx);
|
||||
|
||||
/*
|
||||
* Register an alias for a codeset name.
|
||||
*
|
||||
* Returns:
|
||||
* mdn_success -- ok.
|
||||
* mdn_nomemory -- malloc failed.
|
||||
*/
|
||||
extern mdn_result_t
|
||||
mdn_converter_addalias(const char *alias_name, const char *real_name);
|
||||
|
||||
/*
|
||||
* Register aliases defined by the specified file.
|
||||
*
|
||||
* Returns:
|
||||
* mdn_success -- ok.
|
||||
* mdn_nofile -- no such file.
|
||||
* mdn_invalid_syntax -- file is malformed.
|
||||
* mdn_nomemory -- malloc failed.
|
||||
*/
|
||||
extern mdn_result_t
|
||||
mdn_converter_aliasfile(const char *path);
|
||||
|
||||
/*
|
||||
* Unregister all the aliases.
|
||||
*/
|
||||
extern mdn_result_t
|
||||
mdn_converter_resetalias(void);
|
||||
|
||||
|
||||
/*
|
||||
* New converter registration.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Conversion operation functions.
|
||||
*/
|
||||
typedef mdn_result_t (*mdn_converter_openproc_t)(mdn_converter_t ctx,
|
||||
mdn_converter_dir_t dir);
|
||||
typedef mdn_result_t (*mdn_converter_closeproc_t)(mdn_converter_t ctx,
|
||||
mdn_converter_dir_t dir);
|
||||
typedef mdn_result_t (*mdn_converter_convertproc_t)(mdn_converter_t ctx,
|
||||
mdn_converter_dir_t dir,
|
||||
const char *from,
|
||||
char *to, size_t tolen);
|
||||
|
||||
/*
|
||||
* Register a new converter.
|
||||
* 'ascii_compatible' is a boolean flag indicating this encoding is
|
||||
* an `ascii-compatible encoding'.
|
||||
*
|
||||
* Returns:
|
||||
* mdn_success -- ok.
|
||||
* mdn_nomemory -- malloc failed.
|
||||
*/
|
||||
extern mdn_result_t
|
||||
mdn_converter_register(const char *name,
|
||||
mdn_converter_openproc_t open,
|
||||
mdn_converter_closeproc_t close,
|
||||
mdn_converter_convertproc_t convert,
|
||||
int ascii_compatible);
|
||||
|
||||
#endif /* MDN_CONVERTER_H */
|
||||
72
contrib/idn/mdnkit/include/mdn/debug.h
Normal file
72
contrib/idn/mdnkit/include/mdn/debug.h
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
/* $Id: debug.h,v 1.7 2000/07/04 03:52:32 ishisone 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
#ifndef MDN_DEBUG_H
|
||||
#define MDN_DEBUG_H 1
|
||||
|
||||
/*
|
||||
* Debug utility
|
||||
*/
|
||||
|
||||
extern char *mdn_debug_hexstring(const char *s, int maxbytes);
|
||||
extern char *mdn_debug_xstring(const char *s, int maxbytes);
|
||||
extern char *mdn_debug_hexdata(const char *s, int length, int maxlength);
|
||||
extern void mdn_debug_hexdump(const char *s, int length);
|
||||
|
||||
#endif /* MDN_DEBUG_H */
|
||||
117
contrib/idn/mdnkit/include/mdn/dn.h
Normal file
117
contrib/idn/mdnkit/include/mdn/dn.h
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
/* $Id: dn.h,v 1.7 2000/08/02 02:06:40 ishisone 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
#ifndef MDN_DN_H
|
||||
#define MDN_DN_H 1
|
||||
|
||||
#define MDN_DN_NPTRS 64
|
||||
|
||||
/*
|
||||
* Domain name compression/expansion.
|
||||
*
|
||||
* The interface this module provides is similar to the standard
|
||||
* dn_comp and dn_expand, but with a twist.
|
||||
*/
|
||||
|
||||
#include <mdn/result.h>
|
||||
|
||||
/*
|
||||
* Compression context.
|
||||
*/
|
||||
typedef struct {
|
||||
const unsigned char *msg;
|
||||
int cur;
|
||||
int offset[MDN_DN_NPTRS];
|
||||
} mdn__dn_t;
|
||||
|
||||
/*
|
||||
* Expand a compressed domain name.
|
||||
*
|
||||
* It is similar to dn_expand in resolver library.
|
||||
*
|
||||
* Returns:
|
||||
* mdn_success -- ok.
|
||||
* mdn_buffer_overflow -- 'buflen' is too small.
|
||||
* mdn_invalid_message -- the specified message is not valid.
|
||||
*/
|
||||
extern mdn_result_t
|
||||
mdn__dn_expand(const char *msg, size_t msglen, const char *compressed,
|
||||
char *expanded, size_t buflen, size_t *complenp);
|
||||
|
||||
/*
|
||||
* Initialize compression context.
|
||||
*/
|
||||
extern void
|
||||
mdn__dn_initcompress(mdn__dn_t *ctx, const char *msg);
|
||||
|
||||
/*
|
||||
* Compress a domain name.
|
||||
*
|
||||
* It is similar to dn_comp.
|
||||
*
|
||||
* Returns:
|
||||
* mdn_success -- ok.
|
||||
* mdn_buffer_overflow -- 'length' is too small.
|
||||
* mdn_invalid_name -- the specified name is invalid.
|
||||
*/
|
||||
extern mdn_result_t
|
||||
mdn__dn_compress(const char *name, char *sptr, size_t length,
|
||||
mdn__dn_t *ctx, size_t *complenp);
|
||||
|
||||
#endif /* MDN_DN_H */
|
||||
82
contrib/idn/mdnkit/include/mdn/lace.h
Normal file
82
contrib/idn/mdnkit/include/mdn/lace.h
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
/* $Id: lace.h,v 1.1 2000/11/14 00:13:29 ishisone 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
#ifndef MDN_LACE_H
|
||||
#define MDN_LACE_H 1
|
||||
|
||||
/*
|
||||
* LACE Converter.
|
||||
*
|
||||
* See Internet Draft draft-ietf-idn-lace-00.txt for details.
|
||||
*/
|
||||
|
||||
#include <mdn/result.h>
|
||||
#include <mdn/converter.h>
|
||||
|
||||
extern mdn_result_t
|
||||
mdn__lace_open(mdn_converter_t ctx, mdn_converter_dir_t dir);
|
||||
|
||||
extern mdn_result_t
|
||||
mdn__lace_close(mdn_converter_t ctx, mdn_converter_dir_t dir);
|
||||
|
||||
extern mdn_result_t
|
||||
mdn__lace_convert(mdn_converter_t ctx, mdn_converter_dir_t dir,
|
||||
const char *from, char *to, size_t tolen);
|
||||
|
||||
#endif /* MDN_LACE_H */
|
||||
85
contrib/idn/mdnkit/include/mdn/localencoding.h
Normal file
85
contrib/idn/mdnkit/include/mdn/localencoding.h
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
/* $Id: localencoding.h,v 1.7 2000/08/02 02:06:40 ishisone 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
#ifndef MDN_LOCALENCODING_H
|
||||
#define MDN_LOCALENCODING_H 1
|
||||
|
||||
/*
|
||||
* Local codeset detection.
|
||||
*
|
||||
* Determine the local codeset (the codeset used by the current application),
|
||||
* based on the locale information.
|
||||
*/
|
||||
|
||||
#define MDN_LOCALCS_ENV "MDN_LOCAL_CODESET"
|
||||
|
||||
/*
|
||||
* Get the codeset name corresponding to the current locale,
|
||||
* suitable for passing to 'mdn_converter_create'.
|
||||
*
|
||||
* If the codeset cannot be determined, the locale name itself
|
||||
* will be returned in the hope that codeset alias file translates it
|
||||
* to the right name.
|
||||
*
|
||||
* If it cannot retrieve the current locale name, NULL will be
|
||||
* returned.
|
||||
*/
|
||||
extern const char *mdn_localencoding_name(void);
|
||||
|
||||
#endif /* MDN_LOCALENCODING_H */
|
||||
113
contrib/idn/mdnkit/include/mdn/log.h
Normal file
113
contrib/idn/mdnkit/include/mdn/log.h
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
/* $Id: log.h,v 1.9 2000/10/16 05:00:17 ishisone 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
#ifndef MDN_LOG_H
|
||||
#define MDN_LOG_H 1
|
||||
|
||||
/*
|
||||
* MDN library logging facility.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Log level definition.
|
||||
*/
|
||||
enum {
|
||||
mdn_log_level_fatal = 0,
|
||||
mdn_log_level_error = 1,
|
||||
mdn_log_level_warning = 2,
|
||||
mdn_log_level_info = 3,
|
||||
mdn_log_level_trace = 4,
|
||||
mdn_log_level_dump = 5
|
||||
};
|
||||
|
||||
/*
|
||||
* Log handler type.
|
||||
*/
|
||||
typedef void (*mdn_log_proc_t)(int level, const char *msg);
|
||||
|
||||
/*
|
||||
* Log routines.
|
||||
*/
|
||||
extern void mdn_log_fatal(const char *fmt, ...);
|
||||
extern void mdn_log_error(const char *fmt, ...);
|
||||
extern void mdn_log_warning(const char *fmt, ...);
|
||||
extern void mdn_log_info(const char *fmt, ...);
|
||||
extern void mdn_log_trace(const char *fmt, ...);
|
||||
extern void mdn_log_dump(const char *fmt, ...);
|
||||
|
||||
/*
|
||||
* Set/get log level.
|
||||
*
|
||||
* If log level has not been explicitly defined by 'mdn_log_setlevel',
|
||||
* the default level is determined by the value of enrironment
|
||||
* variable 'MDN_LOG_LEVEL'.
|
||||
*/
|
||||
extern void mdn_log_setlevel(int level);
|
||||
extern int mdn_log_getlevel(void);
|
||||
|
||||
/*
|
||||
* Set log handler.
|
||||
*
|
||||
* If no log handler is set, log goes to stderr by default.
|
||||
* You can reset the handler to the default one by specifying
|
||||
* NULL.
|
||||
*/
|
||||
extern void mdn_log_setproc(mdn_log_proc_t proc);
|
||||
|
||||
#endif /* MDN_LOG_H */
|
||||
80
contrib/idn/mdnkit/include/mdn/logmacro.h
Normal file
80
contrib/idn/mdnkit/include/mdn/logmacro.h
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
/* $Id: logmacro.h,v 1.9 2000/09/20 02:47:29 ishisone 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
#ifndef MDN_LOGMACRO_H
|
||||
#define MDN_LOGMACRO_H 1
|
||||
|
||||
#include <mdn/log.h>
|
||||
|
||||
#define FATAL(x) mdn_log_fatal x
|
||||
#define ERROR(x) mdn_log_error x
|
||||
#define WARNING(x) mdn_log_warning x
|
||||
#define INFO(x) mdn_log_info x
|
||||
|
||||
#ifdef DEBUG
|
||||
#define TRACE(x) mdn_log_trace x
|
||||
#define DUMP(x) mdn_log_dump x
|
||||
#else
|
||||
#define TRACE(x)
|
||||
#define DUMP(x)
|
||||
#endif /* DEBUG */
|
||||
|
||||
#define LOGLEVEL mdn_log_getlevel()
|
||||
|
||||
#endif /* MDN_LOGMACRO_H */
|
||||
113
contrib/idn/mdnkit/include/mdn/msgheader.h
Normal file
113
contrib/idn/mdnkit/include/mdn/msgheader.h
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
/* $Id: msgheader.h,v 1.7 2000/08/02 02:06:40 ishisone 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
#ifndef MDN_MSGHEADER_H
|
||||
#define MDN_MSGHEADER_H 1
|
||||
|
||||
/*
|
||||
* DNS message header parsing/construction.
|
||||
*/
|
||||
|
||||
#include <mdn/result.h>
|
||||
|
||||
/*
|
||||
* Parsed DNS message header.
|
||||
*/
|
||||
typedef struct mdn_msgheader {
|
||||
unsigned int id;
|
||||
int qr;
|
||||
int opcode;
|
||||
int flags;
|
||||
int rcode;
|
||||
unsigned int qdcount;
|
||||
unsigned int ancount;
|
||||
unsigned int nscount;
|
||||
unsigned int arcount;
|
||||
} mdn_msgheader_t;
|
||||
|
||||
/*
|
||||
* Parse DNS message header into mdn_msgheader_t type.
|
||||
*
|
||||
* Returns:
|
||||
* mdn_success -- ok.
|
||||
* mdn_invalid_message -- message is too short.
|
||||
*/
|
||||
extern mdn_result_t
|
||||
mdn_msgheader_parse(const char *msg, size_t msglen, mdn_msgheader_t *parsed);
|
||||
|
||||
/*
|
||||
* Pack mdn_msgheader_t data.
|
||||
*
|
||||
* Returns:
|
||||
* mdn_success -- ok.
|
||||
* mdn_buffer_overflow -- output buffer is too small.
|
||||
*/
|
||||
extern mdn_result_t
|
||||
mdn_msgheader_unparse(mdn_msgheader_t *parsed, char *msg, size_t msglen);
|
||||
|
||||
/*
|
||||
* Convenient functions.
|
||||
*
|
||||
* They do not check the length of the message. Caller must make sure
|
||||
* the message is not smaller than the header size (12 octets).
|
||||
*/
|
||||
extern unsigned int mdn_msgheader_getid(const char *msg);
|
||||
extern void mdn_msgheader_setid(char *msg, unsigned int id);
|
||||
|
||||
#endif /* MDN_MSGHEADER_H */
|
||||
130
contrib/idn/mdnkit/include/mdn/msgtrans.h
Normal file
130
contrib/idn/mdnkit/include/mdn/msgtrans.h
Normal file
|
|
@ -0,0 +1,130 @@
|
|||
/* $Id: msgtrans.h,v 1.11 2000/11/21 02:09:04 ishisone 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
#ifndef MDN_MSGTRANS_H
|
||||
#define MDN_MSGTRANS_H 1
|
||||
|
||||
/*
|
||||
* DNS message translator.
|
||||
*
|
||||
* Parse a DNS message, translate each domain name in it according
|
||||
* to a rule, and rebuild a message with the translated domain names.
|
||||
*/
|
||||
|
||||
#include <mdn/result.h>
|
||||
#include <mdn/converter.h>
|
||||
#include <mdn/normalizer.h>
|
||||
#include <mdn/zldrule.h>
|
||||
|
||||
/*
|
||||
* Translation parameters.
|
||||
*
|
||||
* 'use_local_rule' determines how local codeset and ZLD should be
|
||||
* derived.
|
||||
*
|
||||
* If 'use_local_rule' is true, 'local_rule' will be used for
|
||||
* determining ZLD/codeset. 'mdn_msgtrans_translate' will use
|
||||
* the rule to determine the ZLD and codeset, and set 'local_zld'
|
||||
* and 'local_converter' properly upon return.
|
||||
*
|
||||
* Otherwise, 'mdn_msgtrans_translate' will assume that specified
|
||||
* domain name is either
|
||||
* + the one having ZLD specified by 'local_zld' and codeset
|
||||
* specified by 'local_converter', or
|
||||
* + the one without ZLD and made of only legitimate characters
|
||||
* (alphabets, digits and hyphens), that is, a non-internationalized
|
||||
* domain name.
|
||||
*
|
||||
* If 'local_alt_converter' is not NULL, 'mdn_msgtrans_translate' tries
|
||||
* converting the specified domain name using it before attempting
|
||||
* 'local_conerter'.
|
||||
*
|
||||
* 'target_conveter' and 'target_zld' together define the ZLD/codeset
|
||||
* of the target. If 'target_alt_converter' is not NULL, then it is
|
||||
* used instead of 'target_converter' if the conversion from UTF-8 to
|
||||
* the target encoding fails with error 'mdn_nomapping'.
|
||||
*
|
||||
* 'normalizer' defines the normalization schemes.
|
||||
*/
|
||||
typedef struct mdn_msgtrans_param {
|
||||
int use_local_rule;
|
||||
mdn_zldrule_t local_rule;
|
||||
mdn_converter_t local_converter;
|
||||
mdn_converter_t local_alt_converter;
|
||||
char *local_zld;
|
||||
mdn_converter_t target_converter;
|
||||
mdn_converter_t target_alt_converter;
|
||||
char *target_zld;
|
||||
mdn_normalizer_t normalizer;
|
||||
} mdn_msgtrans_param_t;
|
||||
|
||||
/*
|
||||
* Translate DNS message according to the parameters given.
|
||||
*
|
||||
* Returns:
|
||||
* mdn_success -- ok, translated successfully.
|
||||
* mdn_invalid_message -- the specified message is not valid.
|
||||
* mdn_nomemory -- malloc failed.
|
||||
*/
|
||||
extern mdn_result_t
|
||||
mdn_msgtrans_translate(mdn_msgtrans_param_t *param,
|
||||
const char *msg, size_t msglen,
|
||||
char *outbuf, size_t outbufsize, size_t *outmsglenp);
|
||||
|
||||
#endif /* MDN_MSGTRANS_H */
|
||||
151
contrib/idn/mdnkit/include/mdn/normalizer.h
Normal file
151
contrib/idn/mdnkit/include/mdn/normalizer.h
Normal file
|
|
@ -0,0 +1,151 @@
|
|||
/* $Id: normalizer.h,v 1.11 2000/08/23 05:52:40 ishisone 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
#ifndef MDN_NORMALIZER_H
|
||||
#define MDN_NORMALIZER_H 1
|
||||
|
||||
/*
|
||||
* Domain name normalizer.
|
||||
*
|
||||
* Perform normalization on the specified strings. String must be
|
||||
* in UTF-8 encoding.
|
||||
*/
|
||||
|
||||
#include <mdn/result.h>
|
||||
|
||||
/*
|
||||
* Normalizer type (opaque).
|
||||
*/
|
||||
typedef struct mdn_normalizer *mdn_normalizer_t;
|
||||
|
||||
/*
|
||||
* Normalizer procedure type.
|
||||
*/
|
||||
typedef mdn_result_t (*mdn_normalizer_proc_t)(const char *from,
|
||||
char *to, size_t tolen);
|
||||
|
||||
/*
|
||||
* Initialize this module.
|
||||
*
|
||||
* Returns:
|
||||
* mdn_success -- ok.
|
||||
* mdn_nomemory -- malloc failed.
|
||||
*/
|
||||
extern mdn_result_t
|
||||
mdn_normalizer_initialize(void);
|
||||
|
||||
/*
|
||||
* Create a empty normalizer.
|
||||
*
|
||||
* Returns:
|
||||
* mdn_success -- ok.
|
||||
* mdn_nomemory -- malloc failed.
|
||||
*/
|
||||
extern mdn_result_t
|
||||
mdn_normalizer_create(mdn_normalizer_t *ctxp);
|
||||
|
||||
/*
|
||||
* Release all the memory allocated for a normalizer created by
|
||||
* 'mdn_normalizer_create'.
|
||||
*/
|
||||
extern void
|
||||
mdn_normalizer_destroy(mdn_normalizer_t ctx);
|
||||
|
||||
/*
|
||||
* Add a normalization scheme to a normalizer.
|
||||
*
|
||||
* Multiple shemes can be added to a normalizer, and they will be
|
||||
* applied in order.
|
||||
*
|
||||
* Returns:
|
||||
* mdn_success -- ok.
|
||||
* mdn_invalid_name -- unknown scheme was specified.
|
||||
* mdn_nomemory -- malloc failed.
|
||||
*/
|
||||
extern mdn_result_t
|
||||
mdn_normalizer_add(mdn_normalizer_t ctx, const char *scheme_name);
|
||||
|
||||
/*
|
||||
* Perform normalization(s) defined by a normalizer to the specified string,
|
||||
* If the normalizer has two or more normalization schemes, they are
|
||||
* applied in order.
|
||||
*
|
||||
* Returns:
|
||||
* mdn_success -- ok.
|
||||
* mdn_buffer_overflow -- output buffer is too small.
|
||||
* mdn_invalid_encoding -- input is not a valid UTF-8 string.
|
||||
* mdn_nomemory -- malloc failed.
|
||||
*/
|
||||
extern mdn_result_t
|
||||
mdn_normalizer_normalize(mdn_normalizer_t ctx, const char *from,
|
||||
char *to, size_t tolen);
|
||||
|
||||
/*
|
||||
* Register a new normalization scheme.
|
||||
*
|
||||
* You can override the default normalization schemes, if you want.
|
||||
*
|
||||
* Returns:
|
||||
* mdn_success -- ok.
|
||||
* mdn_nomemory -- malloc failed.
|
||||
*/
|
||||
extern mdn_result_t
|
||||
mdn_normalizer_register(const char *scheme_name, mdn_normalizer_proc_t proc);
|
||||
|
||||
#endif /* MDN_NORMALIZER_H */
|
||||
82
contrib/idn/mdnkit/include/mdn/race.h
Normal file
82
contrib/idn/mdnkit/include/mdn/race.h
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
/* $Id: race.h,v 1.8 2000/10/18 02:15:28 ishisone 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
#ifndef MDN_RACE_H
|
||||
#define MDN_RACE_H 1
|
||||
|
||||
/*
|
||||
* RACE Converter.
|
||||
*
|
||||
* See Internet Draft draft-ietf-idn-race-02.txt for details.
|
||||
*/
|
||||
|
||||
#include <mdn/result.h>
|
||||
#include <mdn/converter.h>
|
||||
|
||||
extern mdn_result_t
|
||||
mdn__race_open(mdn_converter_t ctx, mdn_converter_dir_t dir);
|
||||
|
||||
extern mdn_result_t
|
||||
mdn__race_close(mdn_converter_t ctx, mdn_converter_dir_t dir);
|
||||
|
||||
extern mdn_result_t
|
||||
mdn__race_convert(mdn_converter_t ctx, mdn_converter_dir_t dir,
|
||||
const char *from, char *to, size_t tolen);
|
||||
|
||||
#endif /* MDN_RACE_H */
|
||||
203
contrib/idn/mdnkit/include/mdn/res.h
Normal file
203
contrib/idn/mdnkit/include/mdn/res.h
Normal file
|
|
@ -0,0 +1,203 @@
|
|||
/* $Id: res.h,v 1.3 2000/08/23 06:56:58 ishisone 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
#ifndef MDN_RES_H
|
||||
#define MDN_RES_H 1
|
||||
|
||||
/*
|
||||
* Resolver library support.
|
||||
*
|
||||
* All the functions provided by this module requires MDN resolver
|
||||
* configuration context of type 'mdn_resconf_t' as an argument.
|
||||
* This context holds information described in the configuration file
|
||||
* (mdnres.conf). See mdn_resconf module for details.
|
||||
*
|
||||
* All functions also accept NULL as the context, but since
|
||||
* no conversion/normalization will be done in this case, it is
|
||||
* pretty useless.
|
||||
*/
|
||||
|
||||
#include <mdn/result.h>
|
||||
#include <mdn/resconf.h>
|
||||
|
||||
/*
|
||||
* Convert from the local codeset string to UCS (UTF-8).
|
||||
*
|
||||
* 'local_name' is a string containing a domain name encoded in the
|
||||
* local codeset or the encoding specified by 'alternate-encoding'
|
||||
* directive in the MDN configuration file (mdnres.conf).
|
||||
* This function converts it to UCS and stores in
|
||||
* the buffer 'ucs_name', which is 'ucs_name_len' bytes long.
|
||||
*
|
||||
* 'conf' is a MDN resolver configuration context created by
|
||||
* 'mdn_resconf_create()', or NULL. If it is NULL, no conversion is
|
||||
* performed, and the contents of 'local_name' are copied to 'ucs_name'
|
||||
* verbatim.
|
||||
*
|
||||
* Returns:
|
||||
* mdn_success -- ok.
|
||||
* mdn_buffer_overflow -- output buffer is too small.
|
||||
* mdn_invalid_encoding -- input string has invalid byte sequence.
|
||||
* mdn_invalid_name -- local encoding (codeset) name is invalid.
|
||||
* mdn_failure -- other failure.
|
||||
*/
|
||||
extern mdn_result_t
|
||||
mdn_res_localtoucs(mdn_resconf_t conf, const char *local_name,
|
||||
char *ucs_name, size_t ucs_name_len);
|
||||
|
||||
/*
|
||||
* Convert from UCS (UTF-8) string to the local codeset.
|
||||
*
|
||||
* 'ucs_name' is a string containing a domain name encoded in UTF-8.
|
||||
* This function converts it to the local codeset and stores in
|
||||
* the buffer 'local_name', which is 'local_name_len' bytes long.
|
||||
* If there are any characters which cannot be converted to the local
|
||||
* codeset, the 'alternate-encoding' is used instead of the local codeset.
|
||||
*
|
||||
* 'conf' is a MDN resolver configuration context created by
|
||||
* 'mdn_resconf_create()', or NULL. If it is NULL, no conversion is
|
||||
* performed, and the contents of 'local_name' are copied to 'ucs_name'
|
||||
* verbatim.
|
||||
*
|
||||
* Returns:
|
||||
* mdn_success -- ok.
|
||||
* mdn_buffer_overflow -- output buffer is too small.
|
||||
* mdn_invalid_encoding -- input string has invalid byte sequence.
|
||||
* mdn_invalid_name -- local encoding (codeset) name is invalid.
|
||||
* mdn_failure -- other failure.
|
||||
*/
|
||||
extern mdn_result_t
|
||||
mdn_res_ucstolocal(mdn_resconf_t conf, const char *ucs_name,
|
||||
char *local_name, size_t local_name_len);
|
||||
|
||||
/*
|
||||
* Normalize UCS string.
|
||||
*
|
||||
* Perform normalization/canonicalization specified by the configuration
|
||||
* context 'conf' on the UTF-8 encoded string 'name', and store the result
|
||||
* in 'normalized_name', whose size is 'normalized_name_len' bytes.
|
||||
*
|
||||
* 'conf' is a MDN resolver configuration context created by
|
||||
* 'mdn_resconf_create()', or NULL. If it is NULL, no normalization is
|
||||
* performed, and the contents of 'name' are copied to 'normalized_name'
|
||||
* verbatim.
|
||||
*
|
||||
* Returns:
|
||||
* mdn_success -- ok.
|
||||
* mdn_buffer_overflow -- output buffer is too small.
|
||||
* mdn_invalid_encoding -- input is not a valid UTF-8 string.
|
||||
* mdn_nomemory -- malloc failed.
|
||||
*/
|
||||
extern mdn_result_t
|
||||
mdn_res_normalize(mdn_resconf_t conf, const char *name,
|
||||
char *normalized_name, size_t normalized_name_len);
|
||||
|
||||
/*
|
||||
* Convert from UCS (UTF-8) string to the encoding used in DNS protocol.
|
||||
*
|
||||
* 'ucs_name' is a string containing a domain name encoded in UTF-8.
|
||||
* This function converts it to the encoding used in DNS protocol data
|
||||
* (such as RACE), and stores in the buffer 'dns_name', which is
|
||||
* 'dns_name_len' bytes long. Also if ZLD is specified in the configuration
|
||||
* file, it is appended to the conversion result.
|
||||
*
|
||||
* Both the encoding used in DNS protocol and ZLD are specified by 'conf'
|
||||
* which is a MDN resolver configuration context. If 'conf' is NULL,
|
||||
* then no conversion is done.
|
||||
*
|
||||
* Requires:
|
||||
* 'ucs_name' must be a FQDN. Otherwise the conversion result might
|
||||
* not be correct for some DNS protocol encoding (namely UTF-5).
|
||||
*
|
||||
* Returns:
|
||||
* mdn_success -- ok.
|
||||
* mdn_buffer_overflow -- output buffer is too small.
|
||||
* mdn_invalid_encoding -- input string has invalid byte sequence.
|
||||
* mdn_invalid_name -- local encoding (codeset) name is invalid.
|
||||
* mdn_failure -- other failure.
|
||||
*/
|
||||
extern mdn_result_t
|
||||
mdn_res_ucstodns(mdn_resconf_t conf, const char *ucs_name, char *dns_name,
|
||||
size_t dns_name_len);
|
||||
|
||||
/*
|
||||
* Convert from the DNS protocol encoding to UCS (UTF-8).
|
||||
*
|
||||
* This function converts 'dns_name' whose encoding is the encoding
|
||||
* used in DNS protocol data into UTF-8, and stores the result in the
|
||||
* buffer 'ucs_name', which is 'ucs_name_len' bytes long. Also, if
|
||||
* 'dns_name' has ZLD specified by 'conf', the ZLD part is removed
|
||||
* from 'dns_name' before the conversion.
|
||||
*
|
||||
* Both the encoding used in DNS protocol and ZLD are specified by 'conf'
|
||||
* which is a MDN resolver configuration context. If 'conf' is NULL,
|
||||
* then no conversion is done.
|
||||
*
|
||||
* Returns:
|
||||
* mdn_success -- ok.
|
||||
* mdn_buffer_overflow -- output buffer is too small.
|
||||
* mdn_invalid_encoding -- input string has invalid byte sequence.
|
||||
* mdn_invalid_name -- local encoding (codeset) name is invalid.
|
||||
* mdn_failure -- other failure.
|
||||
*/
|
||||
extern mdn_result_t
|
||||
mdn_res_dnstoucs(mdn_resconf_t conf, const char *dns_name, char *ucs_name,
|
||||
size_t ucs_name_len);
|
||||
|
||||
#endif
|
||||
173
contrib/idn/mdnkit/include/mdn/resconf.h
Normal file
173
contrib/idn/mdnkit/include/mdn/resconf.h
Normal file
|
|
@ -0,0 +1,173 @@
|
|||
/* $Id: resconf.h,v 1.4 2000/08/23 05:53:23 ishisone 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
#ifndef MDN_RESCONF_H
|
||||
#define MDN_RESCONF_H 1
|
||||
|
||||
/*
|
||||
* MDN resolver configuration.
|
||||
*/
|
||||
|
||||
#include <mdn/result.h>
|
||||
#include <mdn/converter.h>
|
||||
#include <mdn/normalizer.h>
|
||||
|
||||
/*
|
||||
* Configuration type (opaque).
|
||||
*/
|
||||
typedef struct mdn_resconf *mdn_resconf_t;
|
||||
|
||||
/*
|
||||
* Initialize.
|
||||
*
|
||||
* Initialize this module and underlying ones. Must be called before
|
||||
* any other functions of this module.
|
||||
*
|
||||
* Returns:
|
||||
* mdn_success -- ok.
|
||||
* mdn_nomemory -- malloc failed.
|
||||
*/
|
||||
extern mdn_result_t
|
||||
mdn_resconf_initialize(void);
|
||||
|
||||
/*
|
||||
* Create a configuration context.
|
||||
*
|
||||
* Create an empty context and store it in '*ctxp'.
|
||||
*
|
||||
* Returns:
|
||||
* mdn_success -- ok.
|
||||
* mdn_nomemory -- malloc failed.
|
||||
*/
|
||||
extern mdn_result_t
|
||||
mdn_resconf_create(mdn_resconf_t *ctxp);
|
||||
|
||||
/*
|
||||
* Destroy the configuration context.
|
||||
*
|
||||
* Destroy the configuration context created by 'mdn_resconf_create',
|
||||
* and release memory for it.
|
||||
*/
|
||||
extern void
|
||||
mdn_resconf_destroy(mdn_resconf_t ctx);
|
||||
|
||||
/*
|
||||
* Load configuration file.
|
||||
*
|
||||
* Parse an MDN configuration file whose name is specified by 'file',
|
||||
* store the result in 'ctx'. If 'file' is NULL, the default file is
|
||||
* loaded.
|
||||
*
|
||||
* Returns:
|
||||
* mdn_success -- ok.
|
||||
* mdn_nofile -- couldn't open specified file.
|
||||
* mdn_invalid_syntax -- syntax error found.
|
||||
* mdn_invalid_name -- invalid encoding/nomalization name is
|
||||
* specified.
|
||||
* mdn_nomemory -- malloc failed.
|
||||
*/
|
||||
extern mdn_result_t
|
||||
mdn_resconf_loadfile(mdn_resconf_t ctx, const char *file);
|
||||
|
||||
/*
|
||||
* Get the pathname of the default configuration file.
|
||||
*
|
||||
* Returns:
|
||||
* the pathname of the default MDN configuration file.
|
||||
*/
|
||||
extern char *
|
||||
mdn_resconf_defaultfile(void);
|
||||
|
||||
/*
|
||||
* Get codeset converters.
|
||||
*
|
||||
* + for local encoding,
|
||||
* + for DNS protocol encoding,
|
||||
* + for alternate encoding (which is used when the string to be converterd
|
||||
* to the local encoding has some characters having no mapping to the
|
||||
* local encoding)
|
||||
* In case of error, NULL will be returned.
|
||||
*/
|
||||
|
||||
extern mdn_converter_t
|
||||
mdn_resconf_localconverter(mdn_resconf_t ctx);
|
||||
|
||||
extern mdn_converter_t
|
||||
mdn_resconf_serverconverter(mdn_resconf_t ctx);
|
||||
|
||||
extern mdn_converter_t
|
||||
mdn_resconf_alternateconverter(mdn_resconf_t ctx);
|
||||
|
||||
/*
|
||||
* Get Zero-Level-Domain name.
|
||||
*
|
||||
* If there's no ZLD, NULL will be returned.
|
||||
*/
|
||||
extern const char *
|
||||
mdn_resconf_zld(mdn_resconf_t ctx);
|
||||
|
||||
/*
|
||||
* Get domain name normalizer.
|
||||
*
|
||||
* In case of error, NULL will be returned.
|
||||
*/
|
||||
extern mdn_normalizer_t
|
||||
mdn_resconf_normalizer(mdn_resconf_t ctx);
|
||||
|
||||
#endif
|
||||
88
contrib/idn/mdnkit/include/mdn/result.h
Normal file
88
contrib/idn/mdnkit/include/mdn/result.h
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
/* $Id: result.h,v 1.10 2000/09/27 02:55:37 ishisone 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
#ifndef MDN_RESULT_H
|
||||
#define MDN_RESULT_H 1
|
||||
|
||||
/*
|
||||
* MDN library result code.
|
||||
*/
|
||||
typedef enum {
|
||||
mdn_success,
|
||||
mdn_notfound,
|
||||
mdn_invalid_encoding,
|
||||
mdn_invalid_syntax,
|
||||
mdn_invalid_name,
|
||||
mdn_invalid_message,
|
||||
mdn_buffer_overflow,
|
||||
mdn_noentry,
|
||||
mdn_nomemory,
|
||||
mdn_nofile,
|
||||
mdn_nomapping,
|
||||
mdn_context_required,
|
||||
mdn_failure /* !!This must be the last one!! */
|
||||
} mdn_result_t;
|
||||
|
||||
/*
|
||||
* Get the string description of a result code.
|
||||
*/
|
||||
extern char *
|
||||
mdn_result_tostring(mdn_result_t result);
|
||||
|
||||
#endif /* MDN_RESULT_H */
|
||||
85
contrib/idn/mdnkit/include/mdn/selectiveencode.h
Normal file
85
contrib/idn/mdnkit/include/mdn/selectiveencode.h
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
/* $Id: selectiveencode.h,v 1.8 2000/08/02 02:06:40 ishisone 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
#ifndef MDN_SELECTIVENCODE_H
|
||||
#define MDN_SELECTIVENCODE_H 1
|
||||
|
||||
/*
|
||||
* Find where to convert.
|
||||
*
|
||||
* Find a substring for which MDN domain name codeset conversion is necessary.
|
||||
*/
|
||||
|
||||
#include <mdn/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:
|
||||
* mdn_success -- ok, found.
|
||||
* mdn_notfound -- not found.
|
||||
*/
|
||||
extern mdn_result_t
|
||||
mdn_selectiveencode_findregion(const char *s, char **startp, char **endp);
|
||||
|
||||
#endif /* MDN_SELECTIVENCODE_H */
|
||||
131
contrib/idn/mdnkit/include/mdn/strhash.h
Normal file
131
contrib/idn/mdnkit/include/mdn/strhash.h
Normal file
|
|
@ -0,0 +1,131 @@
|
|||
/* $Id: strhash.h,v 1.9 2000/08/02 02:06:40 ishisone 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
#ifndef MDN_STRHASH_H
|
||||
#define MDN_STRHASH_H 1
|
||||
|
||||
/*
|
||||
* String-keyed hash table
|
||||
*
|
||||
* Just a hash table. Nothing special. Number of hash buckets
|
||||
* grows automatically.
|
||||
*/
|
||||
|
||||
#include <mdn/result.h>
|
||||
|
||||
/*
|
||||
* Hash table type, which is opaque.
|
||||
*/
|
||||
typedef struct mdn_strhash *mdn_strhash_t;
|
||||
|
||||
/*
|
||||
* Hash value free proc.
|
||||
*/
|
||||
typedef void (*mdn_strhash_freeproc_t)(void *value);
|
||||
|
||||
/*
|
||||
* Create a hash table.
|
||||
*
|
||||
* Returns:
|
||||
* mdn_success -- ok.
|
||||
* mdn_nomemory -- malloc failed.
|
||||
*/
|
||||
extern mdn_result_t
|
||||
mdn_strhash_create(mdn_strhash_t *hashp);
|
||||
|
||||
/*
|
||||
* Delete a hash table created by 'mdn_strhash_create'.
|
||||
* If 'proc' is not NULL, it is called for each value in the
|
||||
* hash to release memory for them.
|
||||
*/
|
||||
extern void
|
||||
mdn_strhash_destroy(mdn_strhash_t hash, mdn_strhash_freeproc_t proc);
|
||||
|
||||
/*
|
||||
* Register an item to the hash table. This function makes a
|
||||
* private copy of the key string.
|
||||
*
|
||||
* Returns:
|
||||
* mdn_success -- ok.
|
||||
* mdn_nomemory -- malloc failed.
|
||||
*/
|
||||
extern mdn_result_t
|
||||
mdn_strhash_put(mdn_strhash_t hash, const char *key, void *value);
|
||||
|
||||
/*
|
||||
* Find an item with the specified key.
|
||||
*
|
||||
* Returns:
|
||||
* mdn_success -- ok. found.
|
||||
* mdn_noentry -- not found.
|
||||
*/
|
||||
extern mdn_result_t
|
||||
mdn_strhash_get(mdn_strhash_t hash, const char *key, void **valuep);
|
||||
|
||||
/*
|
||||
* Check if an item with the specified key exists.
|
||||
*
|
||||
* Returns:
|
||||
* 1 -- yes.
|
||||
* 0 -- no.
|
||||
*/
|
||||
extern int
|
||||
mdn_strhash_exists(mdn_strhash_t hash, const char *key);
|
||||
|
||||
#endif /* MDN_STRHASH_H */
|
||||
127
contrib/idn/mdnkit/include/mdn/translator.h
Normal file
127
contrib/idn/mdnkit/include/mdn/translator.h
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
/* $Id: translator.h,v 1.10 2000/11/21 02:09:04 ishisone 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
#ifndef MDN_TRANSLATOR_H
|
||||
#define MDN_TRANSLATOR_H 1
|
||||
|
||||
/*
|
||||
* Domain name ZLD/codeset translator.
|
||||
*/
|
||||
|
||||
#include <mdn/result.h>
|
||||
#include <mdn/converter.h>
|
||||
#include <mdn/normalizer.h>
|
||||
|
||||
/*
|
||||
* Translate domain name encoded in the local codeset to the target
|
||||
* codeset.
|
||||
*
|
||||
* Requires:
|
||||
* Both 'local_zld' and 'target_zld' must be canonicalized (or NULL)
|
||||
* using mdn_translator_canonicalzld.
|
||||
*
|
||||
* Returns:
|
||||
* mdn_success -- ok.
|
||||
* mdn_nomemory -- malloc failed.
|
||||
* mdn_buffer_overflow -- output buffer too small.
|
||||
* mdn_invalid_encoding -- there are some invalid characters in
|
||||
* the specified domain name.
|
||||
*/
|
||||
extern mdn_result_t
|
||||
mdn_translator_translate(mdn_converter_t local_converter,
|
||||
mdn_converter_t local_alternate_converter,
|
||||
const char *local_zld,
|
||||
mdn_normalizer_t normalizer,
|
||||
mdn_converter_t target_converter,
|
||||
mdn_converter_t target_alternate_converter,
|
||||
const char *target_zld,
|
||||
const char *from, char *to, size_t tolen);
|
||||
|
||||
/*
|
||||
* Canonicalize ZLD.
|
||||
*
|
||||
* Note:
|
||||
* The string returned in *canonicalizedp is malloc'ed by this
|
||||
* function. You should free it when no longer needed.
|
||||
*
|
||||
* If specified ZLD is "" or ".", NULL will be returned in
|
||||
* *canonicalizedp.
|
||||
*
|
||||
* Returns:
|
||||
* mdn_success -- ok.
|
||||
* mdn_nomemory -- malloc failed.
|
||||
*/
|
||||
extern mdn_result_t
|
||||
mdn_translator_canonicalzld(const char *zld, char **canonicalizedp);
|
||||
|
||||
/*
|
||||
* Try matching ZLD against domain name.
|
||||
*
|
||||
* Requires:
|
||||
* 'zld' must be canonicalized (or NULL) using
|
||||
* mdn_translator_canonicalzld.
|
||||
*
|
||||
* Returns:
|
||||
* 1 -- match.
|
||||
* 0 -- no match.
|
||||
*/
|
||||
extern int
|
||||
mdn_translator_matchzld(const char *domain, const char *zld);
|
||||
|
||||
#endif /* MDN_TRANSLATOR_H */
|
||||
193
contrib/idn/mdnkit/include/mdn/unicode.h
Normal file
193
contrib/idn/mdnkit/include/mdn/unicode.h
Normal file
|
|
@ -0,0 +1,193 @@
|
|||
/* $Id: unicode.h,v 1.9 2000/09/27 02:55:37 ishisone 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
#ifndef MDN_UNICODE_H
|
||||
#define MDN_UNICODE_H 1
|
||||
|
||||
/*
|
||||
* Unicode attributes retriever.
|
||||
*
|
||||
* All the information this module provides is based on UnicodeData.txt,
|
||||
* CompositionExclusions-1.txt and SpecialCasing.txt, all of which can be
|
||||
* obtained from unicode.org.
|
||||
*
|
||||
* Unicode characters are represented as 'unsigned long'.
|
||||
*/
|
||||
|
||||
#include <mdn/result.h>
|
||||
|
||||
/*
|
||||
* Context information for case conversion.
|
||||
*/
|
||||
typedef enum {
|
||||
mdn__unicode_context_unknown,
|
||||
mdn__unicode_context_final,
|
||||
mdn__unicode_context_nonfinal
|
||||
} mdn__unicode_context_t;
|
||||
|
||||
/*
|
||||
* Get canonical class.
|
||||
*
|
||||
* For characters out of unicode range (i.e. above 0xffff), 0 will
|
||||
* be returned.
|
||||
*/
|
||||
extern int
|
||||
mdn__unicode_canonicalclass(unsigned long c);
|
||||
|
||||
/*
|
||||
* Decompose a character.
|
||||
*
|
||||
* Decompose character given by 'c', and put the result into 'v',
|
||||
* which can hold 'vlen' characters. The number of decomposed characters
|
||||
* will be stored in '*decomp_lenp'.
|
||||
*
|
||||
* If 'compat' is true, compatibility decomposition is performed.
|
||||
* Otherwise canonical decomposition is done.
|
||||
*
|
||||
* Since decomposition is done recursively, no further decomposition
|
||||
* will be needed.
|
||||
*
|
||||
* Returns:
|
||||
* mdn_success -- ok, decomposed.
|
||||
* mdn_notfound -- no decomposition possible.
|
||||
* mdn_buffer_overflow -- 'vlen' is too small.
|
||||
*/
|
||||
extern mdn_result_t
|
||||
mdn__unicode_decompose(int compat, unsigned long *v, size_t vlen,
|
||||
unsigned long c, int *decomp_lenp);
|
||||
|
||||
/*
|
||||
* Perform canonical composition.
|
||||
*
|
||||
* Do canonical composition to the character sequence 'c1' and 'c2', put the
|
||||
* result into '*compp'.
|
||||
*
|
||||
* Since Unicode Nomalization Froms requires only canonical composition,
|
||||
* compatibility composition is not supported.
|
||||
*
|
||||
* Returns:
|
||||
* mdn_success -- ok, composed.
|
||||
* mdn_notfound -- no composition possible.
|
||||
*/
|
||||
extern mdn_result_t
|
||||
mdn__unicode_compose(unsigned long c1, unsigned long c2, unsigned long *compp);
|
||||
|
||||
/*
|
||||
* Returns if there may be a canonical composition sequence which starts
|
||||
* with the given character.
|
||||
*
|
||||
* Returns:
|
||||
* 1 -- there may be a composition sequence
|
||||
* (maybe not).
|
||||
* 0 -- no, there is definitely no such sequences.
|
||||
*/
|
||||
extern int
|
||||
mdn__unicode_iscompositecandidate(unsigned long c);
|
||||
|
||||
/*
|
||||
* Translate lowercase character to uppercase, and vice versa, according
|
||||
* to Unicode Technical Report #21 "Case Mappings".
|
||||
*
|
||||
* Both functions perform conversion on the given unicode character 'c',
|
||||
* put the result into 'v', whose size is specified by 'vlen'. The actual
|
||||
* number of characters stored in 'v' are returned as '*convlenp'.
|
||||
* In case 'c' has no mapping, 'v[0]' will contain 'c', and '*convlenp'
|
||||
* will be 1.
|
||||
*
|
||||
* Note that these functions perform locale-independent case conversion.
|
||||
*
|
||||
* There are some characters whose case mapping depends on the context.
|
||||
* 'ctx' specifies the context, which can be obtained by
|
||||
* 'mdn__unicode_getcontext'. Most of the time you can just specify
|
||||
* 'mdn__unicode_context_unknown' as 'ctx', and if those functions
|
||||
* return 'mdn_context_required', you can get the context using
|
||||
* 'mdn__unicode_getcontext' and try again.
|
||||
*
|
||||
* Returns:
|
||||
* mdn_success -- successfully converted.
|
||||
* mdn_context_required -- context information is needed to
|
||||
* perform case conversion on 'c'.
|
||||
* mdn_buffer_overflow -- 'vlen' is too small.
|
||||
*/
|
||||
extern mdn_result_t
|
||||
mdn__unicode_toupper(unsigned long c, mdn__unicode_context_t ctx,
|
||||
unsigned long *v, size_t vlen, int *convlenp);
|
||||
extern mdn_result_t
|
||||
mdn__unicode_tolower(unsigned long c, mdn__unicode_context_t ctx,
|
||||
unsigned long *v, size_t vlen, int *convlenp);
|
||||
|
||||
/*
|
||||
* Determine the context needed by the case conversion functions.
|
||||
*
|
||||
* Case conversion functions above needs context information for some
|
||||
* characters. To get the context, you should call this function with
|
||||
* the next character as the parameter. If you get final or nonfinal,
|
||||
* you're done. If you get unknown, move on to the next character until
|
||||
* you get final or nonfinal.
|
||||
*
|
||||
* Returns:
|
||||
* mdn__unicode_context_final -- context is 'FINAL'.
|
||||
* mdn__unicode_context_nonfinal -- context is 'NON_FINAL'.
|
||||
* mdn__unicode_context_unknown -- context cannot be determined,
|
||||
* try the next character.
|
||||
*/
|
||||
extern mdn__unicode_context_t
|
||||
mdn__unicode_getcontext(unsigned long c);
|
||||
|
||||
#endif
|
||||
100
contrib/idn/mdnkit/include/mdn/unormalize.h
Normal file
100
contrib/idn/mdnkit/include/mdn/unormalize.h
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
/* $Id: unormalize.h,v 1.9 2000/08/02 02:06:41 ishisone 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
#ifndef MDN_UNORMALIZE_H
|
||||
#define MDN_UNORMALIZE_H 1
|
||||
|
||||
/*
|
||||
* Unicode Normalizations.
|
||||
*
|
||||
* Perform 4 normalizations defined by 'Unicode Normalization Forms'
|
||||
* (http://www.unicode.org/unicode/reports/tr15)
|
||||
*
|
||||
* All of the functions use UTF-8 encoding for input/output.
|
||||
*/
|
||||
|
||||
#include <mdn/result.h>
|
||||
|
||||
/*
|
||||
* Perform Unicode Normalication Form C, D, KC and KD.
|
||||
*
|
||||
* They take NUL-terminated UTF-8 encoded string 'from', perform
|
||||
* the normalization, put the result (also a NUL-terminated UTF-8
|
||||
* encoded string) to 'to', which must be able to hold at least
|
||||
* 'tolen' bytes.
|
||||
*
|
||||
* Returns:
|
||||
* mdn_success -- ok.
|
||||
* mdn_nomemory -- malloc failed.
|
||||
* mdn_invalid_encoding -- input text is not a valid UTF-8 string.
|
||||
* mdn_buffer_overflow -- 'tolen' is too small.
|
||||
*/
|
||||
extern mdn_result_t
|
||||
mdn__unormalize_formc(const char *from, char *to, size_t tolen);
|
||||
|
||||
extern mdn_result_t
|
||||
mdn__unormalize_formd(const char *from, char *to, size_t tolen);
|
||||
|
||||
extern mdn_result_t
|
||||
mdn__unormalize_formkc(const char *from, char *to, size_t tolen);
|
||||
|
||||
extern mdn_result_t
|
||||
mdn__unormalize_formkd(const char *from, char *to, size_t tolen);
|
||||
|
||||
#endif /* MDN_UNORMALIZE_H */
|
||||
96
contrib/idn/mdnkit/include/mdn/utf5.h
Normal file
96
contrib/idn/mdnkit/include/mdn/utf5.h
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
/* $Id: utf5.h,v 1.7 2000/07/04 03:52:33 ishisone 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
#ifndef MDN_UTF5_H
|
||||
#define MDN_UTF5_H 1
|
||||
|
||||
/*
|
||||
* UTF-5 encoded string facility.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Get one character.
|
||||
*
|
||||
* Get the first character of the UTF-5 string pointed by 's', translate
|
||||
* it into UCS-4 (an unsigned log value), and store it to '*vp'.
|
||||
*
|
||||
* It returns the number of bytes read, or zero if the encoding is invalid.
|
||||
*
|
||||
* This routine treats period (".") specially, that is, "." is recognized
|
||||
* as a valid UTF-5 sequence which translated into itself. This is very
|
||||
* convenient when converting domain names, but you should note that
|
||||
* "." is NOT a valid byte in UTF-5 encoded sequece.
|
||||
*/
|
||||
extern int
|
||||
mdn_utf5_getwc(const char *s, size_t len, unsigned long *vp);
|
||||
|
||||
/*
|
||||
* Put one character.
|
||||
*
|
||||
* This function is an opposite of 'mdn_utf8_getwc'. It takes a UCS-4
|
||||
* value 'v', convert it to UTF-5 encoded sequence, and store it to 's',
|
||||
* whose length is 'len'. It returns the number of bytes written, or
|
||||
* zero 'v' is out of range or 'len' is too small.
|
||||
*
|
||||
* The above note regarding "." also applies to this function.
|
||||
*/
|
||||
extern int
|
||||
mdn_utf5_putwc(char *s, size_t len, unsigned long v);
|
||||
|
||||
#endif /* MDN_UTF5_H */
|
||||
143
contrib/idn/mdnkit/include/mdn/utf8.h
Normal file
143
contrib/idn/mdnkit/include/mdn/utf8.h
Normal file
|
|
@ -0,0 +1,143 @@
|
|||
/* $Id: utf8.h,v 1.8 2000/08/14 07:26:59 ishisone 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
#ifndef MDN_UTF8_H
|
||||
#define MDN_UTF8_H 1
|
||||
|
||||
/*
|
||||
* UTF-8 encoded string facility.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Get the length of a character.
|
||||
*
|
||||
* Get the length (in bytes) of a character whose first byte is pointed
|
||||
* by 's'. Since this function only looks one first byte to determine the
|
||||
* length, it is possible some of the following bytes are invalid.
|
||||
*/
|
||||
extern int
|
||||
mdn_utf8_mblen(const char *s);
|
||||
|
||||
/*
|
||||
* Get one character.
|
||||
*
|
||||
* Get the first character of the string pointed by 's', and copy it
|
||||
* to 'buf', whose length is 'len'. Returns the number of bytes copied,
|
||||
* or zero if the encoding is invalid or len is too small.
|
||||
*
|
||||
* The area pointed by 'buf' must be large enough to store any UTF-8 encoded
|
||||
* character.
|
||||
*
|
||||
* Note that the copied string is not NUL-terminated.
|
||||
*/
|
||||
extern int
|
||||
mdn_utf8_getmb(const char *s, size_t len, char *buf);
|
||||
|
||||
/*
|
||||
* Get one character in UCS-4.
|
||||
*
|
||||
* Similar to 'mdn_utf8_getmb', except that the result is not in UTF-8
|
||||
* encoding, but in UCS-4 format (plain 32bit integer value).
|
||||
*/
|
||||
extern int
|
||||
mdn_utf8_getwc(const char *s, size_t len, unsigned long *vp);
|
||||
|
||||
/*
|
||||
* Put one character.
|
||||
*
|
||||
* This function is an opposite of 'mdn_utf8_getwc'. It takes a UCS-4
|
||||
* value 'v', convert it to UTF-8 encoded sequence, and store it to 's',
|
||||
* whose length is 'len'. It returns the number of bytes written, or
|
||||
* zero 'v' is out of range or 'len' is too small.
|
||||
*/
|
||||
extern int
|
||||
mdn_utf8_putwc(char *s, size_t len, unsigned long v);
|
||||
|
||||
/*
|
||||
* Check the validity of UTF-8 encoded character.
|
||||
*
|
||||
* Check if the character pointed by 's' is a valid UTF-8 encoded
|
||||
* character. Return the length of the character (in bytes) if it is valid,
|
||||
* 0 otherwise.
|
||||
*/
|
||||
extern int
|
||||
mdn_utf8_isvalidchar(const char *s);
|
||||
|
||||
/*
|
||||
* Check the validity of UTF-8 encoded string.
|
||||
*
|
||||
* Check if the NUL-terminated string 's' is valid as a UTF-8 encoded
|
||||
* string. Return 1 if it is valid, 0 otherwise.
|
||||
*/
|
||||
extern int
|
||||
mdn_utf8_isvalidstring(const char *s);
|
||||
|
||||
/*
|
||||
* Find first byte of a character.
|
||||
*
|
||||
* Find the first byte of a character 's' points to. 's' may point
|
||||
* the 2nd or later byte of a character. 'known_top' is a pointer to
|
||||
* a string which contains 's', and is known to be the first byte of
|
||||
* a character. If it couldn't find the first byte between 'known_top'
|
||||
* and 's', NULL will be returned.
|
||||
*/
|
||||
extern char *
|
||||
mdn_utf8_findfirstbyte(const char *s, const char *known_top);
|
||||
|
||||
#endif /* MDN_UTF8_H */
|
||||
101
contrib/idn/mdnkit/include/mdn/util.h
Normal file
101
contrib/idn/mdnkit/include/mdn/util.h
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
/* $Id: util.h,v 1.2 2000/11/14 00:15:35 ishisone 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
#ifndef MDN_UTIL_H
|
||||
#define MDN_UTIL_H 1
|
||||
|
||||
/*
|
||||
* Utility functions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Case-insensitive string match.
|
||||
*
|
||||
* This function compares two strings in case-insensitive way, like
|
||||
* strcasencmp() function which can be found in many systems.
|
||||
* However, this function only disregards the case difference of ASCII
|
||||
* letters ([A-Za-z]), so it is locale independent.
|
||||
* The result is 1 if 's1' and 's2' match, 0 otherwise.
|
||||
*/
|
||||
extern int
|
||||
mdn_util_casematch(const char *s1, const char *s2, size_t n);
|
||||
|
||||
/*
|
||||
* Get a range of valid domain name characters.
|
||||
*
|
||||
* This function sees each character in string 's' until 'end',
|
||||
* and checks if it is valid as a character in ASCII domain names.
|
||||
* It returns a pointer to the first invalid character, or 'end'
|
||||
* if all characters are valid.
|
||||
*/
|
||||
extern const char *
|
||||
mdn_util_domainspan(const char *s, const char *end);
|
||||
|
||||
/*
|
||||
* UTF-8 to UTF-16 conversion and vice versa.
|
||||
*/
|
||||
extern mdn_result_t
|
||||
mdn_util_utf8toutf16(const char *utf8, size_t fromlen,
|
||||
unsigned short *utf16, size_t tolen, size_t *reslenp);
|
||||
|
||||
extern mdn_result_t
|
||||
mdn_util_utf16toutf8(const unsigned short *utf16, size_t fromlen,
|
||||
char *utf8, size_t tolen, size_t *reslenp);
|
||||
|
||||
#endif /* MDN_UTIL_H */
|
||||
128
contrib/idn/mdnkit/include/mdn/zldrule.h
Normal file
128
contrib/idn/mdnkit/include/mdn/zldrule.h
Normal file
|
|
@ -0,0 +1,128 @@
|
|||
/* $Id: zldrule.h,v 1.8 2000/08/02 02:06:41 ishisone 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
#ifndef MDN_ZLDRULE_H
|
||||
#define MDN_ZLDRULE_H 1
|
||||
|
||||
/*
|
||||
* ZLD matcher.
|
||||
*
|
||||
* This module provides a function that takes a domain name as input,
|
||||
* and matches against set of ZLDs.
|
||||
*
|
||||
* Each ZLD has its corresponding codeset (character encoding), or codesets
|
||||
* in which a domain name with the ZLD is encoded.
|
||||
*
|
||||
* The function returns the matched ZLD and the corresponding codeset.
|
||||
*
|
||||
* If a name matches more than one ZLDs, the longer one takes precedence.
|
||||
*
|
||||
* If matched ZLD has more than one codesets, each codeset is applied to
|
||||
* the given domain name in order, and the first one for which the name
|
||||
* is valid is chosen.
|
||||
*/
|
||||
|
||||
#include <mdn/result.h>
|
||||
#include <mdn/converter.h>
|
||||
|
||||
/*
|
||||
* ZLD matching rule set type (opaque)
|
||||
*/
|
||||
typedef struct mdn_zldrule *mdn_zldrule_t;
|
||||
|
||||
/*
|
||||
* Create an empty rule set.
|
||||
*
|
||||
* Returns:
|
||||
* mdn_success -- ok.
|
||||
* mdn_nomemory -- malloc failed.
|
||||
*/
|
||||
extern mdn_result_t
|
||||
mdn_zldrule_create(mdn_zldrule_t *ctxp);
|
||||
|
||||
/*
|
||||
* Destroy the rule set created by mdn_zldrule_create.
|
||||
*/
|
||||
extern void
|
||||
mdn_zldrule_destroy(mdn_zldrule_t ctx);
|
||||
|
||||
/*
|
||||
* Add a ZLD and corresponding encoding(s) to the rule set.
|
||||
*
|
||||
* Returns:
|
||||
* mdn_success -- ok.
|
||||
* mdn_nomemory -- malloc failed.
|
||||
*/
|
||||
extern mdn_result_t
|
||||
mdn_zldrule_add(mdn_zldrule_t ctx, const char *zld,
|
||||
const char **encodings, int nencodings);
|
||||
|
||||
/*
|
||||
* Select matching ZLD and encoding for the specified domain name.
|
||||
*
|
||||
* Returns:
|
||||
* mdn_success -- found.
|
||||
* mdn_notfound -- not found.
|
||||
* mdn_invalid_encoding -- ZLD matched, but encoding is wrong.
|
||||
*/
|
||||
extern mdn_result_t
|
||||
mdn_zldrule_select(mdn_zldrule_t ctx, const char *domain,
|
||||
char **zldp, mdn_converter_t *convctxp);
|
||||
|
||||
#endif /* MDN_ZLDRULE_H */
|
||||
250
contrib/idn/mdnkit/install-sh
Normal file
250
contrib/idn/mdnkit/install-sh
Normal file
|
|
@ -0,0 +1,250 @@
|
|||
#! /bin/sh
|
||||
#
|
||||
# install - install a program, script, or datafile
|
||||
# This comes from X11R5 (mit/util/scripts/install.sh).
|
||||
#
|
||||
# Copyright 1991 by the Massachusetts Institute of Technology
|
||||
#
|
||||
# Permission to use, copy, modify, distribute, and sell this software and its
|
||||
# documentation for any purpose is hereby granted without fee, provided that
|
||||
# the above copyright notice appear in all copies and that both that
|
||||
# copyright notice and this permission notice appear in supporting
|
||||
# documentation, and that the name of M.I.T. not be used in advertising or
|
||||
# publicity pertaining to distribution of the software without specific,
|
||||
# written prior permission. M.I.T. makes no representations about the
|
||||
# suitability of this software for any purpose. It is provided "as is"
|
||||
# without express or implied warranty.
|
||||
#
|
||||
# Calling this script install-sh is preferred over install.sh, to prevent
|
||||
# `make' implicit rules from creating a file called install from it
|
||||
# when there is no Makefile.
|
||||
#
|
||||
# This script is compatible with the BSD install script, but was written
|
||||
# from scratch. It can only install one file at a time, a restriction
|
||||
# shared with many OS's install programs.
|
||||
|
||||
|
||||
# set DOITPROG to echo to test this script
|
||||
|
||||
# Don't use :- since 4.3BSD and earlier shells don't like it.
|
||||
doit="${DOITPROG-}"
|
||||
|
||||
|
||||
# put in absolute paths if you don't have them in your path; or use env. vars.
|
||||
|
||||
mvprog="${MVPROG-mv}"
|
||||
cpprog="${CPPROG-cp}"
|
||||
chmodprog="${CHMODPROG-chmod}"
|
||||
chownprog="${CHOWNPROG-chown}"
|
||||
chgrpprog="${CHGRPPROG-chgrp}"
|
||||
stripprog="${STRIPPROG-strip}"
|
||||
rmprog="${RMPROG-rm}"
|
||||
mkdirprog="${MKDIRPROG-mkdir}"
|
||||
|
||||
transformbasename=""
|
||||
transform_arg=""
|
||||
instcmd="$mvprog"
|
||||
chmodcmd="$chmodprog 0755"
|
||||
chowncmd=""
|
||||
chgrpcmd=""
|
||||
stripcmd=""
|
||||
rmcmd="$rmprog -f"
|
||||
mvcmd="$mvprog"
|
||||
src=""
|
||||
dst=""
|
||||
dir_arg=""
|
||||
|
||||
while [ x"$1" != x ]; do
|
||||
case $1 in
|
||||
-c) instcmd="$cpprog"
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-d) dir_arg=true
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-m) chmodcmd="$chmodprog $2"
|
||||
shift
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-o) chowncmd="$chownprog $2"
|
||||
shift
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-g) chgrpcmd="$chgrpprog $2"
|
||||
shift
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-s) stripcmd="$stripprog"
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-t=*) transformarg=`echo $1 | sed 's/-t=//'`
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-b=*) transformbasename=`echo $1 | sed 's/-b=//'`
|
||||
shift
|
||||
continue;;
|
||||
|
||||
*) if [ x"$src" = x ]
|
||||
then
|
||||
src=$1
|
||||
else
|
||||
# this colon is to work around a 386BSD /bin/sh bug
|
||||
:
|
||||
dst=$1
|
||||
fi
|
||||
shift
|
||||
continue;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ x"$src" = x ]
|
||||
then
|
||||
echo "install: no input file specified"
|
||||
exit 1
|
||||
else
|
||||
true
|
||||
fi
|
||||
|
||||
if [ x"$dir_arg" != x ]; then
|
||||
dst=$src
|
||||
src=""
|
||||
|
||||
if [ -d $dst ]; then
|
||||
instcmd=:
|
||||
else
|
||||
instcmd=mkdir
|
||||
fi
|
||||
else
|
||||
|
||||
# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
|
||||
# might cause directories to be created, which would be especially bad
|
||||
# if $src (and thus $dsttmp) contains '*'.
|
||||
|
||||
if [ -f $src -o -d $src ]
|
||||
then
|
||||
true
|
||||
else
|
||||
echo "install: $src does not exist"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ x"$dst" = x ]
|
||||
then
|
||||
echo "install: no destination specified"
|
||||
exit 1
|
||||
else
|
||||
true
|
||||
fi
|
||||
|
||||
# If destination is a directory, append the input filename; if your system
|
||||
# does not like double slashes in filenames, you may need to add some logic
|
||||
|
||||
if [ -d $dst ]
|
||||
then
|
||||
dst="$dst"/`basename $src`
|
||||
else
|
||||
true
|
||||
fi
|
||||
fi
|
||||
|
||||
## this sed command emulates the dirname command
|
||||
dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
|
||||
|
||||
# Make sure that the destination directory exists.
|
||||
# this part is taken from Noah Friedman's mkinstalldirs script
|
||||
|
||||
# Skip lots of stat calls in the usual case.
|
||||
if [ ! -d "$dstdir" ]; then
|
||||
defaultIFS='
|
||||
'
|
||||
IFS="${IFS-${defaultIFS}}"
|
||||
|
||||
oIFS="${IFS}"
|
||||
# Some sh's can't handle IFS=/ for some reason.
|
||||
IFS='%'
|
||||
set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
|
||||
IFS="${oIFS}"
|
||||
|
||||
pathcomp=''
|
||||
|
||||
while [ $# -ne 0 ] ; do
|
||||
pathcomp="${pathcomp}${1}"
|
||||
shift
|
||||
|
||||
if [ ! -d "${pathcomp}" ] ;
|
||||
then
|
||||
$mkdirprog "${pathcomp}"
|
||||
else
|
||||
true
|
||||
fi
|
||||
|
||||
pathcomp="${pathcomp}/"
|
||||
done
|
||||
fi
|
||||
|
||||
if [ x"$dir_arg" != x ]
|
||||
then
|
||||
$doit $instcmd $dst &&
|
||||
|
||||
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
|
||||
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
|
||||
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
|
||||
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
|
||||
else
|
||||
|
||||
# If we're going to rename the final executable, determine the name now.
|
||||
|
||||
if [ x"$transformarg" = x ]
|
||||
then
|
||||
dstfile=`basename $dst`
|
||||
else
|
||||
dstfile=`basename $dst $transformbasename |
|
||||
sed $transformarg`$transformbasename
|
||||
fi
|
||||
|
||||
# don't allow the sed command to completely eliminate the filename
|
||||
|
||||
if [ x"$dstfile" = x ]
|
||||
then
|
||||
dstfile=`basename $dst`
|
||||
else
|
||||
true
|
||||
fi
|
||||
|
||||
# Make a temp file name in the proper directory.
|
||||
|
||||
dsttmp=$dstdir/#inst.$$#
|
||||
|
||||
# Move or copy the file name to the temp name
|
||||
|
||||
$doit $instcmd $src $dsttmp &&
|
||||
|
||||
trap "rm -f ${dsttmp}" 0 &&
|
||||
|
||||
# and set any options; do chmod last to preserve setuid bits
|
||||
|
||||
# If any of these fail, we abort the whole thing. If we want to
|
||||
# ignore errors from any of these, just make sure not to ignore
|
||||
# errors from the above "$doit $instcmd $src $dsttmp" command.
|
||||
|
||||
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
|
||||
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
|
||||
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
|
||||
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&
|
||||
|
||||
# Now rename the file to the real destination.
|
||||
|
||||
$doit $rmcmd -f $dstdir/$dstfile &&
|
||||
$doit $mvcmd $dsttmp $dstdir/$dstfile
|
||||
|
||||
fi &&
|
||||
|
||||
|
||||
exit 0
|
||||
163
contrib/idn/mdnkit/lib/Makefile.in
Normal file
163
contrib/idn/mdnkit/lib/Makefile.in
Normal file
|
|
@ -0,0 +1,163 @@
|
|||
# $Id: Makefile.in,v 1.23 2000/11/21 02:29:52 ishisone 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
# Tokyo, Japan.
|
||||
#
|
||||
# 1. Use, Modification and Redistribution (including distribution of any
|
||||
# modified or derived work) in source and/or binary forms is permitted
|
||||
# under this License Terms and Conditions.
|
||||
#
|
||||
# 2. Redistribution of source code must retain the copyright notices as they
|
||||
# appear in each source code file, this License Terms and Conditions.
|
||||
#
|
||||
# 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
# this License Terms and Conditions, in the documentation and/or other
|
||||
# materials provided with the distribution. For the purposes of binary
|
||||
# distribution the "Copyright Notice" refers to the following language:
|
||||
# "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
#
|
||||
# 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
# derived from this Software without specific prior written approval of
|
||||
# JPNIC.
|
||||
#
|
||||
# 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
#
|
||||
# 6. Indemnification by Licensee
|
||||
# Any person or entities using and/or redistributing this Software under
|
||||
# this License Terms and Conditions shall defend indemnify and hold
|
||||
# harmless JPNIC from and against any and all judgements damages,
|
||||
# expenses, settlement liabilities, cost and other liabilities of any
|
||||
# kind as a result of use and redistribution of this Software or any
|
||||
# claim, suite, action, litigation or proceeding by any third party
|
||||
# arising out of or relates to this License Terms and Conditions.
|
||||
#
|
||||
# 7. Governing Law, Jurisdiction and Venue
|
||||
# This License Terms and Conditions shall be governed by and and
|
||||
# construed in accordance with the law of Japan. Any person or entities
|
||||
# using and/or redistributing this Software under this License Terms and
|
||||
# Conditions hereby agrees and consent to the personal and exclusive
|
||||
# jurisdiction and venue of Tokyo District Court of Japan.
|
||||
|
||||
LIB_CURRENT = 4
|
||||
LIB_REVISION = 0
|
||||
|
||||
.SUFFIXES: .lo
|
||||
|
||||
top_builddir = ..
|
||||
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
prefix = @prefix@
|
||||
exec_prefix = @exec_prefix@
|
||||
|
||||
BINDIR = @bindir@
|
||||
LIBDIR = @libdir@
|
||||
ETCDIR = @sysconfdir@
|
||||
|
||||
CC = @CC@
|
||||
RANLIB = @RANLIB@
|
||||
INSTALL = @INSTALL@
|
||||
INSTALL_PROGRAM = @INSTALL_PROGRAM@
|
||||
INSTALL_DATA = @INSTALL_DATA@
|
||||
SHELL = @SHELL@
|
||||
LIBTOOL = @LIBTOOL@
|
||||
|
||||
OPTS =
|
||||
INCS = -I$(srcdir)/../include -I../include
|
||||
DEFS = -DMDN_RESCONF_DIR="\"$(ETCDIR)\""
|
||||
|
||||
CFLAGS = $(OPTS) $(INCS) $(DEFS) @CFLAGS@
|
||||
LDFLAGS = @LDFLAGS@
|
||||
|
||||
ICONVLIB = @ICONVLIB@
|
||||
|
||||
SRCS = \
|
||||
brace.c \
|
||||
converter.c \
|
||||
debug.c \
|
||||
dn.c \
|
||||
lace.c \
|
||||
localencoding.c \
|
||||
log.c \
|
||||
msgheader.c \
|
||||
msgtrans.c \
|
||||
normalizer.c \
|
||||
race.c \
|
||||
res.c \
|
||||
resconf.c \
|
||||
result.c \
|
||||
selectiveencode.c \
|
||||
strhash.c \
|
||||
translator.c \
|
||||
unicode.c \
|
||||
unicodedata.c \
|
||||
unormalize.c \
|
||||
utf5.c \
|
||||
utf8.c \
|
||||
util.c \
|
||||
zldrule.c
|
||||
|
||||
OBJS = \
|
||||
brace.lo \
|
||||
converter.lo \
|
||||
debug.lo \
|
||||
dn.lo \
|
||||
lace.lo \
|
||||
localencoding.lo \
|
||||
log.lo \
|
||||
msgheader.lo \
|
||||
msgtrans.lo \
|
||||
normalizer.lo \
|
||||
race.lo \
|
||||
res.lo \
|
||||
resconf.lo \
|
||||
result.lo \
|
||||
selectiveencode.lo \
|
||||
strhash.lo \
|
||||
translator.lo \
|
||||
unicode.lo \
|
||||
unormalize.lo \
|
||||
utf5.lo \
|
||||
utf8.lo \
|
||||
util.lo \
|
||||
zldrule.lo
|
||||
|
||||
LIB = libmdn
|
||||
|
||||
.c.lo:
|
||||
$(LIBTOOL) --mode=compile $(CC) $(CFLAGS) -c $<
|
||||
|
||||
all: $(LIB).la
|
||||
|
||||
$(LIB).la: $(OBJS)
|
||||
$(LIBTOOL) --mode=link $(LD) $(LDFLAGS) -o $@ \
|
||||
-version-info $(LIB_CURRENT):$(LIB_REVISION) \
|
||||
-rpath $(LIBDIR) $(OBJS)
|
||||
|
||||
install: $(LIB).la
|
||||
[ -d $(LIBDIR) ] || mkdir $(LIBDIR)
|
||||
$(LIBTOOL) $(INSTALL_DATA) $(LIB).la $(LIBDIR)
|
||||
[ -f $(LIBDIR)/$(LIB).a ] && $(RANLIB) $(LIBDIR)/$(LIB).a
|
||||
[ -d $(ETCDIR) ] || mkdir $(ETCDIR)
|
||||
$(INSTALL_DATA) $(srcdir)/mdnres.conf.sample $(ETCDIR)
|
||||
|
||||
clean:
|
||||
rm -f *.o *.lo *.la *.a core *.core *~
|
||||
82
contrib/idn/mdnkit/lib/README
Normal file
82
contrib/idn/mdnkit/lib/README
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
This directory contains source files for MDN library.
|
||||
|
||||
Here's the brief description of each module.
|
||||
|
||||
|
||||
* Higher level modules
|
||||
|
||||
msgtrans.c
|
||||
DNS message translator.
|
||||
This is the heart of 'dnsproxy' daemon.
|
||||
|
||||
translator.c
|
||||
Domain name translator.
|
||||
Perform domain name translation, including
|
||||
+ add/remove ZLD
|
||||
+ conversion between local codeset and target codeset
|
||||
+ normalization
|
||||
|
||||
res.c
|
||||
resconf.c
|
||||
Domain name translation interface suitable for embedding in
|
||||
client-side resolver library, including configuration file
|
||||
(mdnres.conf) reader.
|
||||
|
||||
* Lower level modules
|
||||
|
||||
converter.c
|
||||
Codeset converter.
|
||||
All the conversion is done between some local encoding and UTF-8.
|
||||
It is specially designed for domain-name conversion.
|
||||
For example some converter (such as UTF-5 <-> UTF-8)
|
||||
treats period specially.
|
||||
|
||||
normalizer.c
|
||||
String normalizer, including Unicode normalization forms.
|
||||
|
||||
unormalize.c
|
||||
Perform normalization defined in "Unicode Normalization Forms".
|
||||
|
||||
zldrule.c
|
||||
Find out ZLD and codeset of a domain name.
|
||||
|
||||
|
||||
* Utility modules
|
||||
|
||||
localencoding.c
|
||||
Local encoding (codeset) detecter based on the locale information.
|
||||
|
||||
debug.c
|
||||
Debug utilities.
|
||||
|
||||
log.c
|
||||
Logging facility.
|
||||
|
||||
msgheader.c
|
||||
DNS message header parser/builder.
|
||||
|
||||
dn.c
|
||||
Domain name compression/expansion, similar to dn_comp/dn_expand
|
||||
in the resolver library.
|
||||
|
||||
race.c
|
||||
Codeset conversion routine for RACE encoding.
|
||||
|
||||
result.c
|
||||
MDN result code to string conversion.
|
||||
|
||||
strhash.c
|
||||
String-keyed hash table.
|
||||
|
||||
utf5.c
|
||||
UTF-5 encoding utility.
|
||||
|
||||
utf8.c
|
||||
UTF-8 encoding utility.
|
||||
|
||||
unicode.c
|
||||
Provide access to various information contained in "UnicodeData.txt".
|
||||
|
||||
selectiveencode.c
|
||||
Find a substring which seems to be a part of domain name containing
|
||||
non-ascii characters.
|
||||
775
contrib/idn/mdnkit/lib/brace.c
Normal file
775
contrib/idn/mdnkit/lib/brace.c
Normal file
|
|
@ -0,0 +1,775 @@
|
|||
#ifndef lint
|
||||
static char *rcsid = "$Id: brace.c,v 1.11 2000/11/22 06:33:33 m-kasahr Exp $";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <mdn/result.h>
|
||||
#include <mdn/assert.h>
|
||||
#include <mdn/logmacro.h>
|
||||
#include <mdn/converter.h>
|
||||
#include <mdn/utf8.h>
|
||||
#include <mdn/debug.h>
|
||||
#include <mdn/brace.h>
|
||||
#include <mdn/util.h>
|
||||
|
||||
#ifndef MDN_BRACE_SUFFIX
|
||||
#define MDN_BRACE_SUFFIX "-8q9"
|
||||
#endif
|
||||
#define BRACE_SUFFIX_LEN (strlen(MDN_BRACE_SUFFIX))
|
||||
#define BRACE_BUF_SIZE 128 /* more than enough */
|
||||
#define BRACE_BASE32(n) (brace_base32[n])
|
||||
#define BRACE_RBASE32(c) (brace_rbase32(c))
|
||||
|
||||
#define IS_LDH(c) \
|
||||
(('a' <= (c) && (c) <= 'z') || ('A' <= (c) && (c) <= 'Z') || \
|
||||
('0' <= (c) && (c) <= '9') || (c) == '-')
|
||||
|
||||
/*
|
||||
* Encoding Styles.
|
||||
*/
|
||||
enum {
|
||||
half_row_style, /* all non-LDH characters are in a single half row */
|
||||
full_row_style, /* all non-LDH characters are in a single row */
|
||||
mixed_style,
|
||||
no_row_style
|
||||
};
|
||||
|
||||
/*
|
||||
* Base-32 encoding array.
|
||||
*/
|
||||
static char brace_base32[] = "23456789abcdefghijkmnpqrstuvwxyz";
|
||||
|
||||
static mdn_result_t brace_l2u(const char *from, const char *end,
|
||||
char *to, size_t tolen, size_t *clenp);
|
||||
static mdn_result_t brace_u2l(const char *from, const char *end,
|
||||
char *to, size_t tolen, size_t *clenp);
|
||||
static mdn_result_t brace_decode(const char *from, size_t fromlen,
|
||||
char *to, size_t tolen);
|
||||
static mdn_result_t brace_decode_utf16(const char *from,
|
||||
size_t fromlen,
|
||||
unsigned short *buf,
|
||||
size_t *lenp);
|
||||
static mdn_result_t brace_encode(const char *from, size_t fromlen,
|
||||
char *to, size_t tolen);
|
||||
static mdn_result_t brace_encode_utf16(const unsigned short *p, size_t len,
|
||||
char *to, size_t tolen,
|
||||
int encoding_style,
|
||||
unsigned short row);
|
||||
static mdn_result_t get_encoding_style(unsigned short *p, size_t len,
|
||||
int *stylep, unsigned short *rowp);
|
||||
static int brace_rbase32(int c);
|
||||
|
||||
/* ARGSUSED */
|
||||
mdn_result_t
|
||||
mdn__brace_open(mdn_converter_t ctx, mdn_converter_dir_t dir) {
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
/* ARGSUSED */
|
||||
mdn_result_t
|
||||
mdn__brace_close(mdn_converter_t ctx, mdn_converter_dir_t dir) {
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
mdn_result_t
|
||||
mdn__brace_convert(mdn_converter_t ctx, mdn_converter_dir_t dir,
|
||||
const char *from, char *toorg, size_t tolen)
|
||||
{
|
||||
char *to = toorg;
|
||||
|
||||
assert(ctx != NULL &&
|
||||
(dir == mdn_converter_l2u || dir == mdn_converter_u2l));
|
||||
|
||||
TRACE(("mdn__brace_convert(dir=%s,from=\"%s\")\n",
|
||||
dir == mdn_converter_l2u ? "l2u" : "u2l",
|
||||
mdn_debug_xstring(from, 20)));
|
||||
|
||||
for (;;) {
|
||||
const char *end;
|
||||
size_t convlen;
|
||||
mdn_result_t r;
|
||||
|
||||
/*
|
||||
* Find the end of this component (label).
|
||||
*/
|
||||
if ((end = strchr(from, '.')) == NULL)
|
||||
end = from + strlen(from);
|
||||
|
||||
/*
|
||||
* Convert it.
|
||||
*/
|
||||
if (dir == mdn_converter_l2u)
|
||||
r = brace_l2u(from, end, to, tolen, &convlen);
|
||||
else
|
||||
r = brace_u2l(from, end, to, tolen, &convlen);
|
||||
if (r != mdn_success)
|
||||
return (r);
|
||||
|
||||
/*
|
||||
* Copy '.' or NUL.
|
||||
*/
|
||||
if (tolen <= convlen)
|
||||
return (mdn_buffer_overflow);
|
||||
|
||||
to += convlen;
|
||||
*to++ = *end;
|
||||
tolen -= convlen + 1;
|
||||
|
||||
if (*end == '\0')
|
||||
break;
|
||||
|
||||
from = end + 1;
|
||||
}
|
||||
|
||||
DUMP(("mdn__brace_convert: \"%s\"\n", mdn_debug_xstring(toorg, 70)));
|
||||
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
brace_l2u(const char *from, const char *end,
|
||||
char *to, size_t tolen, size_t *clenp) {
|
||||
size_t len = end - from;
|
||||
size_t suflen = BRACE_SUFFIX_LEN;
|
||||
|
||||
if (len >= suflen &&
|
||||
mdn_util_casematch(end - suflen, MDN_BRACE_SUFFIX, suflen)) {
|
||||
/*
|
||||
* BRACE encoding suffix found.
|
||||
*/
|
||||
mdn_result_t r;
|
||||
|
||||
r = brace_decode(from, len - suflen, to, tolen);
|
||||
if (r == mdn_invalid_encoding)
|
||||
goto copy;
|
||||
else if (r != mdn_success)
|
||||
return (r);
|
||||
|
||||
len = strlen(to);
|
||||
} else {
|
||||
/*
|
||||
* Not BRACE encoded. Copy verbatim.
|
||||
*/
|
||||
copy:
|
||||
if (mdn_util_domainspan(from, end) < end) {
|
||||
/* invalid character found */
|
||||
return (mdn_invalid_encoding);
|
||||
}
|
||||
|
||||
if (tolen < len)
|
||||
return (mdn_buffer_overflow);
|
||||
|
||||
(void)memcpy(to, from, len);
|
||||
}
|
||||
*clenp = len;
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
brace_u2l(const char *from, const char *end,
|
||||
char *to, size_t tolen, size_t *clenp) {
|
||||
size_t len = end - from;
|
||||
size_t suflen = BRACE_SUFFIX_LEN;
|
||||
|
||||
/*
|
||||
* See if encoding is necessary.
|
||||
*/
|
||||
if (mdn_util_domainspan(from, end) < end ||
|
||||
(len >= suflen &&
|
||||
mdn_util_casematch(end - suflen, MDN_BRACE_SUFFIX, suflen))) {
|
||||
/*
|
||||
* Conversion is necessary.
|
||||
*/
|
||||
mdn_result_t r;
|
||||
size_t t;
|
||||
|
||||
r = brace_encode(from, len, to, tolen);
|
||||
if (r != mdn_success)
|
||||
return (r);
|
||||
t = strlen(to);
|
||||
|
||||
/* Append suffix. */
|
||||
if (tolen < t + suflen)
|
||||
return (mdn_buffer_overflow);
|
||||
(void)memcpy(to + t, MDN_BRACE_SUFFIX, suflen);
|
||||
|
||||
len = t + suflen;
|
||||
} else {
|
||||
/*
|
||||
* Conversion is NOT necessary.
|
||||
* Copy verbatim.
|
||||
*/
|
||||
if (tolen < len)
|
||||
return (mdn_buffer_overflow);
|
||||
|
||||
(void)memcpy(to, from, len);
|
||||
}
|
||||
*clenp = len;
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
brace_decode(const char *from, size_t fromlen, char *to, size_t tolen) {
|
||||
unsigned short *buf;
|
||||
unsigned short local_buf[BRACE_BUF_SIZE];
|
||||
size_t len, reslen;
|
||||
mdn_result_t r;
|
||||
|
||||
/*
|
||||
* Allocate sufficient buffer.
|
||||
*/
|
||||
if (fromlen > BRACE_BUF_SIZE) {
|
||||
if ((buf = malloc(sizeof(*buf) * fromlen)) == NULL)
|
||||
return (mdn_nomemory);
|
||||
} else {
|
||||
/* Use local buffer. */
|
||||
buf = local_buf;
|
||||
}
|
||||
|
||||
/*
|
||||
* Decode into UTF-16 string.
|
||||
*/
|
||||
r = brace_decode_utf16(from, fromlen, buf, &len);
|
||||
if (r != mdn_success)
|
||||
goto ret;
|
||||
|
||||
/*
|
||||
* Now 'buf' points the decompressed string, which must contain
|
||||
* UTF-16 characters.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Convert to utf-8.
|
||||
*/
|
||||
r = mdn_util_utf16toutf8(buf, len, to, tolen, &reslen);
|
||||
if (r != mdn_success)
|
||||
goto ret;
|
||||
if (reslen >= tolen) {
|
||||
r = mdn_buffer_overflow;
|
||||
goto ret;
|
||||
}
|
||||
to[reslen] = '\0';
|
||||
|
||||
r = mdn_success;
|
||||
|
||||
ret:
|
||||
if (buf != local_buf)
|
||||
free(buf);
|
||||
return (r);
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
brace_decode_utf16(const char *from, size_t fromlen,
|
||||
unsigned short *buf, size_t *lenp)
|
||||
{
|
||||
int encoding_style;
|
||||
unsigned short row;
|
||||
unsigned long bitbuf = 0;
|
||||
int bitlen = 0;
|
||||
int literal_mode;
|
||||
int i;
|
||||
|
||||
#define READ_BITS(n) \
|
||||
do { \
|
||||
int len = (n); \
|
||||
while (bitlen < len) { \
|
||||
int x; \
|
||||
if (fromlen-- <= 0) \
|
||||
return (mdn_invalid_encoding); \
|
||||
if ((x = BRACE_RBASE32(*from++)) < 0) \
|
||||
return (mdn_invalid_encoding); \
|
||||
bitbuf = (bitbuf << 5) | x; \
|
||||
bitlen += 5; \
|
||||
} \
|
||||
} while (0)
|
||||
#define EXTRACT_BITS(n) \
|
||||
(bitlen -= (n), ((bitbuf >> bitlen) & ((1<<(n)) - 1)))
|
||||
|
||||
READ_BITS(2);
|
||||
switch (EXTRACT_BITS(2)) {
|
||||
case 0:
|
||||
encoding_style = half_row_style;
|
||||
READ_BITS(9);
|
||||
row = EXTRACT_BITS(9) << 7;
|
||||
break;
|
||||
case 1:
|
||||
encoding_style = full_row_style;
|
||||
READ_BITS(8);
|
||||
row = EXTRACT_BITS(8) << 8;
|
||||
break;
|
||||
case 2:
|
||||
encoding_style = mixed_style;
|
||||
READ_BITS(9);
|
||||
row = EXTRACT_BITS(9) << 7;
|
||||
break;
|
||||
case 3:
|
||||
encoding_style = no_row_style;
|
||||
row = 0; /* to keep lint happy */
|
||||
break;
|
||||
default:
|
||||
FATAL(("brace_decode_utf16: internal error\n"));
|
||||
abort();
|
||||
return (mdn_failure); /* to keep lint happy */
|
||||
}
|
||||
|
||||
i = 0;
|
||||
literal_mode = 0;
|
||||
while (fromlen > 0) {
|
||||
int c = *from; /* peek */
|
||||
|
||||
if (c == '-') {
|
||||
if (fromlen > 0 && from[1] == '-') {
|
||||
buf[i++] = '-';
|
||||
from += 2;
|
||||
fromlen -= 2;
|
||||
} else {
|
||||
literal_mode = !literal_mode;
|
||||
from++;
|
||||
fromlen--;
|
||||
}
|
||||
} else if (literal_mode) {
|
||||
buf[i++] = c;
|
||||
from++;
|
||||
fromlen--;
|
||||
} else {
|
||||
switch (encoding_style) {
|
||||
case half_row_style:
|
||||
READ_BITS(7);
|
||||
buf[i++] = row | EXTRACT_BITS(7);
|
||||
break;
|
||||
case full_row_style:
|
||||
READ_BITS(8);
|
||||
buf[i++] = row | EXTRACT_BITS(8);
|
||||
break;
|
||||
case mixed_style:
|
||||
READ_BITS(2);
|
||||
if (EXTRACT_BITS(1)) {
|
||||
if (EXTRACT_BITS(1)) {
|
||||
READ_BITS(16);
|
||||
buf[i++] = EXTRACT_BITS(16);
|
||||
} else {
|
||||
READ_BITS(7);
|
||||
buf[i++] = (row ^ 0x80) |
|
||||
EXTRACT_BITS(7);
|
||||
}
|
||||
} else {
|
||||
READ_BITS(7);
|
||||
buf[i++] = row | EXTRACT_BITS(7);
|
||||
}
|
||||
break;
|
||||
case no_row_style:
|
||||
READ_BITS(16);
|
||||
buf[i++] = EXTRACT_BITS(16);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (bitlen > 4)
|
||||
return (mdn_invalid_encoding);
|
||||
|
||||
*lenp = i;
|
||||
return (mdn_success);
|
||||
#undef READ_BITS
|
||||
#undef EXTRACT_BITS
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
brace_encode(const char *from, size_t fromlen, char *to, size_t tolen) {
|
||||
unsigned short *buf;
|
||||
unsigned short local_buf[BRACE_BUF_SIZE]; /* UTF-16 */
|
||||
unsigned short row;
|
||||
mdn_result_t r;
|
||||
size_t buflen, len;
|
||||
int encoding_style;
|
||||
|
||||
/*
|
||||
* Convert to UTF-16.
|
||||
*/
|
||||
buf = local_buf;
|
||||
buflen = BRACE_BUF_SIZE;
|
||||
for (;;) {
|
||||
r = mdn_util_utf8toutf16(from, fromlen,
|
||||
buf, buflen, &len);
|
||||
if (r == mdn_buffer_overflow) {
|
||||
buflen *= 2;
|
||||
if (buf == local_buf)
|
||||
buf = malloc(sizeof(*buf) * buflen);
|
||||
else
|
||||
buf = realloc(buf, sizeof(*buf) * buflen);
|
||||
if (buf == NULL)
|
||||
return (mdn_nomemory);
|
||||
} else if (r == mdn_success) {
|
||||
break;
|
||||
} else {
|
||||
goto finish;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Now 'buf' contains UTF-16 encoded string consisting of
|
||||
* 'len' characters.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Choose encoding style.
|
||||
*/
|
||||
r = get_encoding_style(buf, len, &encoding_style, &row);
|
||||
if (r != mdn_success)
|
||||
goto finish;
|
||||
|
||||
r = brace_encode_utf16(buf, len, to, tolen, encoding_style, row);
|
||||
|
||||
finish:
|
||||
if (buf != local_buf)
|
||||
free(buf);
|
||||
return (r);
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
brace_encode_utf16(const unsigned short *p, size_t len,
|
||||
char *to, size_t tolen,
|
||||
int encoding_style, unsigned short row)
|
||||
{
|
||||
unsigned long bitbuf = 0; /* bit stream buffer */
|
||||
char *save_to;
|
||||
int bitlen = 0; /* # of bits in 'bitbuf' */
|
||||
int nonhyphen;
|
||||
int i;
|
||||
|
||||
#define FLUSH_BITS_1(p) \
|
||||
do { \
|
||||
int x = (bitbuf >> (bitlen - 5)) & 0x1f; \
|
||||
bitlen -= 5; \
|
||||
*p = BRACE_BASE32(x); \
|
||||
} while (0)
|
||||
#define FLUSH_BITS \
|
||||
do { \
|
||||
while (bitlen >= 5) { \
|
||||
if (tolen < 1) \
|
||||
return (mdn_buffer_overflow); \
|
||||
FLUSH_BITS_1(to); \
|
||||
to++, tolen--; \
|
||||
} \
|
||||
} while (0)
|
||||
#define PUT(c) \
|
||||
do { \
|
||||
if (tolen-- < 1) \
|
||||
return (mdn_buffer_overflow); \
|
||||
*to++ = c; \
|
||||
} while (0)
|
||||
|
||||
switch (encoding_style) {
|
||||
case half_row_style:
|
||||
/* 00xxxxxxxxx */
|
||||
bitbuf = row >> 7;
|
||||
bitlen = 2 + 9;
|
||||
break;
|
||||
case full_row_style:
|
||||
/* 01xxxxxxxx */
|
||||
bitbuf = (1 << 8) | (row >> 8);
|
||||
bitlen = 2 + 8;
|
||||
break;
|
||||
case mixed_style:
|
||||
/* 10xxxxxxxxx */
|
||||
bitbuf = (1 << 10) | (row >> 7);
|
||||
bitlen = 2 + 9;
|
||||
break;
|
||||
case no_row_style:
|
||||
/* 11 */
|
||||
bitbuf = 3;
|
||||
bitlen = 2;
|
||||
break;
|
||||
default:
|
||||
FATAL(("brace_compress_encode: internal error "
|
||||
"invalid encoding_style\n"));
|
||||
abort();
|
||||
break;
|
||||
}
|
||||
|
||||
FLUSH_BITS;
|
||||
|
||||
if (bitlen > 0) {
|
||||
save_to = to++;
|
||||
if (tolen-- < 1)
|
||||
return (mdn_buffer_overflow);
|
||||
} else {
|
||||
save_to = NULL;
|
||||
}
|
||||
|
||||
nonhyphen = 0;
|
||||
for (i = 0; i < len; i++) {
|
||||
if (p[i] == 0x2d) {
|
||||
PUT('-');
|
||||
PUT('-');
|
||||
} else if (IS_LDH(p[i])) {
|
||||
if (!nonhyphen)
|
||||
PUT('-');
|
||||
PUT(p[i]);
|
||||
nonhyphen = 1;
|
||||
} else {
|
||||
if (nonhyphen) {
|
||||
PUT('-');
|
||||
}
|
||||
nonhyphen = 0;
|
||||
switch (encoding_style) {
|
||||
case half_row_style:
|
||||
bitlen += 7;
|
||||
bitbuf = (bitbuf << 7) | (p[i] & 0x7f);
|
||||
break;
|
||||
case full_row_style:
|
||||
bitlen += 8;
|
||||
bitbuf = (bitbuf << 8) | (p[i] & 0xff);
|
||||
break;
|
||||
case mixed_style:
|
||||
if ((p[i] & 0xff80) == row) {
|
||||
bitlen += 8;
|
||||
bitbuf = (bitbuf << 8) | (p[i] & 0x7f);
|
||||
} else if ((p[i] & 0xff80) == (row ^ 0x80)) {
|
||||
bitlen += 9;
|
||||
bitbuf = (bitbuf << 9) | (1 << 8) |
|
||||
(p[i] & 0x7f);
|
||||
} else {
|
||||
bitlen += 18;
|
||||
bitbuf = (bitbuf << 18) | (3 << 16) |
|
||||
p[i];
|
||||
}
|
||||
break;
|
||||
case no_row_style:
|
||||
bitlen += 16;
|
||||
bitbuf = (bitbuf << 16) | p[i];
|
||||
break;
|
||||
}
|
||||
if (save_to != NULL)
|
||||
FLUSH_BITS_1(save_to);
|
||||
FLUSH_BITS;
|
||||
if (bitlen > 0) {
|
||||
save_to = to++;
|
||||
if (tolen-- < 1)
|
||||
return (mdn_buffer_overflow);
|
||||
} else {
|
||||
save_to = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (bitlen > 0) {
|
||||
assert(save_to != NULL && bitlen < 5);
|
||||
bitbuf <<= 5 - bitlen;
|
||||
bitlen = 5;
|
||||
FLUSH_BITS_1(save_to);
|
||||
}
|
||||
|
||||
if (tolen <= 0)
|
||||
return (mdn_buffer_overflow);
|
||||
|
||||
*to = '\0';
|
||||
return (mdn_success);
|
||||
#undef FLUSH_BITS_1
|
||||
#undef FLUSH_BITS
|
||||
#undef PUT
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
get_encoding_style(unsigned short *p, size_t len,
|
||||
int *stylep, unsigned short *rowp)
|
||||
{
|
||||
struct row {
|
||||
unsigned short upper;
|
||||
unsigned short num;
|
||||
unsigned short cmpl;
|
||||
} *row_cands, row_cands_buf[64]; /* usually 64 is enough */
|
||||
int cands_size = 64;
|
||||
int num_cands = 0;
|
||||
int num_nonldh = 0;
|
||||
int style = no_row_style; /* to keep lint happy */
|
||||
int best;
|
||||
int m, m_prime;
|
||||
int i, j;
|
||||
|
||||
row_cands = row_cands_buf;
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
unsigned int upper;
|
||||
|
||||
/* Ignore LDH characters. */
|
||||
if (IS_LDH(p[i]))
|
||||
continue;
|
||||
|
||||
num_nonldh++;
|
||||
upper = p[i] & 0xff80; /* upper 9bits */
|
||||
|
||||
for (j = 0; j < num_cands; j++) {
|
||||
if (upper == row_cands[j].upper) {
|
||||
row_cands[j].num++;
|
||||
goto found;
|
||||
}
|
||||
}
|
||||
if (num_cands >= cands_size) {
|
||||
/* Make the row buffer bigger. */
|
||||
cands_size *= 2;
|
||||
if (row_cands == row_cands_buf)
|
||||
row_cands = malloc(sizeof(struct row) *
|
||||
cands_size);
|
||||
else
|
||||
row_cands = realloc(row_cands,
|
||||
sizeof(struct row) *
|
||||
cands_size);
|
||||
if (row_cands == NULL)
|
||||
return (mdn_nomemory);
|
||||
}
|
||||
row_cands[num_cands].upper = upper;
|
||||
row_cands[num_cands].num = 1;
|
||||
row_cands[num_cands].cmpl = 0;
|
||||
num_cands++;
|
||||
found:
|
||||
;
|
||||
}
|
||||
|
||||
if (num_cands == 0) {
|
||||
/*
|
||||
* There is no non-LDH characters. Draft is not clear on
|
||||
* this case, but the sample implementation uses no-row style.
|
||||
*/
|
||||
style = no_row_style;
|
||||
goto ret;
|
||||
}
|
||||
if (num_cands == 1) {
|
||||
/*
|
||||
* Choose half-row style.
|
||||
*/
|
||||
*rowp = row_cands[0].upper;
|
||||
style = half_row_style;
|
||||
goto ret;
|
||||
}
|
||||
if (num_cands == 2 &&
|
||||
(row_cands[0].upper ^ row_cands[1].upper) == 0x80) {
|
||||
/*
|
||||
* All the non-LDH characters are in the same row.
|
||||
* Choose full-row style.
|
||||
*/
|
||||
*rowp = row_cands[0].upper & ~0x80;
|
||||
style = full_row_style;
|
||||
goto ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the number of characters in the complementary half-row.
|
||||
*/
|
||||
for (i = 1; i < num_cands; i++) {
|
||||
unsigned int upper = row_cands[i].upper;
|
||||
|
||||
for (j = 0; j < i; j++) {
|
||||
if ((row_cands[j].upper ^ upper) == 0x80) {
|
||||
row_cands[i].cmpl = row_cands[j].num;
|
||||
row_cands[j].cmpl = row_cands[i].num;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Choose the best M.
|
||||
*/
|
||||
#define M(i) \
|
||||
(3 + (num_nonldh * 18 - row_cands[i].num * 10 - row_cands[i].cmpl * 9) / 5)
|
||||
for (best = 0, m = M(0), i = 1; i < num_cands; i++) {
|
||||
int m_i = M(i);
|
||||
if (m_i < m ||
|
||||
(m_i == m && row_cands[i].upper < row_cands[best].upper)) {
|
||||
best = i;
|
||||
m = m_i;
|
||||
}
|
||||
}
|
||||
#undef M
|
||||
m_prime = (6 + num_nonldh * 16) / 5;
|
||||
if (m_prime <= m) {
|
||||
style = no_row_style;
|
||||
} else {
|
||||
*rowp = row_cands[best].upper;
|
||||
style = mixed_style;
|
||||
}
|
||||
ret:
|
||||
if (row_cands != row_cands_buf)
|
||||
free(row_cands);
|
||||
*stylep = style;
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
static int
|
||||
brace_rbase32(int c) {
|
||||
if ('A' <= c && c <= 'Z')
|
||||
c = 'a' + (c - 'A');
|
||||
if ('2' <= c && c <= '9')
|
||||
return (c - '2');
|
||||
else if ('a' <= c && c <= 'k')
|
||||
return (c - 'a' + 8);
|
||||
else if ('m' <= c && c <= 'n')
|
||||
return (c - 'm' + 19);
|
||||
else if ('p' <= c && c <= 'z')
|
||||
return (c - 'p' + 21);
|
||||
else
|
||||
return (-1);
|
||||
}
|
||||
994
contrib/idn/mdnkit/lib/converter.c
Normal file
994
contrib/idn/mdnkit/lib/converter.c
Normal file
|
|
@ -0,0 +1,994 @@
|
|||
#ifndef lint
|
||||
static char *rcsid = "$Id: converter.c,v 1.23 2000/11/14 00:13:31 ishisone Exp $";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <iconv.h>
|
||||
|
||||
#include <mdn/result.h>
|
||||
#include <mdn/assert.h>
|
||||
#include <mdn/logmacro.h>
|
||||
#include <mdn/converter.h>
|
||||
#include <mdn/strhash.h>
|
||||
#include <mdn/utf8.h>
|
||||
#include <mdn/utf5.h>
|
||||
#include <mdn/debug.h>
|
||||
#include <mdn/race.h>
|
||||
#include <mdn/brace.h>
|
||||
#include <mdn/lace.h>
|
||||
|
||||
#ifndef MDN_UTF8_ENCODING_NAME
|
||||
#define MDN_UTF8_ENCODING_NAME "UTF-8" /* by IANA */
|
||||
#endif
|
||||
#ifndef MDN_UTF5_ENCODING_NAME
|
||||
#define MDN_UTF5_ENCODING_NAME "UTF-5"
|
||||
#endif
|
||||
#ifndef MDN_RACE_ENCODING_NAME
|
||||
#define MDN_RACE_ENCODING_NAME "RACE"
|
||||
#endif
|
||||
#ifndef MDN_BRACE_ENCODING_NAME
|
||||
#define MDN_BRACE_ENCODING_NAME "BRACE"
|
||||
#endif
|
||||
#ifndef MDN_LACE_ENCODING_NAME
|
||||
#define MDN_LACE_ENCODING_NAME "LACE"
|
||||
#endif
|
||||
|
||||
#define MAX_RECURSE 20
|
||||
|
||||
typedef struct {
|
||||
mdn_converter_openproc_t open;
|
||||
mdn_converter_closeproc_t close;
|
||||
mdn_converter_convertproc_t convert;
|
||||
int ascii_compatible;
|
||||
} converter_ops_t;
|
||||
|
||||
struct mdn_converter {
|
||||
char *local_encoding_name;
|
||||
converter_ops_t *ops;
|
||||
int flags;
|
||||
int opened[2];
|
||||
iconv_t ictx[2];
|
||||
};
|
||||
|
||||
static mdn_strhash_t encoding_name_hash;
|
||||
static mdn_strhash_t encoding_alias_hash;
|
||||
|
||||
static mdn_result_t converter_open(mdn_converter_t ctx,
|
||||
mdn_converter_dir_t dir);
|
||||
static mdn_result_t converter_close(mdn_converter_t ctx,
|
||||
mdn_converter_dir_t dir);
|
||||
static mdn_result_t register_standard_encoding(void);
|
||||
static const char *get_realname(const char *name);
|
||||
static void free_alias_value(void *value);
|
||||
static mdn_result_t roundtrip_check(mdn_converter_t ctx,
|
||||
mdn_converter_dir_t dir,
|
||||
const char *from, const char *to);
|
||||
static mdn_result_t converter_none_open(mdn_converter_t ctx,
|
||||
mdn_converter_dir_t dir);
|
||||
static mdn_result_t converter_none_close(mdn_converter_t ctx,
|
||||
mdn_converter_dir_t dir);
|
||||
static mdn_result_t converter_none_convert(mdn_converter_t ctx,
|
||||
mdn_converter_dir_t dir,
|
||||
const char *from,
|
||||
char *to, size_t tolen);
|
||||
static mdn_result_t converter_iconv_open(mdn_converter_t ctx,
|
||||
mdn_converter_dir_t dir);
|
||||
static mdn_result_t converter_iconv_close(mdn_converter_t ctx,
|
||||
mdn_converter_dir_t dir);
|
||||
static mdn_result_t converter_iconv_convert(mdn_converter_t ctx,
|
||||
mdn_converter_dir_t dir,
|
||||
const char *from,
|
||||
char *to, size_t tolen);
|
||||
static mdn_result_t converter_utf5_open(mdn_converter_t ctx,
|
||||
mdn_converter_dir_t dir);
|
||||
static mdn_result_t converter_utf5_close(mdn_converter_t ctx,
|
||||
mdn_converter_dir_t dir);
|
||||
static mdn_result_t converter_utf5_convert(mdn_converter_t ctx,
|
||||
mdn_converter_dir_t dir,
|
||||
const char *from,
|
||||
char *to, size_t tolen);
|
||||
#ifdef DEBUG
|
||||
static mdn_result_t converter_uescape_open(mdn_converter_t ctx,
|
||||
mdn_converter_dir_t dir);
|
||||
static mdn_result_t converter_uescape_close(mdn_converter_t ctx,
|
||||
mdn_converter_dir_t dir);
|
||||
static mdn_result_t converter_uescape_convert(mdn_converter_t ctx,
|
||||
mdn_converter_dir_t dir,
|
||||
const char *from,
|
||||
char *to, size_t tolen);
|
||||
#endif
|
||||
|
||||
static converter_ops_t none_converter_ops = {
|
||||
converter_none_open,
|
||||
converter_none_close,
|
||||
converter_none_convert,
|
||||
0,
|
||||
};
|
||||
|
||||
static converter_ops_t iconv_converter_ops = {
|
||||
converter_iconv_open,
|
||||
converter_iconv_close,
|
||||
converter_iconv_convert,
|
||||
0,
|
||||
};
|
||||
|
||||
/*
|
||||
* Initialize.
|
||||
*/
|
||||
|
||||
mdn_result_t
|
||||
mdn_converter_initialize(void) {
|
||||
mdn_result_t r = mdn_success;
|
||||
mdn_strhash_t hash;
|
||||
|
||||
if (encoding_alias_hash == NULL) {
|
||||
if ((r = mdn_strhash_create(&hash)) != mdn_success)
|
||||
return (r);
|
||||
encoding_alias_hash = hash;
|
||||
}
|
||||
if (encoding_name_hash == NULL) {
|
||||
if ((r = mdn_strhash_create(&hash)) != mdn_success)
|
||||
return (r);
|
||||
encoding_name_hash = hash;
|
||||
r = register_standard_encoding();
|
||||
}
|
||||
return (r);
|
||||
}
|
||||
|
||||
mdn_result_t
|
||||
mdn_converter_create(const char *name, mdn_converter_t *ctxp, int flags) {
|
||||
const char *realname;
|
||||
mdn_converter_t ctx;
|
||||
mdn_result_t r;
|
||||
void *v;
|
||||
|
||||
assert(name != NULL && ctxp != NULL);
|
||||
|
||||
TRACE(("mdn_converter_create(%s)\n", name));
|
||||
|
||||
realname = get_realname(name);
|
||||
#ifdef DEBUG
|
||||
if (strcmp(name, realname) != 0) {
|
||||
TRACE(("mdn_converter_create: realname=%s\n", realname));
|
||||
}
|
||||
#endif
|
||||
|
||||
*ctxp = NULL;
|
||||
|
||||
/* Allocate memory for a converter context and the name. */
|
||||
ctx = malloc(sizeof(struct mdn_converter) + strlen(realname) + 1);
|
||||
if (ctx == NULL) {
|
||||
WARNING(("mdn_converter_create: malloc failed\n"));
|
||||
return (mdn_nomemory);
|
||||
}
|
||||
(void)memset(ctx, 0, sizeof(*ctx));
|
||||
ctx->local_encoding_name = (char *)(ctx + 1);
|
||||
(void)strcpy(ctx->local_encoding_name, realname);
|
||||
ctx->flags = flags;
|
||||
|
||||
assert(encoding_name_hash != NULL);
|
||||
|
||||
if (strcmp(realname, MDN_UTF8_ENCODING_NAME) == 0) {
|
||||
/* No conversion needed */
|
||||
ctx->ops = &none_converter_ops;
|
||||
} else if ((r = mdn_strhash_get(encoding_name_hash, realname, &v))
|
||||
== mdn_success) {
|
||||
/* Special converter found */
|
||||
ctx->ops = (converter_ops_t *)v;
|
||||
} else {
|
||||
/* General case */
|
||||
ctx->ops = &iconv_converter_ops;
|
||||
}
|
||||
|
||||
if ((flags & MDN_CONVERTER_DELAYEDOPEN) == 0) {
|
||||
mdn_result_t r;
|
||||
|
||||
if ((r = converter_open(ctx,
|
||||
mdn_converter_l2u)) != mdn_success) {
|
||||
WARNING(("mdn_converter_create: open failed "
|
||||
"(local->utf8)\n"));
|
||||
return (r);
|
||||
}
|
||||
if ((r = converter_open(ctx,
|
||||
mdn_converter_u2l)) != mdn_success) {
|
||||
WARNING(("mdn_converter_create: open failed "
|
||||
"(utf8->local)\n"));
|
||||
return (r);
|
||||
}
|
||||
}
|
||||
|
||||
*ctxp = ctx;
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
converter_open(mdn_converter_t ctx, mdn_converter_dir_t dir) {
|
||||
mdn_result_t st = mdn_success;
|
||||
|
||||
assert(ctx != NULL &&
|
||||
(dir == mdn_converter_l2u || dir == mdn_converter_u2l));
|
||||
|
||||
if (!ctx->opened[dir]) {
|
||||
st = (*ctx->ops->open)(ctx, dir);
|
||||
if (st == mdn_success)
|
||||
ctx->opened[dir] = 1;
|
||||
}
|
||||
return (st);
|
||||
}
|
||||
|
||||
void
|
||||
mdn_converter_destroy(mdn_converter_t ctx) {
|
||||
assert(ctx != NULL);
|
||||
|
||||
TRACE(("mdn_converter_destroy()\n"));
|
||||
|
||||
(void)converter_close(ctx, mdn_converter_l2u);
|
||||
(void)converter_close(ctx, mdn_converter_u2l);
|
||||
free(ctx);
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
converter_close(mdn_converter_t ctx, mdn_converter_dir_t dir) {
|
||||
mdn_result_t st = mdn_success;
|
||||
|
||||
assert(ctx != NULL &&
|
||||
(dir == mdn_converter_l2u || dir == mdn_converter_u2l));
|
||||
|
||||
if (ctx->opened[dir]) {
|
||||
st = (*ctx->ops->close)(ctx, dir);
|
||||
if (st == mdn_success)
|
||||
ctx->opened[dir] = 0;
|
||||
}
|
||||
return (st);
|
||||
}
|
||||
|
||||
char *
|
||||
mdn_converter_localencoding(mdn_converter_t ctx) {
|
||||
assert(ctx != NULL);
|
||||
TRACE(("mdn_converter_localencoding()\n"));
|
||||
return (ctx->local_encoding_name);
|
||||
}
|
||||
|
||||
int
|
||||
mdn_converter_isasciicompatible(mdn_converter_t ctx) {
|
||||
assert(ctx != NULL);
|
||||
TRACE(("mdn_converter_isasciicompatible()\n"));
|
||||
return (ctx->ops->ascii_compatible);
|
||||
}
|
||||
|
||||
mdn_result_t
|
||||
mdn_converter_convert(mdn_converter_t ctx, mdn_converter_dir_t dir,
|
||||
const char *from, char *to, size_t tolen)
|
||||
{
|
||||
mdn_result_t r;
|
||||
|
||||
assert(ctx != NULL &&
|
||||
(dir == mdn_converter_l2u || dir == mdn_converter_u2l));
|
||||
|
||||
TRACE(("mdn_converter_convert(dir=%s,from=\"%s\")\n",
|
||||
dir == mdn_converter_l2u ? "l2u" : "u2l",
|
||||
from == NULL ? "(null)" : mdn_debug_xstring(from, 20)));
|
||||
|
||||
if (!ctx->opened[dir]) {
|
||||
mdn_result_t st = converter_open(ctx, dir);
|
||||
if (st != mdn_success)
|
||||
return (st);
|
||||
}
|
||||
|
||||
if (from == NULL) {
|
||||
/* for compatibility */
|
||||
INFO(("mdn_converter_convert: "
|
||||
"obsolete feature (reset) invoked\n"));
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
r = (*ctx->ops->convert)(ctx, dir, from, to, tolen);
|
||||
if (r == mdn_success && dir == mdn_converter_u2l &&
|
||||
(ctx->flags & MDN_CONVERTER_RTCHECK) != 0) {
|
||||
return (roundtrip_check(ctx, dir, from, to));
|
||||
}
|
||||
|
||||
return (r);
|
||||
}
|
||||
|
||||
/*
|
||||
* Encoding registration.
|
||||
*/
|
||||
|
||||
mdn_result_t
|
||||
mdn_converter_register(const char *name,
|
||||
mdn_converter_openproc_t open,
|
||||
mdn_converter_closeproc_t close,
|
||||
mdn_converter_convertproc_t convert,
|
||||
int ascii_compatible) {
|
||||
converter_ops_t *ops;
|
||||
mdn_result_t r;
|
||||
|
||||
assert(name != NULL && open != NULL && close != NULL &&
|
||||
convert != NULL);
|
||||
|
||||
TRACE(("mdn_converter_register(name=%s)\n", name));
|
||||
|
||||
if ((ops = malloc(sizeof(*ops))) == NULL) {
|
||||
WARNING(("mdn_converter_register: malloc failed\n"));
|
||||
return (mdn_nomemory);
|
||||
}
|
||||
ops->open = open;
|
||||
ops->close = close;
|
||||
ops->convert = convert;
|
||||
ops->ascii_compatible = ascii_compatible;
|
||||
|
||||
r = mdn_strhash_put(encoding_name_hash, name, ops);
|
||||
if (r != mdn_success)
|
||||
free(ops);
|
||||
|
||||
return (r);
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
register_standard_encoding(void) {
|
||||
mdn_result_t r;
|
||||
|
||||
r = mdn_converter_register(MDN_UTF5_ENCODING_NAME,
|
||||
converter_utf5_open,
|
||||
converter_utf5_close,
|
||||
converter_utf5_convert,
|
||||
1);
|
||||
if (r != mdn_success)
|
||||
return (r);
|
||||
|
||||
r = mdn_converter_register(MDN_RACE_ENCODING_NAME,
|
||||
mdn__race_open,
|
||||
mdn__race_close,
|
||||
mdn__race_convert,
|
||||
1);
|
||||
if (r != mdn_success)
|
||||
return (r);
|
||||
|
||||
r = mdn_converter_register(MDN_BRACE_ENCODING_NAME,
|
||||
mdn__brace_open,
|
||||
mdn__brace_close,
|
||||
mdn__brace_convert,
|
||||
1);
|
||||
if (r != mdn_success)
|
||||
return (r);
|
||||
|
||||
r = mdn_converter_register(MDN_LACE_ENCODING_NAME,
|
||||
mdn__lace_open,
|
||||
mdn__lace_close,
|
||||
mdn__lace_convert,
|
||||
1);
|
||||
if (r != mdn_success)
|
||||
return (r);
|
||||
|
||||
#ifdef DEBUG
|
||||
/* This is convenient for debug. Not useful for other purposes. */
|
||||
r = mdn_converter_register("U-escape",
|
||||
converter_uescape_open,
|
||||
converter_uescape_close,
|
||||
converter_uescape_convert,
|
||||
0);
|
||||
if (r != mdn_success)
|
||||
return (r);
|
||||
#endif /* DEBUG */
|
||||
|
||||
return (r);
|
||||
}
|
||||
|
||||
/*
|
||||
* Encoding alias support.
|
||||
*/
|
||||
|
||||
mdn_result_t
|
||||
mdn_converter_addalias(const char *alias_name, const char *real_name) {
|
||||
char *rn_copy;
|
||||
|
||||
assert(alias_name != NULL && real_name != NULL);
|
||||
|
||||
TRACE(("mdn_converter_addalias(alias_name=%s,real_name=%s)\n",
|
||||
alias_name, real_name));
|
||||
|
||||
if (strcmp(alias_name, real_name) == 0)
|
||||
return (mdn_success);
|
||||
|
||||
if (encoding_alias_hash == NULL)
|
||||
return (mdn_failure);
|
||||
|
||||
if ((rn_copy = malloc(strlen(real_name) + 1)) == NULL) {
|
||||
WARNING(("mdn_converter_addalias: malloc failed\n"));
|
||||
return (mdn_nomemory);
|
||||
}
|
||||
(void)strcpy(rn_copy, real_name);
|
||||
(void)mdn_strhash_put(encoding_alias_hash, alias_name, rn_copy);
|
||||
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
mdn_result_t
|
||||
mdn_converter_aliasfile(const char *path) {
|
||||
FILE *fp;
|
||||
int line_no;
|
||||
mdn_result_t st = mdn_success;
|
||||
char line[200], alias[200], real[200];
|
||||
|
||||
assert(path != NULL);
|
||||
|
||||
TRACE(("mdn_converter_aliasfile(path=%s)\n", path));
|
||||
|
||||
if ((fp = fopen(path, "r")) == NULL) {
|
||||
return (mdn_nofile);
|
||||
}
|
||||
for (line_no = 1; fgets(line, sizeof(line), fp) != NULL; line_no++) {
|
||||
unsigned char *p = (unsigned char *)line;
|
||||
|
||||
while (isascii(*p) && isspace(*p))
|
||||
p++;
|
||||
if (*p == '#' || *p == '\n')
|
||||
continue;
|
||||
if (sscanf((char *)p, "%s %s", alias, real) == 2) {
|
||||
st = mdn_converter_addalias(alias, real);
|
||||
if (st != mdn_success)
|
||||
break;
|
||||
} else {
|
||||
WARNING(("mdn_converter_aliasfile: file %s has "
|
||||
"invalid contents at line %d\n",
|
||||
path, line_no));
|
||||
st = mdn_invalid_syntax;
|
||||
break;
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
return st;
|
||||
}
|
||||
|
||||
mdn_result_t
|
||||
mdn_converter_resetalias(void) {
|
||||
mdn_strhash_t hash;
|
||||
mdn_result_t r;
|
||||
|
||||
TRACE(("mdn_converter_resetalias()\n"));
|
||||
|
||||
hash = encoding_alias_hash;
|
||||
encoding_alias_hash = NULL;
|
||||
mdn_strhash_destroy(hash, free_alias_value);
|
||||
hash = NULL;
|
||||
r = mdn_strhash_create(&hash);
|
||||
encoding_alias_hash = hash;
|
||||
return (r);
|
||||
}
|
||||
|
||||
static const char *
|
||||
get_realname(const char *name) {
|
||||
if (encoding_alias_hash != NULL) {
|
||||
char *realname;
|
||||
int recurse = 0;
|
||||
|
||||
while (recurse < MAX_RECURSE) {
|
||||
mdn_result_t r;
|
||||
|
||||
r = mdn_strhash_get(encoding_alias_hash,
|
||||
name, (void **)&realname);
|
||||
if (r != mdn_success)
|
||||
break;
|
||||
|
||||
name = realname;
|
||||
recurse++;
|
||||
}
|
||||
if (recurse >= MAX_RECURSE) {
|
||||
WARNING(("mdn_converter: encoding alias table has "
|
||||
"cyclic reference\n"));
|
||||
}
|
||||
}
|
||||
return (name);
|
||||
}
|
||||
|
||||
static void
|
||||
free_alias_value(void *value) {
|
||||
free(value);
|
||||
}
|
||||
|
||||
/*
|
||||
* Round trip check.
|
||||
*/
|
||||
|
||||
static mdn_result_t
|
||||
roundtrip_check(mdn_converter_t ctx, mdn_converter_dir_t dir,
|
||||
const char *from, const char *to)
|
||||
{
|
||||
/*
|
||||
* One problem with iconv() convertion is that
|
||||
* iconv() doesn't signal an error if the input
|
||||
* string contains characters which are valid but
|
||||
* do not have mapping to the output codeset.
|
||||
* (the behavior of iconv() for that case is defined as
|
||||
* `implementation dependent')
|
||||
* One way to check this case is to perform round-trip
|
||||
* conversion and see if it is same as the original string.
|
||||
*/
|
||||
mdn_result_t r;
|
||||
char *back_converted;
|
||||
char buf[256];
|
||||
size_t len;
|
||||
|
||||
TRACE(("mdn_converter_convert: round-trip checking ("
|
||||
" from=\"%s\")\n", mdn_debug_xstring(from, 20)));
|
||||
|
||||
/* Allocate enough buffer. */
|
||||
len = strlen(from) + 1;
|
||||
if (len <= sizeof(buf)) {
|
||||
back_converted = buf;
|
||||
len = sizeof(buf);
|
||||
} else {
|
||||
back_converted = malloc(len);
|
||||
if (back_converted == NULL)
|
||||
return (mdn_nomemory);
|
||||
}
|
||||
|
||||
/*
|
||||
* Perform backward conversion.
|
||||
*/
|
||||
if (dir == mdn_converter_l2u)
|
||||
dir = mdn_converter_u2l;
|
||||
else
|
||||
dir = mdn_converter_l2u;
|
||||
r = mdn_converter_convert(ctx, dir, to, back_converted, len);
|
||||
|
||||
switch (r) {
|
||||
case mdn_success:
|
||||
if (strcmp(back_converted, from) != 0)
|
||||
r = mdn_nomapping;
|
||||
break;
|
||||
case mdn_invalid_encoding:
|
||||
case mdn_buffer_overflow:
|
||||
r = mdn_nomapping;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (back_converted != buf)
|
||||
free(back_converted);
|
||||
|
||||
if (r != mdn_success) {
|
||||
TRACE(("round-trip check failed: %s\n",
|
||||
mdn_result_tostring(r)));
|
||||
}
|
||||
|
||||
return (r);
|
||||
}
|
||||
|
||||
/*
|
||||
* Identity conversion (or, no conversion at all).
|
||||
*/
|
||||
|
||||
/* ARGSUSED */
|
||||
static mdn_result_t
|
||||
converter_none_open(mdn_converter_t ctx, mdn_converter_dir_t dir) {
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
/* ARGSUSED */
|
||||
static mdn_result_t
|
||||
converter_none_close(mdn_converter_t ctx, mdn_converter_dir_t dir) {
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
converter_none_convert(mdn_converter_t ctx, mdn_converter_dir_t dir,
|
||||
const char *from, char *to, size_t tolen)
|
||||
{
|
||||
size_t fromlen;
|
||||
|
||||
assert(ctx != NULL &&
|
||||
(dir == mdn_converter_l2u || dir == mdn_converter_u2l));
|
||||
|
||||
/*
|
||||
* Just copying is not enough. We should at least check
|
||||
* the validity of 'from'.
|
||||
*/
|
||||
if (!mdn_utf8_isvalidstring(from))
|
||||
return (mdn_invalid_encoding);
|
||||
|
||||
fromlen = strlen(from) + 1; /* including NUL */
|
||||
if (fromlen > tolen)
|
||||
return (mdn_buffer_overflow);
|
||||
|
||||
(void)memcpy(to, from, fromlen); /* including NUL */
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Conversion using iconv() interface.
|
||||
*/
|
||||
|
||||
static mdn_result_t
|
||||
converter_iconv_open(mdn_converter_t ctx, mdn_converter_dir_t dir) {
|
||||
iconv_t ictx;
|
||||
|
||||
if (dir == mdn_converter_l2u) {
|
||||
ictx = iconv_open(MDN_UTF8_ENCODING_NAME,
|
||||
ctx->local_encoding_name);
|
||||
} else {
|
||||
ictx = iconv_open(ctx->local_encoding_name,
|
||||
MDN_UTF8_ENCODING_NAME);
|
||||
}
|
||||
ctx->ictx[dir] = ictx;
|
||||
if (ictx == (iconv_t)(-1)) {
|
||||
switch (errno) {
|
||||
case ENOMEM:
|
||||
return (mdn_nomemory);
|
||||
case EINVAL:
|
||||
return (mdn_invalid_name);
|
||||
default:
|
||||
WARNING(("iconv_open failed with errno %d\n", errno));
|
||||
return (mdn_failure);
|
||||
}
|
||||
}
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
converter_iconv_close(mdn_converter_t ctx, mdn_converter_dir_t dir) {
|
||||
assert(ctx != NULL &&
|
||||
(dir == mdn_converter_l2u || dir == mdn_converter_u2l));
|
||||
|
||||
if (ctx->opened[dir])
|
||||
(void)iconv_close(ctx->ictx[dir]);
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
converter_iconv_convert(mdn_converter_t ctx, mdn_converter_dir_t dir,
|
||||
const char *from, char *to, size_t tolen)
|
||||
{
|
||||
char *toorg = to;
|
||||
size_t sz;
|
||||
size_t fromsz;
|
||||
size_t tosz;
|
||||
char *p;
|
||||
|
||||
assert(ctx != NULL &&
|
||||
(dir == mdn_converter_l2u || dir == mdn_converter_u2l));
|
||||
|
||||
if (tolen <= 0)
|
||||
return (mdn_buffer_overflow); /* need space for NUL */
|
||||
|
||||
/*
|
||||
* For utf-8 -> local conversion, check the validity of
|
||||
* the input string.
|
||||
*/
|
||||
if (dir == mdn_converter_u2l && !mdn_utf8_isvalidstring(from)) {
|
||||
WARNING(("mdn_converter_convert: "
|
||||
"input is not a valid UTF-8 string\n"));
|
||||
return (mdn_invalid_encoding);
|
||||
}
|
||||
|
||||
/*
|
||||
* Reset internal state.
|
||||
*/
|
||||
#if 0
|
||||
(void)iconv(ctx->ictx[dir], (const char **)NULL, (size_t *)NULL,
|
||||
(char **)NULL, (size_t *)NULL);
|
||||
#else
|
||||
/*
|
||||
* Above code should work according to the spec, but causes
|
||||
* segmentation fault with Solaris 2.6.
|
||||
* So.. a work-around.
|
||||
*/
|
||||
fromsz = tosz = 0;
|
||||
p = NULL;
|
||||
(void)iconv(ctx->ictx[dir], (const char **)NULL,
|
||||
&fromsz, &p, &tosz);
|
||||
#endif
|
||||
|
||||
fromsz = strlen(from);
|
||||
tosz = tolen - 1; /* reserve space for terminating NUL */
|
||||
sz = iconv(ctx->ictx[dir], &from, &fromsz, &to, &tosz);
|
||||
|
||||
if (sz == (size_t)(-1) || fromsz > 0) {
|
||||
switch (errno) {
|
||||
case EILSEQ:
|
||||
case EINVAL:
|
||||
if (dir == mdn_converter_u2l) {
|
||||
/*
|
||||
* We already checked the validity of the
|
||||
* input string. So we assume a mapping
|
||||
* error.
|
||||
*/
|
||||
return (mdn_nomapping);
|
||||
} else {
|
||||
/*
|
||||
* We assume all the characters in the local
|
||||
* codeset are included in UCS. This means
|
||||
* mapping error is not possible, so the
|
||||
* input string must have some problem.
|
||||
*/
|
||||
return (mdn_invalid_encoding);
|
||||
}
|
||||
case E2BIG:
|
||||
return (mdn_buffer_overflow);
|
||||
default:
|
||||
return (mdn_failure);
|
||||
}
|
||||
}
|
||||
*to = '\0';
|
||||
|
||||
/*
|
||||
* For local -> utf-8 conversion, check the validity of the
|
||||
* output string.
|
||||
*/
|
||||
if (dir == mdn_converter_l2u && !mdn_utf8_isvalidstring(toorg)) {
|
||||
WARNING(("mdn_converter_convert: "
|
||||
"output is not a valid UTF-8 string\n"));
|
||||
return (mdn_invalid_encoding);
|
||||
}
|
||||
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
/*
|
||||
* Conversion to/from UTF-5.
|
||||
*/
|
||||
|
||||
/* ARGSUSED */
|
||||
static mdn_result_t
|
||||
converter_utf5_open(mdn_converter_t ctx, mdn_converter_dir_t dir) {
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
/* ARGSUSED */
|
||||
static mdn_result_t
|
||||
converter_utf5_close(mdn_converter_t ctx, mdn_converter_dir_t dir) {
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
converter_utf5_convert(mdn_converter_t ctx, mdn_converter_dir_t dir,
|
||||
const char *from, char *to, size_t tolen)
|
||||
{
|
||||
size_t fromlen = strlen(from);
|
||||
|
||||
if (dir == mdn_converter_l2u) {
|
||||
unsigned long v;
|
||||
int flen, tlen;
|
||||
|
||||
while (fromlen > 0) {
|
||||
flen = mdn_utf5_getwc(from, fromlen, &v);
|
||||
if (flen == 0) {
|
||||
WARNING(("mdn_converter_convert: "
|
||||
"invalid character\n"));
|
||||
return (mdn_invalid_encoding);
|
||||
}
|
||||
from += flen;
|
||||
fromlen -= flen;
|
||||
|
||||
tlen = mdn_utf8_putwc(to, tolen, v);
|
||||
if (tlen == 0)
|
||||
goto overflow;
|
||||
to += tlen;
|
||||
tolen -= tlen;
|
||||
}
|
||||
} else { /* mdn_converter_u2l */
|
||||
unsigned long v;
|
||||
int flen, tlen;
|
||||
|
||||
while (fromlen > 0) {
|
||||
flen = mdn_utf8_getwc(from, fromlen, &v);
|
||||
if (flen == 0) {
|
||||
WARNING(("mdn_converter_convert: "
|
||||
"invalid character\n"));
|
||||
return (mdn_invalid_encoding);
|
||||
}
|
||||
from += flen;
|
||||
fromlen -= flen;
|
||||
|
||||
tlen = mdn_utf5_putwc(to, tolen, v);
|
||||
if (tlen == 0)
|
||||
goto overflow;
|
||||
to += tlen;
|
||||
tolen -= tlen;
|
||||
}
|
||||
}
|
||||
if (tolen <= 0)
|
||||
goto overflow;
|
||||
|
||||
*to = '\0';
|
||||
return (mdn_success);
|
||||
|
||||
overflow:
|
||||
WARNING(("mdn_converter_convert: buffer overflow\n"));
|
||||
return (mdn_buffer_overflow);
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
/*
|
||||
* Conversion to/from unicode escape string.
|
||||
* Arbitrary UCS-4 character can be specified by a special sequence
|
||||
* \u{XXXXXX}
|
||||
* where XXXXX denotes any hexadecimal string up to FFFFFFFF.
|
||||
* This is designed for debugging.
|
||||
*/
|
||||
|
||||
static int uescape_getwc(const char *from, size_t fromlen,
|
||||
unsigned long *vp);
|
||||
static int uescape_putwc(char *to, size_t tolen, unsigned long v);
|
||||
|
||||
/* ARGSUSED */
|
||||
static mdn_result_t
|
||||
converter_uescape_open(mdn_converter_t ctx, mdn_converter_dir_t dir) {
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
/* ARGSUSED */
|
||||
static mdn_result_t
|
||||
converter_uescape_close(mdn_converter_t ctx, mdn_converter_dir_t dir) {
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
converter_uescape_convert(mdn_converter_t ctx, mdn_converter_dir_t dir,
|
||||
const char *from, char *to, size_t tolen)
|
||||
{
|
||||
size_t fromlen = strlen(from);
|
||||
|
||||
if (dir == mdn_converter_l2u) {
|
||||
unsigned long v;
|
||||
int flen, tlen;
|
||||
|
||||
while (fromlen > 0) {
|
||||
flen = uescape_getwc(from, fromlen, &v);
|
||||
if (flen == 0) {
|
||||
WARNING(("mdn_converter_convert: "
|
||||
"invalid character\n"));
|
||||
return (mdn_invalid_encoding);
|
||||
}
|
||||
from += flen;
|
||||
fromlen -= flen;
|
||||
|
||||
tlen = mdn_utf8_putwc(to, tolen, v);
|
||||
if (tlen == 0)
|
||||
goto overflow;
|
||||
to += tlen;
|
||||
tolen -= tlen;
|
||||
}
|
||||
} else { /* mdn_converter_u2l */
|
||||
unsigned long v;
|
||||
int flen, tlen;
|
||||
|
||||
while (fromlen > 0) {
|
||||
flen = mdn_utf8_getwc(from, fromlen, &v);
|
||||
if (flen == 0) {
|
||||
WARNING(("mdn_converter_convert: "
|
||||
"invalid character\n"));
|
||||
return (mdn_invalid_encoding);
|
||||
}
|
||||
from += flen;
|
||||
fromlen -= flen;
|
||||
|
||||
tlen = uescape_putwc(to, tolen, v);
|
||||
if (tlen == 0)
|
||||
goto overflow;
|
||||
to += tlen;
|
||||
tolen -= tlen;
|
||||
}
|
||||
}
|
||||
if (tolen <= 0)
|
||||
goto overflow;
|
||||
|
||||
*to = '\0';
|
||||
return (mdn_success);
|
||||
|
||||
overflow:
|
||||
WARNING(("mdn_converter_convert: buffer overflow\n"));
|
||||
return (mdn_buffer_overflow);
|
||||
}
|
||||
|
||||
static int
|
||||
uescape_getwc(const char *from, size_t fromlen, unsigned long *vp) {
|
||||
char *end;
|
||||
if (fromlen >= 4 && strncmp(from, "\\u{", 3) == 0 &&
|
||||
(end = memchr(from, '}', fromlen)) != NULL &&
|
||||
end - from <= 3 + 8) { /* '\u{' + 'xxxxxxxx' */
|
||||
int len = end - from - 3;
|
||||
char tmp[9];
|
||||
|
||||
(void)memcpy(tmp, from + 3, len);
|
||||
tmp[len] = '\0';
|
||||
*vp = strtoul(tmp, NULL, 16);
|
||||
return (end + 1 - from);
|
||||
} else if (fromlen > 0) {
|
||||
*vp = (unsigned char)from[0];
|
||||
return (1);
|
||||
} else {
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
uescape_putwc(char *to, size_t tolen, unsigned long v) {
|
||||
if (v <= 0x7f) {
|
||||
if (tolen < 1)
|
||||
return (0);
|
||||
*to = v;
|
||||
return (1);
|
||||
} else if (v <= 0xffffffff) {
|
||||
char tmp[20];
|
||||
int len;
|
||||
|
||||
(void)sprintf(tmp, "\\u{%lx}", v);
|
||||
len = strlen(tmp);
|
||||
if (tolen < len)
|
||||
return (0);
|
||||
(void)memcpy(to, tmp, len);
|
||||
return (len);
|
||||
} else {
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
180
contrib/idn/mdnkit/lib/debug.c
Normal file
180
contrib/idn/mdnkit/lib/debug.c
Normal file
|
|
@ -0,0 +1,180 @@
|
|||
#ifndef lint
|
||||
static char *rcsid = "$Id: debug.c,v 1.6 2000/07/04 03:52:36 ishisone Exp $";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <mdn/debug.h>
|
||||
|
||||
static char *hex = "0123456789abcdef";
|
||||
|
||||
char *
|
||||
mdn_debug_hexstring(const char *s, int maxbytes) {
|
||||
int i;
|
||||
char *p;
|
||||
static char buf[256 * 3 + 3 + 1]; /* +3 for "..." */
|
||||
|
||||
if (maxbytes > 256)
|
||||
maxbytes = 256;
|
||||
|
||||
for (i = 0, p = buf; i < maxbytes; i++) {
|
||||
int c = ((unsigned char *)s)[i];
|
||||
|
||||
if (c == '\0')
|
||||
break;
|
||||
*p++ = hex[c >> 4];
|
||||
*p++ = hex[c & 15];
|
||||
*p++ = ' ';
|
||||
}
|
||||
|
||||
if (i >= maxbytes)
|
||||
(void)strcpy(p, "...");
|
||||
else
|
||||
*p = '\0';
|
||||
|
||||
return (buf);
|
||||
}
|
||||
|
||||
char *
|
||||
mdn_debug_xstring(const char *s, int maxbytes) {
|
||||
int i;
|
||||
char *p;
|
||||
static char buf[256 * 4 + 3 + 1]; /* +3 for "..." */
|
||||
|
||||
if (maxbytes > 256)
|
||||
maxbytes = 256;
|
||||
|
||||
for (i = 0, p = buf; i < maxbytes; i++) {
|
||||
int c = ((unsigned char *)s)[i];
|
||||
|
||||
if (c == '\0') {
|
||||
break;
|
||||
} else if (c < 0x20 || c > 0x7e) {
|
||||
*p++ = '\\';
|
||||
*p++ = 'x';
|
||||
*p++ = hex[c >> 4];
|
||||
*p++ = hex[c & 15];
|
||||
} else {
|
||||
*p++ = c;
|
||||
}
|
||||
}
|
||||
|
||||
if (i >= maxbytes)
|
||||
(void)strcpy(p, "...");
|
||||
else
|
||||
*p = '\0';
|
||||
|
||||
return (buf);
|
||||
}
|
||||
|
||||
char *
|
||||
mdn_debug_hexdata(const char *s, int length, int maxlength) {
|
||||
int i;
|
||||
const unsigned char *p = (const unsigned char *)s;
|
||||
char *q;
|
||||
static char buf[256 * 3 + 3 + 1]; /* +3 for "..." */
|
||||
char *cont = NULL;
|
||||
|
||||
if (maxlength > 256)
|
||||
maxlength = 256;
|
||||
|
||||
if (length > maxlength) {
|
||||
length = maxlength;
|
||||
cont = "...";
|
||||
}
|
||||
|
||||
for (i = 0, q = buf; i < length; i++) {
|
||||
int c = p[i];
|
||||
|
||||
*q++ = hex[c >> 4];
|
||||
*q++ = hex[c & 15];
|
||||
*q++ = ' ';
|
||||
}
|
||||
|
||||
if (cont != NULL)
|
||||
(void)strcpy(q, "...");
|
||||
else
|
||||
*q = '\0';
|
||||
|
||||
return (buf);
|
||||
}
|
||||
|
||||
void
|
||||
mdn_debug_hexdump(const char *s, int length) {
|
||||
int i;
|
||||
const unsigned char *p = (const unsigned char *)s;
|
||||
|
||||
i = 0;
|
||||
while (length-- > 0) {
|
||||
if (i % 16 == 0) {
|
||||
if (i > 0)
|
||||
fprintf(stderr, "\n");
|
||||
fprintf(stderr, "%4x:", i);
|
||||
}
|
||||
fprintf(stderr, " %02x", p[i]);
|
||||
i++;
|
||||
}
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
341
contrib/idn/mdnkit/lib/dn.c
Normal file
341
contrib/idn/mdnkit/lib/dn.c
Normal file
|
|
@ -0,0 +1,341 @@
|
|||
#ifndef lint
|
||||
static char *rcsid = "$Id: dn.c,v 1.8 2000/09/20 02:47:31 ishisone Exp $";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Domain name compression/expansion.
|
||||
*
|
||||
* Similar to the functionality of dn_comp/dn_expand in the resolv library.
|
||||
* In fact, the loop detection in mdn__dn_expand is borrowed from
|
||||
* ns_name_unpack.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <mdn/result.h>
|
||||
#include <mdn/assert.h>
|
||||
#include <mdn/logmacro.h>
|
||||
#include <mdn/dn.h>
|
||||
|
||||
#define COMPRESS_MASK 0xc0
|
||||
#define COMPRESS_FLAG 0xc0
|
||||
#define MAX_OFFSET 0x3fff
|
||||
|
||||
#define MAXNAMELEN 1024
|
||||
#define MAXLABEL 63
|
||||
#define MAXCOMPRESS 255
|
||||
|
||||
/*
|
||||
* uppercase -> lowercase conversion table, to be initialized
|
||||
* by init_lcase().
|
||||
*/
|
||||
static char lcase[128];
|
||||
|
||||
static mdn_result_t split_name(const char *name, unsigned char *namebuf);
|
||||
static int find_label(const unsigned char *p, int limit,
|
||||
mdn__dn_t *ctx);
|
||||
static int match(const unsigned char *p, const unsigned char *q,
|
||||
mdn__dn_t *ctx);
|
||||
static void append_ptr(mdn__dn_t *ctx, unsigned char *ptr);
|
||||
static int get_offset(const unsigned char *p);
|
||||
static void init_lcase(void);
|
||||
|
||||
|
||||
mdn_result_t
|
||||
mdn__dn_expand(const char *msg, size_t msglen, const char *compressed,
|
||||
char *expanded, size_t buflen, size_t *complenp)
|
||||
{
|
||||
const unsigned char *p = (const unsigned char *)compressed;
|
||||
const unsigned char *ueom = (const unsigned char *)(msg + msglen);
|
||||
int compress_len = 0;
|
||||
size_t checked = 0;
|
||||
|
||||
assert(msg != NULL && expanded != NULL && complenp != NULL);
|
||||
|
||||
/*
|
||||
* Sanity check.
|
||||
*/
|
||||
if (compressed < msg || msg + msglen <= compressed)
|
||||
return (mdn_invalid_message);
|
||||
|
||||
if (*p == 0) {
|
||||
/* Root label */
|
||||
if (buflen < 2)
|
||||
return (mdn_buffer_overflow);
|
||||
(void)strcpy(expanded, ".");
|
||||
*complenp = 1;
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
while (p < ueom) {
|
||||
int c = *p++;
|
||||
size_t len;
|
||||
|
||||
len = c & ~COMPRESS_MASK;
|
||||
|
||||
if (c == 0) {
|
||||
if (compress_len == 0)
|
||||
compress_len = (const char *)p - compressed;
|
||||
*complenp = compress_len;
|
||||
return (mdn_success);
|
||||
} else if ((c & COMPRESS_MASK) == 0) {
|
||||
if (p + len > ueom)
|
||||
return (mdn_invalid_message);
|
||||
if (buflen < len + 2)
|
||||
return (mdn_buffer_overflow);
|
||||
(void)memcpy(expanded, p, len);
|
||||
(void)strcpy(expanded + len, "."); /* dot and NUL */
|
||||
p += len;
|
||||
checked += len + 1;
|
||||
expanded += len + 1;
|
||||
buflen -= len + 1;
|
||||
} else if ((c & COMPRESS_MASK) == COMPRESS_FLAG) {
|
||||
if (p >= ueom)
|
||||
return (mdn_invalid_message);
|
||||
len = (len << 8) + *p++;
|
||||
if (compress_len == 0)
|
||||
compress_len = (const char *)p - compressed;
|
||||
p = (const unsigned char *)(msg + len);
|
||||
|
||||
/*
|
||||
* Loop detection.
|
||||
*/
|
||||
checked += 2;
|
||||
if (checked >= msglen) {
|
||||
WARNING(("mdn__dn_expand: loop detected\n"));
|
||||
return (mdn_invalid_message);
|
||||
}
|
||||
} else {
|
||||
return (mdn_invalid_message);
|
||||
}
|
||||
}
|
||||
return (mdn_invalid_message);
|
||||
}
|
||||
|
||||
void
|
||||
mdn__dn_initcompress(mdn__dn_t *ctx, const char *msg) {
|
||||
ctx->msg = (const unsigned char *)msg;
|
||||
ctx->cur = 0;
|
||||
}
|
||||
|
||||
mdn_result_t
|
||||
mdn__dn_compress(const char *name, char *sptr, size_t length,
|
||||
mdn__dn_t *ctx, size_t *complenp)
|
||||
{
|
||||
unsigned char namebuf[MAXNAMELEN+1];
|
||||
unsigned char *ptr, *p;
|
||||
mdn_result_t r;
|
||||
int offset_limit;
|
||||
static int initialized = 0;
|
||||
|
||||
if (!initialized) {
|
||||
init_lcase();
|
||||
initialized = 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Split domain name into labels.
|
||||
*/
|
||||
if ((r = split_name(name, namebuf)) != mdn_success)
|
||||
return (r);
|
||||
|
||||
p = namebuf;
|
||||
ptr = (unsigned char *)sptr;
|
||||
offset_limit = ctx->cur;
|
||||
while (*p != 0) {
|
||||
int off;
|
||||
|
||||
if ((off = find_label(p, offset_limit, ctx)) >= 0) {
|
||||
if (length < 2)
|
||||
return (mdn_buffer_overflow);
|
||||
|
||||
ptr[0] = COMPRESS_FLAG | (off >> 8);
|
||||
ptr[1] = off & 0xff;
|
||||
ptr += 2;
|
||||
if ((*complenp = (char *)ptr - sptr) > MAXCOMPRESS)
|
||||
return (mdn_invalid_name);
|
||||
return (mdn_success);
|
||||
} else {
|
||||
int l = *p + 1;
|
||||
|
||||
if (length < l)
|
||||
return (mdn_buffer_overflow);
|
||||
|
||||
(void)memcpy(ptr, p, l);
|
||||
append_ptr(ctx, ptr);
|
||||
|
||||
ptr += l;
|
||||
length -= l;
|
||||
}
|
||||
p += *p + 1;
|
||||
}
|
||||
if (length < 1)
|
||||
return (mdn_buffer_overflow);
|
||||
*ptr++ = 0;
|
||||
if ((*complenp = (char *)ptr - sptr) > MAXCOMPRESS)
|
||||
return (mdn_invalid_name);
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
split_name(const char *name, unsigned char *namebuf) {
|
||||
const unsigned char *p = (const unsigned char *)name;
|
||||
const unsigned char *end = p + MAXNAMELEN;
|
||||
unsigned char *q, *qtop;
|
||||
|
||||
q = namebuf;
|
||||
qtop = q++;
|
||||
while (p < end) {
|
||||
if (*p == '.' || *p == '\0') {
|
||||
int len = q - qtop - 1;
|
||||
if (len > MAXLABEL)
|
||||
return (mdn_invalid_name);
|
||||
*qtop = len;
|
||||
qtop = q++;
|
||||
if (*p == '\0') {
|
||||
*qtop = 0;
|
||||
return (mdn_success);
|
||||
}
|
||||
p++;
|
||||
} else {
|
||||
*q++ = *p++;
|
||||
}
|
||||
}
|
||||
/* Name too long. */
|
||||
return (mdn_invalid_name);
|
||||
}
|
||||
|
||||
static int
|
||||
find_label(const unsigned char *p, int limit, mdn__dn_t *ctx) {
|
||||
int i;
|
||||
|
||||
assert(limit <= ctx->cur);
|
||||
|
||||
if (ctx == NULL)
|
||||
return (-1);
|
||||
|
||||
for (i = 0; i < limit; i++) {
|
||||
if (match(p, ctx->msg + ctx->offset[i], ctx))
|
||||
return (ctx->offset[i]);
|
||||
}
|
||||
return (-1);
|
||||
}
|
||||
|
||||
static int
|
||||
match(const unsigned char *p, const unsigned char *q, mdn__dn_t *ctx) {
|
||||
for (;;) {
|
||||
int len, l;
|
||||
|
||||
/* Dereference 'q'. */
|
||||
while ((*q & COMPRESS_FLAG) != 0) {
|
||||
int offset = get_offset(q);
|
||||
|
||||
if (offset < 0 || offset > MAX_OFFSET)
|
||||
return (0);
|
||||
q = ctx->msg + offset;
|
||||
}
|
||||
|
||||
/* Check length. */
|
||||
len = *p++;
|
||||
if (*q++ != len)
|
||||
return (0);
|
||||
|
||||
if (len == 0)
|
||||
return (1);
|
||||
|
||||
/* Compare labels. */
|
||||
for (l = 0; l < len; l++, p++, q++) {
|
||||
if (*p == *q)
|
||||
continue;
|
||||
else if (*p < 128 && *q < 128 &&
|
||||
lcase[*p] == lcase[*q])
|
||||
continue;
|
||||
else
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
append_ptr(mdn__dn_t *ctx, unsigned char *ptr) {
|
||||
if (ctx != NULL && ctx->cur < MDN_DN_NPTRS &&
|
||||
ptr >= ctx->msg && (ptr - ctx->msg) <= MAX_OFFSET)
|
||||
ctx->offset[ctx->cur++] = ptr - ctx->msg;
|
||||
}
|
||||
|
||||
static int
|
||||
get_offset(const unsigned char *p) {
|
||||
return (((p[0] & ~COMPRESS_MASK) << 8) | p[1]);
|
||||
}
|
||||
|
||||
static void
|
||||
init_lcase(void) {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 128; i++)
|
||||
lcase[i] = i;
|
||||
for (i = 'A'; i <= 'Z'; i++)
|
||||
lcase[i] += 'a' - 'A';
|
||||
}
|
||||
570
contrib/idn/mdnkit/lib/lace.c
Normal file
570
contrib/idn/mdnkit/lib/lace.c
Normal file
|
|
@ -0,0 +1,570 @@
|
|||
#ifndef lint
|
||||
static char *rcsid = "$Id: lace.c,v 1.4 2000/11/22 01:52:18 ishisone Exp $";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <mdn/result.h>
|
||||
#include <mdn/assert.h>
|
||||
#include <mdn/logmacro.h>
|
||||
#include <mdn/converter.h>
|
||||
#include <mdn/utf8.h>
|
||||
#include <mdn/debug.h>
|
||||
#include <mdn/lace.h>
|
||||
#include <mdn/util.h>
|
||||
|
||||
#ifdef DEBUG
|
||||
/* Be paranoid. */
|
||||
#define PARANOID
|
||||
#endif
|
||||
|
||||
#ifndef MDN_LACE_PREFIX
|
||||
#define MDN_LACE_PREFIX "bq--"
|
||||
#endif
|
||||
#define LACE_PREFIX_LEN (strlen(MDN_LACE_PREFIX))
|
||||
|
||||
#define LACE_BUF_SIZE 128 /* more than enough */
|
||||
|
||||
static mdn_result_t lace_l2u(const char *from, const char *end,
|
||||
char *to, size_t tolen, size_t *clenp);
|
||||
static mdn_result_t lace_u2l(const char *from, const char *end,
|
||||
char *to, size_t tolen, size_t *clenp);
|
||||
static mdn_result_t lace_decode(const char *from, size_t fromlen,
|
||||
char *to, size_t tolen);
|
||||
static mdn_result_t lace_decode_utf16(const char *from, size_t fromlen,
|
||||
unsigned short *buf, size_t *lenp);
|
||||
static mdn_result_t lace_encode(const char *from, size_t fromlen,
|
||||
char *to, size_t tolen);
|
||||
static mdn_result_t lace_encode_utf16(const unsigned short *p,
|
||||
size_t len, char *to, size_t tolen,
|
||||
int compress);
|
||||
static int is_compress_effective(unsigned short *p, size_t len);
|
||||
|
||||
/* ARGSUSED */
|
||||
mdn_result_t
|
||||
mdn__lace_open(mdn_converter_t ctx, mdn_converter_dir_t dir) {
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
/* ARGSUSED */
|
||||
mdn_result_t
|
||||
mdn__lace_close(mdn_converter_t ctx, mdn_converter_dir_t dir) {
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
mdn_result_t
|
||||
mdn__lace_convert(mdn_converter_t ctx, mdn_converter_dir_t dir,
|
||||
const char *from, char *toorg, size_t tolen)
|
||||
{
|
||||
char *to = toorg;
|
||||
|
||||
assert(ctx != NULL &&
|
||||
(dir == mdn_converter_l2u || dir == mdn_converter_u2l));
|
||||
|
||||
TRACE(("mdn__lace_convert(dir=%s,from=\"%s\")\n",
|
||||
dir == mdn_converter_l2u ? "l2u" : "u2l",
|
||||
mdn_debug_xstring(from, 20)));
|
||||
|
||||
for (;;) {
|
||||
const char *end;
|
||||
size_t convlen;
|
||||
mdn_result_t r;
|
||||
|
||||
/*
|
||||
* Find the end of this component (label).
|
||||
*/
|
||||
if ((end = strchr(from, '.')) == NULL)
|
||||
end = from + strlen(from);
|
||||
|
||||
/*
|
||||
* Convert it.
|
||||
*/
|
||||
if (dir == mdn_converter_l2u)
|
||||
r = lace_l2u(from, end, to, tolen, &convlen);
|
||||
else
|
||||
r = lace_u2l(from, end, to, tolen, &convlen);
|
||||
if (r != mdn_success)
|
||||
return (r);
|
||||
|
||||
/*
|
||||
* Copy '.' or NUL.
|
||||
*/
|
||||
if (tolen <= convlen)
|
||||
return (mdn_buffer_overflow);
|
||||
|
||||
to += convlen;
|
||||
*to++ = *end;
|
||||
tolen -= convlen + 1;
|
||||
|
||||
if (*end == '\0')
|
||||
break;
|
||||
|
||||
from = end + 1;
|
||||
}
|
||||
|
||||
DUMP(("mdn__lace_convert: \"%s\"\n", mdn_debug_xstring(toorg, 70)));
|
||||
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
lace_l2u(const char *from, const char *end,
|
||||
char *to, size_t tolen, size_t *clenp)
|
||||
{
|
||||
size_t len = end - from;
|
||||
size_t prefix_len = LACE_PREFIX_LEN;
|
||||
|
||||
if (len >= prefix_len &&
|
||||
mdn_util_casematch(from, MDN_LACE_PREFIX, prefix_len)) {
|
||||
/*
|
||||
* LACE encoding prefix found.
|
||||
*/
|
||||
mdn_result_t r;
|
||||
|
||||
r = lace_decode(from + prefix_len,
|
||||
len - prefix_len, to, tolen);
|
||||
if (r == mdn_invalid_encoding)
|
||||
goto copy;
|
||||
else if (r != mdn_success)
|
||||
return (r);
|
||||
|
||||
len = strlen(to);
|
||||
} else {
|
||||
/*
|
||||
* Not LACE encoded. Copy verbatim.
|
||||
*/
|
||||
copy:
|
||||
if (mdn_util_domainspan(from, end) < end) {
|
||||
/* invalid character found */
|
||||
return (mdn_invalid_encoding);
|
||||
}
|
||||
|
||||
if (tolen < len)
|
||||
return (mdn_buffer_overflow);
|
||||
|
||||
(void)memcpy(to, from, len);
|
||||
}
|
||||
*clenp = len;
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
lace_u2l(const char *from, const char *end,
|
||||
char *to, size_t tolen, size_t *clenp) {
|
||||
size_t len = end - from;
|
||||
size_t prefix_len = LACE_PREFIX_LEN;
|
||||
|
||||
/*
|
||||
* See if encoding is necessary.
|
||||
*/
|
||||
if (mdn_util_domainspan(from, end) < end) {
|
||||
/*
|
||||
* Conversion is necessary.
|
||||
*/
|
||||
mdn_result_t r;
|
||||
|
||||
/* Set prefix. */
|
||||
if (tolen < prefix_len)
|
||||
return (mdn_buffer_overflow);
|
||||
(void)memcpy(to, MDN_LACE_PREFIX, prefix_len);
|
||||
to += prefix_len;
|
||||
tolen -= prefix_len;
|
||||
|
||||
r = lace_encode(from, len, to, tolen);
|
||||
if (r != mdn_success)
|
||||
return (r);
|
||||
|
||||
len = prefix_len + strlen(to);
|
||||
} else {
|
||||
/*
|
||||
* Conversion is NOT necessary.
|
||||
* Copy verbatim.
|
||||
*/
|
||||
if (tolen < len)
|
||||
return (mdn_buffer_overflow);
|
||||
|
||||
(void)memcpy(to, from, len);
|
||||
}
|
||||
*clenp = len;
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
lace_decode(const char *from, size_t fromlen, char *to, size_t tolen) {
|
||||
unsigned short *buf;
|
||||
unsigned short local_buf[LACE_BUF_SIZE];
|
||||
size_t len, reslen;
|
||||
mdn_result_t r;
|
||||
|
||||
/*
|
||||
* Allocate sufficient buffer.
|
||||
*/
|
||||
if (fromlen > LACE_BUF_SIZE) {
|
||||
if ((buf = malloc(sizeof(*buf) * fromlen)) == NULL)
|
||||
return (mdn_nomemory);
|
||||
} else {
|
||||
/* Use local buffer. */
|
||||
buf = local_buf;
|
||||
}
|
||||
|
||||
/*
|
||||
* Decode base32 and decompress.
|
||||
*/
|
||||
r = lace_decode_utf16(from, fromlen, buf, &len);
|
||||
if (r != mdn_success)
|
||||
goto ret;
|
||||
|
||||
/*
|
||||
* Now 'buf' holds the decompressed string, which must contain
|
||||
* UTF-16 characters. Convert them into UTF-8.
|
||||
*/
|
||||
r = mdn_util_utf16toutf8(buf, len, to, tolen, &reslen);
|
||||
if (r != mdn_success)
|
||||
goto ret;
|
||||
|
||||
/*
|
||||
* Terminate with NUL.
|
||||
*/
|
||||
if (tolen <= reslen) {
|
||||
r = mdn_buffer_overflow;
|
||||
goto ret;
|
||||
}
|
||||
|
||||
to += reslen;
|
||||
*to = '\0';
|
||||
tolen -= reslen;
|
||||
|
||||
r = mdn_success;
|
||||
|
||||
ret:
|
||||
if (buf != local_buf)
|
||||
free(buf);
|
||||
return (r);
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
lace_decode_utf16(const char *from, size_t fromlen,
|
||||
unsigned short *buf, size_t *lenp)
|
||||
{
|
||||
unsigned short *p, *q;
|
||||
unsigned int bitbuf = 0;
|
||||
int bitlen = 0;
|
||||
size_t len;
|
||||
|
||||
/*
|
||||
* Decode Base32 and put the result bytes to 'buf'.
|
||||
* Since decoded string will be shorter in length, and
|
||||
* the caller allocated 'buf' so that its length is not
|
||||
* less than 'fromlen', we don't have to worry about overflow.
|
||||
*/
|
||||
p = buf;
|
||||
while (fromlen-- > 0) {
|
||||
int c = *from++;
|
||||
int x;
|
||||
|
||||
if ('a' <= c && c <= 'z')
|
||||
x = c - 'a';
|
||||
else if ('A' <= c && c <= 'Z')
|
||||
x = c - 'A';
|
||||
else if ('2' <= c && c <= '7')
|
||||
x = c - '2' + 26;
|
||||
else
|
||||
return (mdn_invalid_encoding);
|
||||
|
||||
bitbuf = (bitbuf << 5) + x;
|
||||
bitlen += 5;
|
||||
if (bitlen >= 8) {
|
||||
*p++ = (bitbuf >> (bitlen - 8)) & 0xff;
|
||||
bitlen -= 8;
|
||||
}
|
||||
}
|
||||
#ifdef PARANOID
|
||||
/* Check if the padding bits are all zero. */
|
||||
if (bitlen > 0 && (bitbuf & ((1 << bitlen) - 1)) != 0) {
|
||||
WARNING(("mdn__lace_convert: non-zero padding\n"));
|
||||
return (mdn_invalid_encoding);
|
||||
}
|
||||
#endif
|
||||
len = p - buf;
|
||||
|
||||
if (len == 0)
|
||||
return (mdn_invalid_encoding);
|
||||
|
||||
/*
|
||||
* Now 'buf' holds the decoded bytes. Rebuild the
|
||||
* original UTF-16 string.
|
||||
*/
|
||||
if (buf[0] == 0xff) {
|
||||
/*
|
||||
* Not compressed.
|
||||
*/
|
||||
len--; /* skip first byte (0xff) */
|
||||
if (len % 2 != 0) {
|
||||
/* number of bytes must be even. */
|
||||
return (mdn_invalid_encoding);
|
||||
}
|
||||
for (p = buf + 1, q = buf; len > 0; p += 2, q++, len -= 2) {
|
||||
*q = (p[0] << 8) | p[1];
|
||||
}
|
||||
#ifdef PARANOID
|
||||
if (is_compress_effective(buf, q - buf)) {
|
||||
/*
|
||||
* This string must have been compressed.
|
||||
*/
|
||||
WARNING(("mdn__lace_convert: decoded string is not "
|
||||
"compressed, though it should be.\n"));
|
||||
return (mdn_invalid_encoding);
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
/*
|
||||
* Compressed.
|
||||
*/
|
||||
int count = 0;
|
||||
unsigned short high = 0; /* initialize for lint */
|
||||
|
||||
for (p = q = buf; len > 0; p++, q++, len--) {
|
||||
if (count == 0) {
|
||||
if (len < 3 || p[0] == 0)
|
||||
return (mdn_invalid_encoding);
|
||||
/* Get COUNT and HIGH. */
|
||||
count = p[0];
|
||||
high = p[1] << 8;
|
||||
p += 2;
|
||||
len -= 2;
|
||||
}
|
||||
*q = high | *p;
|
||||
count--;
|
||||
}
|
||||
if (count != 0)
|
||||
return (mdn_invalid_encoding);
|
||||
#ifdef PARANOID
|
||||
if (!is_compress_effective(buf, q - buf)) {
|
||||
/*
|
||||
* This string must not have been compressed.
|
||||
*/
|
||||
WARNING(("mdn__lace_convert: decoded string is "
|
||||
"compressed, though it shouldn't.\n"));
|
||||
return (mdn_invalid_encoding);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
*lenp = q - buf;
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
lace_encode(const char *from, size_t fromlen, char *to, size_t tolen) {
|
||||
unsigned short *buf;
|
||||
unsigned short local_buf[LACE_BUF_SIZE]; /* UTF-16 */
|
||||
mdn_result_t r;
|
||||
size_t buflen, len;
|
||||
|
||||
/*
|
||||
* Convert to UTF-16.
|
||||
*/
|
||||
buf = local_buf;
|
||||
buflen = LACE_BUF_SIZE;
|
||||
for (;;) {
|
||||
r = mdn_util_utf8toutf16(from, fromlen,
|
||||
buf, buflen, &len);
|
||||
if (r == mdn_buffer_overflow) {
|
||||
buflen *= 2;
|
||||
if (buf == local_buf)
|
||||
buf = malloc(sizeof(*buf) * buflen);
|
||||
else
|
||||
buf = realloc(buf, sizeof(*buf) * buflen);
|
||||
if (buf == NULL)
|
||||
return (mdn_nomemory);
|
||||
} else if (r == mdn_success) {
|
||||
break;
|
||||
} else {
|
||||
goto ret;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Compress, encode in base-32 and output.
|
||||
*/
|
||||
r = lace_encode_utf16(buf, len, to, tolen,
|
||||
is_compress_effective(buf, len));
|
||||
|
||||
ret:
|
||||
if (buf != local_buf)
|
||||
free(buf);
|
||||
return (r);
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
lace_encode_utf16(const unsigned short *p, size_t len,
|
||||
char *to, size_t tolen, int compress)
|
||||
{
|
||||
unsigned long bitbuf = 0; /* bit stream buffer */
|
||||
int bitlen = 0; /* # of bits in 'bitbuf' */
|
||||
int compress_count = 0;
|
||||
int i, j;
|
||||
|
||||
if (!compress) {
|
||||
/* prepend non-compression mark */
|
||||
bitbuf = 0xff;
|
||||
bitlen = 8;
|
||||
}
|
||||
|
||||
for (i = 0; i <= len; i++) {
|
||||
if (i == len) {
|
||||
/*
|
||||
* End of data. Flush. The current draft (-00)
|
||||
* doesn't seem to define which value to use for
|
||||
* padding (which it should). We assume zero.
|
||||
*/
|
||||
if (bitlen % 5 == 0)
|
||||
break;
|
||||
bitbuf <<= 5 - (bitlen % 5); /* padding with zero */
|
||||
bitlen += 5 - (bitlen % 5);
|
||||
} else if (compress) {
|
||||
if (compress_count == 0) {
|
||||
/*
|
||||
* Get the number of consecutive characters
|
||||
* with the same high byte.
|
||||
*/
|
||||
unsigned short high = p[i] & 0xff00;
|
||||
|
||||
compress_count = 1;
|
||||
for (j = i + 1; j < len; j++) {
|
||||
if ((p[j] & 0xff00) != high)
|
||||
break;
|
||||
compress_count++;
|
||||
}
|
||||
bitbuf = (bitbuf << 16) |
|
||||
(compress_count << 8) |
|
||||
(high >> 8);
|
||||
bitlen += 16;
|
||||
}
|
||||
bitbuf = (bitbuf << 8) | (p[i] & 0xff);
|
||||
bitlen += 8;
|
||||
compress_count--;
|
||||
} else {
|
||||
bitbuf = (bitbuf << 16) | p[i];
|
||||
bitlen += 16;
|
||||
}
|
||||
|
||||
/*
|
||||
* Output bits in 'bitbuf' in 5-bit unit.
|
||||
*/
|
||||
while (bitlen >= 5) {
|
||||
int x;
|
||||
|
||||
/* Get top 5 bits. */
|
||||
x = (bitbuf >> (bitlen - 5)) & 0x1f;
|
||||
bitlen -= 5;
|
||||
|
||||
/* Encode. */
|
||||
if (x < 26)
|
||||
x += 'a';
|
||||
else
|
||||
x = (x - 26) + '2';
|
||||
|
||||
if (tolen < 1)
|
||||
return (mdn_buffer_overflow);
|
||||
|
||||
*to++ = x;
|
||||
tolen--;
|
||||
}
|
||||
}
|
||||
|
||||
if (tolen <= 0)
|
||||
return (mdn_buffer_overflow);
|
||||
|
||||
*to = '\0';
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
static int
|
||||
is_compress_effective(unsigned short *p, size_t len) {
|
||||
unsigned short last_high = 0x1; /* initialize with an invalid value */
|
||||
int nhigh = 0;
|
||||
int i;
|
||||
|
||||
/*
|
||||
* Find the number of HIGH value in the compressed string.
|
||||
*/
|
||||
for (i = 0; i < len; i++) {
|
||||
unsigned short high = p[i] & 0xff00;
|
||||
if (high != last_high)
|
||||
nhigh++;
|
||||
last_high = high;
|
||||
}
|
||||
|
||||
/*
|
||||
* Compressed string would take 2 * 'nhigh' + 'len' bytes,
|
||||
* while the original (uncomressed) string would take 2 * 'len'.
|
||||
* So the difference is 2 * 'nhigh' - len.
|
||||
*/
|
||||
if (2 * nhigh <= len)
|
||||
return (1); /* Compression is effective. */
|
||||
else
|
||||
return (0); /* Nope. */
|
||||
}
|
||||
195
contrib/idn/mdnkit/lib/localencoding.c
Normal file
195
contrib/idn/mdnkit/lib/localencoding.c
Normal file
|
|
@ -0,0 +1,195 @@
|
|||
#ifndef lint
|
||||
static char *rcsid = "$Id: localencoding.c,v 1.8 2000/09/20 02:47:31 ishisone Exp $";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef HAVE_LOCALE_H
|
||||
#include <locale.h>
|
||||
#endif
|
||||
#ifdef HAVE_LANGINFO_H
|
||||
#include <langinfo.h>
|
||||
#endif
|
||||
|
||||
#include <mdn/logmacro.h>
|
||||
#include <mdn/localencoding.h>
|
||||
#include <mdn/debug.h>
|
||||
|
||||
#if defined(HAVE_NL_LANGINFO) && defined(CODESET)
|
||||
|
||||
/*
|
||||
* This is the correct method to get the codeset name
|
||||
* corresponding to the current locale.
|
||||
*/
|
||||
const char *
|
||||
mdn_localencoding_name(void) {
|
||||
char *name;
|
||||
|
||||
TRACE(("mdn_localencoding_name()\n"));
|
||||
if ((name = getenv(MDN_LOCALCS_ENV)) == NULL)
|
||||
name = nl_langinfo(CODESET);
|
||||
TRACE(("local encoding=\"%-.30s\"\n", name == NULL ? "<null>" : name));
|
||||
return (name);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
typedef struct locale2encoding {
|
||||
char *locale_pattern; /* locale name pattern */
|
||||
char *encoding; /* MIME-preferred charset name */
|
||||
} locale2encoding_t;
|
||||
|
||||
static locale2encoding_t l2e[] = {
|
||||
{ "*.ISO_8859-1", "ISO-8859-1" },
|
||||
{ "*.ISO_8859-2", "ISO-8859-2" },
|
||||
{ "*.SJIS", "Shift_JIS" },
|
||||
{ "*.Shift_JIS", "Shift_JIS" },
|
||||
{ "ja_JP.EUC", "EUC-JP" },
|
||||
{ "ko_KR.EUC", "EUC-KR" },
|
||||
{ "*.big5" "Big5" },
|
||||
{ "*.Big5" "Big5" },
|
||||
{ "*.KOI8-R", "KOI8-R" },
|
||||
{ "*.GB2312", "GB2312" },
|
||||
#ifdef hpux
|
||||
{ "japanese", "Shift_JIS" },
|
||||
#else
|
||||
{ "japanese", "EUC-JP" },
|
||||
#endif
|
||||
{ "ja", "EUC-JP" },
|
||||
{ NULL, NULL },
|
||||
};
|
||||
|
||||
static const char *locale_to_encoding(const char *name);
|
||||
static int match(const char *pattern, const char *str);
|
||||
|
||||
const char *
|
||||
mdn_localencoding_name(void) {
|
||||
char *name;
|
||||
|
||||
TRACE(("mdn_localencoding_name()\n"));
|
||||
|
||||
if ((name = getenv(MDN_LOCALCS_ENV)) != NULL) {
|
||||
TRACE(("local encoding=\"%-.30s\"\n",
|
||||
name == NULL ? "<null>" : name));
|
||||
return (name);
|
||||
}
|
||||
(void)(
|
||||
#if HAVE_SETLOCALE
|
||||
(name = setlocale(LC_CTYPE, NULL)) ||
|
||||
#endif
|
||||
(name = getenv("LC_ALL")) ||
|
||||
(name = getenv("LC_CTYPE")) ||
|
||||
(name = getenv("LANG")));
|
||||
name = (char *)locale_to_encoding(name);
|
||||
TRACE(("local encoding=\"%-.30s\"\n", name == NULL ? "<null>" : name));
|
||||
return (name);
|
||||
}
|
||||
|
||||
/*
|
||||
* Locale name to encoding name.
|
||||
*/
|
||||
static const char *
|
||||
locale_to_encoding(const char *name) {
|
||||
int i;
|
||||
|
||||
if (name == NULL)
|
||||
return (NULL);
|
||||
|
||||
for (i = 0; l2e[i].locale_pattern != NULL; i++) {
|
||||
if (match(l2e[i].locale_pattern, name))
|
||||
return (l2e[i].encoding);
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
/*
|
||||
* Wild card matching function that supports only '*'.
|
||||
*/
|
||||
static int
|
||||
match(const char *pattern, const char *str) {
|
||||
for (;;) {
|
||||
int c;
|
||||
|
||||
switch (c = *pattern++) {
|
||||
case '\0':
|
||||
return (*str == '\0');
|
||||
case '*':
|
||||
while (!match(pattern, str)) {
|
||||
if (*str == '\0')
|
||||
return (0);
|
||||
str++;
|
||||
}
|
||||
return (1);
|
||||
break;
|
||||
default:
|
||||
if (*str++ != c)
|
||||
return (0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
230
contrib/idn/mdnkit/lib/log.c
Normal file
230
contrib/idn/mdnkit/lib/log.c
Normal file
|
|
@ -0,0 +1,230 @@
|
|||
#ifndef lint
|
||||
static char *rcsid = "$Id: log.c,v 1.12 2000/10/16 05:00:18 ishisone Exp $";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <mdn/log.h>
|
||||
|
||||
#define LOGLEVEL_ENV "MDN_LOG_LEVEL"
|
||||
|
||||
#ifdef DEBUG
|
||||
#define DEFAULT_LOG_LEVEL mdn_log_level_info
|
||||
#else
|
||||
#define DEFAULT_LOG_LEVEL mdn_log_level_error
|
||||
#endif
|
||||
|
||||
static int log_level = -1;
|
||||
static mdn_log_proc_t log_proc;
|
||||
|
||||
static void initialize(void);
|
||||
static void log(int level, const char *fmt, va_list args);
|
||||
static void log_to_stderr(int level, const char *buf);
|
||||
|
||||
void
|
||||
mdn_log_fatal(const char *fmt, ...) {
|
||||
va_list args;
|
||||
|
||||
va_start(args, fmt);
|
||||
log(mdn_log_level_fatal, fmt, args);
|
||||
va_end(args);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void
|
||||
mdn_log_error(const char *fmt, ...) {
|
||||
va_list args;
|
||||
|
||||
va_start(args, fmt);
|
||||
log(mdn_log_level_error, fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void
|
||||
mdn_log_warning(const char *fmt, ...) {
|
||||
va_list args;
|
||||
|
||||
va_start(args, fmt);
|
||||
log(mdn_log_level_warning, fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void
|
||||
mdn_log_info(const char *fmt, ...) {
|
||||
va_list args;
|
||||
|
||||
va_start(args, fmt);
|
||||
log(mdn_log_level_info, fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void
|
||||
mdn_log_trace(const char *fmt, ...) {
|
||||
va_list args;
|
||||
|
||||
va_start(args, fmt);
|
||||
log(mdn_log_level_trace, fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void
|
||||
mdn_log_dump(const char *fmt, ...) {
|
||||
va_list args;
|
||||
|
||||
va_start(args, fmt);
|
||||
log(mdn_log_level_dump, fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void
|
||||
mdn_log_setlevel(int level) {
|
||||
if (level >= 0)
|
||||
log_level = level;
|
||||
}
|
||||
|
||||
int
|
||||
mdn_log_getlevel(void) {
|
||||
initialize();
|
||||
return log_level;
|
||||
}
|
||||
|
||||
void
|
||||
mdn_log_setproc(mdn_log_proc_t proc) {
|
||||
if (proc == NULL)
|
||||
log_proc = log_to_stderr;
|
||||
else
|
||||
log_proc = proc;
|
||||
}
|
||||
|
||||
static void
|
||||
initialize(void) {
|
||||
char *s;
|
||||
|
||||
if (log_level < 0) {
|
||||
if ((s = getenv(LOGLEVEL_ENV)) != NULL) {
|
||||
int level = atoi(s);
|
||||
if (level >= 0)
|
||||
log_level = level;
|
||||
}
|
||||
if (log_level < 0)
|
||||
log_level = DEFAULT_LOG_LEVEL;
|
||||
}
|
||||
|
||||
if (log_proc == NULL)
|
||||
log_proc = log_to_stderr;
|
||||
}
|
||||
|
||||
static void
|
||||
log(int level, const char *fmt, va_list args) {
|
||||
char buf[1024];
|
||||
|
||||
initialize();
|
||||
|
||||
if (log_level < level)
|
||||
return;
|
||||
|
||||
#if HAVE_VSNPRINTF
|
||||
(void)vsnprintf(buf, sizeof(buf), fmt, args);
|
||||
#else
|
||||
/* Let's hope 1024 is enough.. */
|
||||
(void)vsprintf(buf, fmt, args);
|
||||
#endif
|
||||
(*log_proc)(level, buf);
|
||||
}
|
||||
|
||||
static void
|
||||
log_to_stderr(int level, const char *buf) {
|
||||
char *title;
|
||||
char tmp[20];
|
||||
|
||||
switch (level) {
|
||||
case mdn_log_level_fatal:
|
||||
title = "FATAL";
|
||||
break;
|
||||
case mdn_log_level_error:
|
||||
title = "ERROR";
|
||||
break;
|
||||
case mdn_log_level_warning:
|
||||
title = "WARNING";
|
||||
break;
|
||||
case mdn_log_level_info:
|
||||
title = "INFO";
|
||||
break;
|
||||
case mdn_log_level_trace:
|
||||
title = "TRACE";
|
||||
break;
|
||||
case mdn_log_level_dump:
|
||||
title = "DUMP";
|
||||
break;
|
||||
default:
|
||||
(void)sprintf(tmp, "LEVEL%d", level);
|
||||
title = tmp;
|
||||
break;
|
||||
}
|
||||
fprintf(stderr, "%u: [%s] %s", (unsigned int)getpid(), title, buf);
|
||||
}
|
||||
113
contrib/idn/mdnkit/lib/make.os2
Normal file
113
contrib/idn/mdnkit/lib/make.os2
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
# $Id: make.os2,v 1.1 2000/12/07 00:52:24 tale Exp $
|
||||
# Makefile for MDN library, manually configured for OS2 (for EMX/GCC)
|
||||
#
|
||||
# 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
# Tokyo, Japan.
|
||||
#
|
||||
# 1. Use, Modification and Redistribution (including distribution of any
|
||||
# modified or derived work) in source and/or binary forms is permitted
|
||||
# under this License Terms and Conditions.
|
||||
#
|
||||
# 2. Redistribution of source code must retain the copyright notices as they
|
||||
# appear in each source code file, this License Terms and Conditions.
|
||||
#
|
||||
# 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
# this License Terms and Conditions, in the documentation and/or other
|
||||
# materials provided with the distribution. For the purposes of binary
|
||||
# distribution the "Copyright Notice" refers to the following language:
|
||||
# "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
#
|
||||
# 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
# derived from this Software without specific prior written approval of
|
||||
# JPNIC.
|
||||
#
|
||||
# 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
#
|
||||
# 6. Indemnification by Licensee
|
||||
# Any person or entities using and/or redistributing this Software under
|
||||
# this License Terms and Conditions shall defend indemnify and hold
|
||||
# harmless JPNIC from and against any and all judgements damages,
|
||||
# expenses, settlement liabilities, cost and other liabilities of any
|
||||
# kind as a result of use and redistribution of this Software or any
|
||||
# claim, suite, action, litigation or proceeding by any third party
|
||||
# arising out of or relates to this License Terms and Conditions.
|
||||
#
|
||||
# 7. Governing Law, Jurisdiction and Venue
|
||||
# This License Terms and Conditions shall be governed by and and
|
||||
# construed in accordance with the law of Japan. Any person or entities
|
||||
# using and/or redistributing this Software under this License Terms and
|
||||
# Conditions hereby agrees and consent to the personal and exclusive
|
||||
# jurisdiction and venue of Tokyo District Court of Japan.
|
||||
|
||||
ICONVDIR = ../os2
|
||||
INCDIR = ../include
|
||||
CC = gcc -c
|
||||
CFLAGS = -Wall -Zmtd -I$(INCDIR) -I$(ICONVDIR) -DOS2 -DHAVE_UNISTD_H -DDEBUG
|
||||
LD = gcc
|
||||
LDFLAGS = -Zmtd
|
||||
|
||||
LIBS =
|
||||
SYSLIBS =
|
||||
|
||||
#
|
||||
# Files to build MDN library
|
||||
#
|
||||
|
||||
HDRS = $(ICONVDIR)/iconv.h \
|
||||
$(INCDIR)/config.h \
|
||||
$(INCDIR)/mdn/assert.h $(INCDIR)/mdn/converter.h \
|
||||
$(INCDIR)/mdn/debug.h $(INCDIR)/mdn/localencoding.h \
|
||||
$(INCDIR)/mdn/log.h $(INCDIR)/mdn/logmacro.h \
|
||||
$(INCDIR)/mdn/msgheader.h $(INCDIR)/mdn/msgtrans.h \
|
||||
$(INCDIR)/mdn/normalizer.h $(INCDIR)/mdn/result.h \
|
||||
$(INCDIR)/mdn/selectiveencode.h $(INCDIR)/mdn/strhash.h \
|
||||
$(INCDIR)/mdn/translator.h $(INCDIR)/mdn/unicode.h \
|
||||
$(INCDIR)/mdn/unormalize.h $(INCDIR)/mdn/utf5.h \
|
||||
$(INCDIR)/mdn/utf8.h $(INCDIR)/mdn/util.h $(INCDIR)/mdn/zldrule.h
|
||||
|
||||
SRCS = converter.c debug.c dn.c localencoding.c log.c \
|
||||
msgheader.c msgtrans.c normalizer.c race.c result.c \
|
||||
selectiveencode.c strhash.c translator.c \
|
||||
unicode.c unicodedata.c unormalize.c \
|
||||
utf5.c utf8.c util.c zldrule.c
|
||||
|
||||
OBJS = converter.o debug.o dn.o localencoding.o log.o \
|
||||
msgheader.o msgtrans.o normalizer.o race.o result.o \
|
||||
selectiveencode.o strhash.o translator.o \
|
||||
unicode.o unormalize.o \
|
||||
utf5.o utf8.o util.o zldrule.o
|
||||
|
||||
LIB = libmdn.a
|
||||
|
||||
all: $(LIB)
|
||||
|
||||
libmdn.a: $(OBJS)
|
||||
ar d $@ __.SYMDEF
|
||||
ar rs $@ $(OBJS)
|
||||
|
||||
generate:
|
||||
generate_normalize_data.pl > unicodedata.c
|
||||
|
||||
install:
|
||||
|
||||
clean:
|
||||
rm -f *.o *.a core *.core *~
|
||||
|
||||
192
contrib/idn/mdnkit/lib/make.wnt
Normal file
192
contrib/idn/mdnkit/lib/make.wnt
Normal file
|
|
@ -0,0 +1,192 @@
|
|||
# $Id: make.wnt,v 1.1 2000/12/07 00:52:24 tale Exp $
|
||||
# Makefile for MDN library, manually configured for WIN-NT (VC5.0)
|
||||
#
|
||||
# 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
# Tokyo, Japan.
|
||||
#
|
||||
# 1. Use, Modification and Redistribution (including distribution of any
|
||||
# modified or derived work) in source and/or binary forms is permitted
|
||||
# under this License Terms and Conditions.
|
||||
#
|
||||
# 2. Redistribution of source code must retain the copyright notices as they
|
||||
# appear in each source code file, this License Terms and Conditions.
|
||||
#
|
||||
# 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
# this License Terms and Conditions, in the documentation and/or other
|
||||
# materials provided with the distribution. For the purposes of binary
|
||||
# distribution the "Copyright Notice" refers to the following language:
|
||||
# "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
#
|
||||
# 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
# derived from this Software without specific prior written approval of
|
||||
# JPNIC.
|
||||
#
|
||||
# 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
#
|
||||
# 6. Indemnification by Licensee
|
||||
# Any person or entities using and/or redistributing this Software under
|
||||
# this License Terms and Conditions shall defend indemnify and hold
|
||||
# harmless JPNIC from and against any and all judgements damages,
|
||||
# expenses, settlement liabilities, cost and other liabilities of any
|
||||
# kind as a result of use and redistribution of this Software or any
|
||||
# claim, suite, action, litigation or proceeding by any third party
|
||||
# arising out of or relates to this License Terms and Conditions.
|
||||
#
|
||||
# 7. Governing Law, Jurisdiction and Venue
|
||||
# This License Terms and Conditions shall be governed by and and
|
||||
# construed in accordance with the law of Japan. Any person or entities
|
||||
# using and/or redistributing this Software under this License Terms and
|
||||
# Conditions hereby agrees and consent to the personal and exclusive
|
||||
# jurisdiction and venue of Tokyo District Court of Japan.
|
||||
|
||||
!include <ntwin32.mak>
|
||||
|
||||
INCDIR = ..\include
|
||||
ICONVDIR = ..\win
|
||||
LIBS =
|
||||
SYSLIBS = $(conlibsdll)
|
||||
|
||||
#
|
||||
# Files to build MDN library
|
||||
#
|
||||
|
||||
HDRS = $(ICONVDIR)\iconv.h \
|
||||
$(INCDIR)\config.h \
|
||||
$(INCDIR)\mdn\assert.h $(INCDIR)\mdn\converter.h \
|
||||
$(INCDIR)\mdn\debug.h $(INCDIR)\mdn\localencoding.h \
|
||||
$(INCDIR)\mdn\log.h $(INCDIR)\mdn\logmacro.h \
|
||||
$(INCDIR)\mdn\msgheader.h $(INCDIR)\mdn\msgtrans.h \
|
||||
$(INCDIR)\mdn\normalizer.h $(INCDIR)\mdn\result.h \
|
||||
$(INCDIR)\mdn\selectiveencode.h $(INCDIR)\mdn\strhash.h \
|
||||
$(INCDIR)\mdn\translator.h $(INCDIR)\mdn\unicode.h \
|
||||
$(INCDIR)\mdn\unormalize.h $(INCDIR)\mdn\utf5.h \
|
||||
$(INCDIR)\mdn\utf8.h $(INCDIR)\mdn\util.h $(INCDIR)\mdn\zldrule.h
|
||||
|
||||
SRCS = brace.c converter.c debug.c dn.c lace.c localencoding.c log.c \
|
||||
msgheader.c msgtrans.c normalizer.c race.c \
|
||||
res.c resconf.c result.c \
|
||||
selectiveencode.c strhash.c translator.c \
|
||||
unicode.c unicodedata.c unormalize.c \
|
||||
utf5.c utf8.c util.c zldrule.c
|
||||
|
||||
OBJS = brace.obj converter.obj debug.obj dn.obj lace.obj localencoding.obj log.obj \
|
||||
msgheader.obj msgtrans.obj normalizer.obj race.obj \
|
||||
res.obj resconf.obj result.obj \
|
||||
selectiveencode.obj strhash.obj translator.obj \
|
||||
unicode.obj unormalize.obj \
|
||||
utf5.obj utf8.obj util.obj zldrule.obj
|
||||
|
||||
LIB = libmdn.lib
|
||||
|
||||
#
|
||||
# Target to build
|
||||
#
|
||||
|
||||
all: $(LIB)
|
||||
|
||||
libmdn.lib: $(OBJS)
|
||||
-del libmdn.lib
|
||||
lib /out:libmdn.lib $(OBJS)
|
||||
|
||||
#
|
||||
# Dependencies
|
||||
#
|
||||
|
||||
brace.obj : brace.c $(HDRS)
|
||||
$(cc) $(cflags) $(cvarsdll) -I$(INCDIR) -I$(ICONVDIR) -DDEBUG $*.c
|
||||
|
||||
converter.obj : converter.c $(HDRS)
|
||||
$(cc) $(cflags) $(cvarsdll) -I$(INCDIR) -I$(ICONVDIR) -DDEBUG $*.c
|
||||
|
||||
debug.obj : debug.c $(HDRS)
|
||||
$(cc) $(cflags) $(cvarsdll) -I$(INCDIR) -I$(ICONVDIR) -DDEBUG $*.c
|
||||
|
||||
dn.obj : dn.c $(HDRS)
|
||||
$(cc) $(cflags) $(cvarsdll) -I$(INCDIR) -I$(ICONVDIR) -DDEBUG $*.c
|
||||
|
||||
lace.obj : lace.c $(HDRS)
|
||||
$(cc) $(cflags) $(cvarsdll) -I$(INCDIR) -I$(ICONVDIR) -DDEBUG $*.c
|
||||
|
||||
localencoding.obj : localencoding.c $(HDRS)
|
||||
$(cc) $(cflags) $(cvarsdll) -I$(INCDIR) -I$(ICONVDIR) -DDEBUG $*.c
|
||||
|
||||
log.obj : log.c $(HDRS)
|
||||
$(cc) $(cflags) $(cvarsdll) -I$(INCDIR) -I$(ICONVDIR) -DDEBUG $*.c
|
||||
|
||||
msgheader.obj : msgheader.c $(HDRS)
|
||||
$(cc) $(cflags) $(cvarsdll) -I$(INCDIR) -I$(ICONVDIR) -DDEBUG $*.c
|
||||
|
||||
msgtrans.obj : msgtrans.c $(HDRS)
|
||||
$(cc) $(cflags) $(cvarsdll) -I$(INCDIR) -I$(ICONVDIR) -DDEBUG $*.c
|
||||
|
||||
normalizer.obj : normalizer.c $(HDRS)
|
||||
$(cc) $(cflags) $(cvarsdll) -I$(INCDIR) -I$(ICONVDIR) -DDEBUG $*.c
|
||||
|
||||
race.obj : race.c $(HDRS)
|
||||
$(cc) $(cflags) $(cvarsdll) -I$(INCDIR) -I$(ICONVDIR) -DDEBUG $*.c
|
||||
|
||||
res.obj : res.c $(HDRS)
|
||||
$(cc) $(cflags) $(cvarsdll) -I$(INCDIR) -I$(ICONVDIR) -DDEBUG $*.c
|
||||
|
||||
resconf.obj : resconf.c $(HDRS)
|
||||
$(cc) $(cflags) $(cvarsdll) -I$(INCDIR) -I$(ICONVDIR) -DDEBUG $*.c
|
||||
|
||||
result.obj : result.c $(HDRS)
|
||||
$(cc) $(cflags) $(cvarsdll) -I$(INCDIR) -I$(ICONVDIR) -DDEBUG $*.c
|
||||
|
||||
selectiveencode.obj : selectiveencode.c $(HDRS)
|
||||
$(cc) $(cflags) $(cvarsdll) -I$(INCDIR) -I$(ICONVDIR) -DDEBUG $*.c
|
||||
|
||||
strhash.obj : strhash.c $(HDRS)
|
||||
$(cc) $(cflags) $(cvarsdll) -I$(INCDIR) -I$(ICONVDIR) -DDEBUG $*.c
|
||||
|
||||
translator.obj : translator.c $(HDRS)
|
||||
$(cc) $(cflags) $(cvarsdll) -I$(INCDIR) -I$(ICONVDIR) -DDEBUG $*.c
|
||||
|
||||
unicode.obj : unicode.c $(HDRS)
|
||||
$(cc) $(cflags) $(cvarsdll) -I$(INCDIR) -I$(ICONVDIR) -DDEBUG $*.c
|
||||
|
||||
unormalize.obj : unormalize.c $(HDRS)
|
||||
$(cc) $(cflags) $(cvarsdll) -I$(INCDIR) -I$(ICONVDIR) -DDEBUG $*.c
|
||||
|
||||
utf5.obj : utf5.c $(HDRS)
|
||||
$(cc) $(cflags) $(cvarsdll) -I$(INCDIR) -I$(ICONVDIR) -DDEBUG $*.c
|
||||
|
||||
utf8.obj : utf8.c $(HDRS)
|
||||
$(cc) $(cflags) $(cvarsdll) -I$(INCDIR) -I$(ICONVDIR) -DDEBUG $*.c
|
||||
|
||||
util.obj : util.c $(HDRS)
|
||||
$(cc) $(cflags) $(cvarsdll) -I$(INCDIR) -I$(ICONVDIR) -DDEBUG $*.c
|
||||
|
||||
zldrule.obj : zldrule.c $(HDRS)
|
||||
$(cc) $(cflags) $(cvarsdll) -I$(INCDIR) -I$(ICONVDIR) -DDEBUG $*.c
|
||||
|
||||
#
|
||||
# mics.
|
||||
#
|
||||
generate:
|
||||
generate_normalize_data.pl > unicodedata.c
|
||||
|
||||
install:
|
||||
|
||||
clean:
|
||||
del *.obj *.lib core *.core *~
|
||||
|
||||
53
contrib/idn/mdnkit/lib/mdnres.conf.sample
Normal file
53
contrib/idn/mdnkit/lib/mdnres.conf.sample
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
# $Id: mdnres.conf.sample,v 1.6 2000/11/22 06:57:31 ishisone Exp $
|
||||
#
|
||||
# A sample file for mDNkit's resolver configuration file (mdnres.conf)
|
||||
#
|
||||
|
||||
#
|
||||
# The following line specifies the encoding which DNS protocol uses,
|
||||
# such as RACE or UTF-8.
|
||||
# Note that the application's local encoding is determined from its
|
||||
# locale, so there is no 'client-encoding' line.
|
||||
#
|
||||
server-encoding RACE
|
||||
|
||||
#
|
||||
# If the server-encoding needs ZLD (zero level domain). Use the following
|
||||
# line to spcify. Note that you must enable ZLD feature (by giving
|
||||
# "--enable-zld" option to the configure script) to use it.
|
||||
#
|
||||
# server-zld zld.to.be.used
|
||||
|
||||
#
|
||||
# The following line specifies the normalization scheme(s) to be used.
|
||||
# If two or more shemes are specified, they are applied in order
|
||||
# (from left to right). The available shmemes are:
|
||||
# ascii-lowercase -- ASCII uppercase letters to lowercase
|
||||
# ascii-uppercase -- ASCII lowercase letters to uppercase
|
||||
# unicode-lowercase -- Unicode uppercase letters to lowercase
|
||||
# unicode-uppercase -- Unicode lowercase letters to uppercase
|
||||
# unicode-form-c -- Unicode normalization form C
|
||||
# unicode-form-kc -- Unicode normalization form KC
|
||||
# ja-kana-fullwidth -- Japanese halfwidth kana letters to fullwidth
|
||||
# ja-alnum-halfwidth -- Fullwidth alphabets, digits and minus sign
|
||||
# to halfwidth
|
||||
# ja-compose-voiced-sound -- Combine Japanese fullwidth kana and the
|
||||
# following (semi) voiced sound mark
|
||||
# ja-minus-hack -- Japanse fullwidth minus sign to '-'
|
||||
#
|
||||
normalize unicode-lowercase unicode-form-kc
|
||||
|
||||
#
|
||||
# The following line specifies the alternative encoding to use in case
|
||||
# the conversion from DNS protocol encoding to the application's local
|
||||
# encoding fails due to the lack of certain character in the character
|
||||
# set of the local encoding.
|
||||
# The alternative encoding must be an ASCII-compatible encoding (ACE).
|
||||
#
|
||||
alternate-encoding RACE
|
||||
|
||||
#
|
||||
# You can add alias names to the encoding (codeset) names. The following
|
||||
# line specifies the pathname of the alias definition file.
|
||||
#
|
||||
# alias-file /some/where/mdnalias.txt
|
||||
147
contrib/idn/mdnkit/lib/msgheader.c
Normal file
147
contrib/idn/mdnkit/lib/msgheader.c
Normal file
|
|
@ -0,0 +1,147 @@
|
|||
#ifndef lint
|
||||
static char *rcsid = "$Id: msgheader.c,v 1.7 2000/09/20 02:47:31 ishisone Exp $";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <mdn/result.h>
|
||||
#include <mdn/assert.h>
|
||||
#include <mdn/logmacro.h>
|
||||
#include <mdn/debug.h>
|
||||
#include <mdn/msgheader.h>
|
||||
|
||||
#define DNS_HEADER_SIZE 12
|
||||
|
||||
mdn_result_t
|
||||
mdn_msgheader_parse(const char *msg, size_t msglen, mdn_msgheader_t *parsed) {
|
||||
const unsigned char *p = (const unsigned char *)msg;
|
||||
unsigned int v;
|
||||
|
||||
assert(msg != NULL && parsed != NULL);
|
||||
|
||||
TRACE(("mdn_msgheader_parse(msg=<%s>, msglen=%d)\n",
|
||||
mdn_debug_hexdata(msg, msglen, 12), msglen));
|
||||
|
||||
if (msglen < DNS_HEADER_SIZE)
|
||||
return (mdn_invalid_message);
|
||||
|
||||
#define GET16(off) ((p[off]<<8)+p[(off)+1])
|
||||
parsed->id = GET16(0);
|
||||
v = GET16(2);
|
||||
parsed->qr = (v & 0x8000) != 0;
|
||||
parsed->opcode = (v >> 11) & 0xf;
|
||||
parsed->flags = (v >> 4) & 0x7f;
|
||||
parsed->rcode = v & 0xf;
|
||||
parsed->qdcount = GET16(4);
|
||||
parsed->ancount = GET16(6);
|
||||
parsed->nscount = GET16(8);
|
||||
parsed->arcount = GET16(10);
|
||||
#undef GET16
|
||||
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
mdn_result_t
|
||||
mdn_msgheader_unparse(mdn_msgheader_t *parsed, char *msg, size_t msglen) {
|
||||
unsigned char *p = (unsigned char *)msg;
|
||||
unsigned int v;
|
||||
|
||||
assert(parsed != NULL && msg != NULL);
|
||||
|
||||
TRACE(("mdn_msgheader_unparse()\n"));
|
||||
|
||||
if (msglen < DNS_HEADER_SIZE)
|
||||
return (mdn_buffer_overflow);
|
||||
|
||||
v = ((parsed->qr & 1) << 15) +
|
||||
((parsed->opcode & 0xf) << 11) +
|
||||
((parsed->flags & 0x7f) << 4) +
|
||||
(parsed->rcode & 0xf);
|
||||
|
||||
#define PUT16(off, v) p[off] = ((v)>>8) & 0xff; p[(off)+1] = (v) & 0xff
|
||||
PUT16(0, parsed->id);
|
||||
PUT16(2, v);
|
||||
PUT16(4, parsed->qdcount);
|
||||
PUT16(6, parsed->ancount);
|
||||
PUT16(8, parsed->nscount);
|
||||
PUT16(10, parsed->arcount);
|
||||
#undef PUT16
|
||||
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
unsigned int
|
||||
mdn_msgheader_getid(const char *msg) {
|
||||
const unsigned char *p = (const unsigned char *)msg;
|
||||
|
||||
return ((p[0] << 8) + p[1]);
|
||||
}
|
||||
|
||||
void
|
||||
mdn_msgheader_setid(char *msg, unsigned int id) {
|
||||
unsigned char *p = (unsigned char *)msg;
|
||||
|
||||
p[0] = (id >> 8) & 0xff;
|
||||
p[1] = id & 0xff;
|
||||
}
|
||||
633
contrib/idn/mdnkit/lib/msgtrans.c
Normal file
633
contrib/idn/mdnkit/lib/msgtrans.c
Normal file
|
|
@ -0,0 +1,633 @@
|
|||
#ifndef lint
|
||||
static char *rcsid = "$Id: msgtrans.c,v 1.22 2000/11/21 02:09:05 ishisone Exp $";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#include <winsock.h>
|
||||
#else /* for normal systems */
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/nameser.h>
|
||||
#include <resolv.h>
|
||||
#endif
|
||||
|
||||
#include <mdn/result.h>
|
||||
#include <mdn/assert.h>
|
||||
#include <mdn/logmacro.h>
|
||||
#include <mdn/converter.h>
|
||||
#include <mdn/normalizer.h>
|
||||
#include <mdn/translator.h>
|
||||
#include <mdn/zldrule.h>
|
||||
#include <mdn/msgheader.h>
|
||||
#include <mdn/msgtrans.h>
|
||||
#include <mdn/dn.h>
|
||||
#include <mdn/debug.h>
|
||||
|
||||
#define DNS_HEADER_SIZE 12
|
||||
#define DNAME_SIZE 512
|
||||
#define RRFORMAT_HASH_SIZE 47
|
||||
|
||||
/*
|
||||
* DNS opcodes.
|
||||
*/
|
||||
enum {
|
||||
opcode_query = 0,
|
||||
opcode_iquery = 1,
|
||||
opcode_status = 2,
|
||||
opcode_notify = 4,
|
||||
opcode_update = 5
|
||||
};
|
||||
|
||||
/*
|
||||
* Resource record types.
|
||||
*/
|
||||
enum {
|
||||
rrtype_A = 1,
|
||||
rrtype_NS = 2,
|
||||
rrtype_MD = 3,
|
||||
rrtype_MF = 4,
|
||||
rrtype_CNAME = 5,
|
||||
rrtype_SOA = 6,
|
||||
rrtype_MB = 7,
|
||||
rrtype_MG = 8,
|
||||
rrtype_MR = 9,
|
||||
rrtype_NULL = 10,
|
||||
rrtype_WKS = 11,
|
||||
rrtype_PTR = 12,
|
||||
rrtype_HINFO = 13,
|
||||
rrtype_MINFO = 14,
|
||||
rrtype_MX = 15,
|
||||
rrtype_TXT = 16,
|
||||
rrtype_RP = 17,
|
||||
rrtype_AFSDB = 18,
|
||||
rrtype_X25 = 19,
|
||||
rrtype_ISDN = 20,
|
||||
rrtype_RT = 21,
|
||||
rrtype_AAAA = 28
|
||||
};
|
||||
|
||||
/*
|
||||
* Resource record classes.
|
||||
*/
|
||||
enum {
|
||||
rrclass_IN = 1,
|
||||
rrclass_CS = 2,
|
||||
rrclass_CH = 3,
|
||||
rrclass_ANY = 255
|
||||
};
|
||||
|
||||
typedef struct msgtrans_ctx {
|
||||
const char *in; /* input message */
|
||||
size_t in_len; /* length of it */
|
||||
const char *in_ptr; /* current pointer */
|
||||
size_t in_remain; /* # of remaining octets */
|
||||
char *out; /* output (translated) message */
|
||||
char *out_ptr; /* current pointer */
|
||||
size_t out_remain; /* # of remaining (available) octets */
|
||||
mdn__dn_t dn_ctx; /* for compression */
|
||||
int determined; /* if ZLD/codeset are determined */
|
||||
mdn_msgtrans_param_t *param; /* translation parameters */
|
||||
} msgtrans_ctx_t;
|
||||
|
||||
static struct rrformat {
|
||||
unsigned int type; /* RR type */
|
||||
unsigned int class; /* RR class */
|
||||
const char *format; /* RDATA format */
|
||||
struct rrformat *next; /* hash chain */
|
||||
} rrformats[] = {
|
||||
{ rrtype_CNAME, rrclass_ANY, "D" },
|
||||
{ rrtype_HINFO, rrclass_ANY, "TT" },
|
||||
{ rrtype_MB, rrclass_ANY, "D" },
|
||||
{ rrtype_MD, rrclass_ANY, "D" },
|
||||
{ rrtype_MF, rrclass_ANY, "D" },
|
||||
{ rrtype_MG, rrclass_ANY, "D" },
|
||||
{ rrtype_MINFO, rrclass_ANY, "DD" },
|
||||
{ rrtype_MR, rrclass_ANY, "D" },
|
||||
{ rrtype_MX, rrclass_ANY, "SD" },
|
||||
{ rrtype_NULL, rrclass_ANY, "R" },
|
||||
{ rrtype_NS, rrclass_ANY, "D" },
|
||||
{ rrtype_PTR, rrclass_ANY, "D" },
|
||||
{ rrtype_SOA, rrclass_ANY, "DDLLLLL" },
|
||||
{ rrtype_TXT, rrclass_ANY, "T" },
|
||||
{ rrtype_A, rrclass_IN, "L" },
|
||||
{ rrtype_WKS, rrclass_IN, "LCR" },
|
||||
{ rrtype_RP, rrclass_ANY, "DD" },
|
||||
{ rrtype_AFSDB, rrclass_ANY, "SD" },
|
||||
{ rrtype_X25, rrclass_ANY, "T" },
|
||||
{ rrtype_ISDN, rrclass_ANY, "TT" },
|
||||
{ rrtype_RT, rrclass_ANY, "SD" },
|
||||
{ rrtype_AAAA, rrclass_IN, "H" },
|
||||
{ 0, 0, NULL },
|
||||
};
|
||||
static struct rrformat *rrformathash[RRFORMAT_HASH_SIZE];
|
||||
|
||||
static mdn_result_t copy_header(msgtrans_ctx_t *ctx);
|
||||
static mdn_result_t translate_question(msgtrans_ctx_t *ctx);
|
||||
static mdn_result_t translate_rr(msgtrans_ctx_t *ctx);
|
||||
static mdn_result_t translate_rdata(msgtrans_ctx_t *ctx,
|
||||
unsigned int rr_type,
|
||||
unsigned int rr_class,
|
||||
unsigned int rr_length);
|
||||
static const char *rdata_format(unsigned int rr_type, unsigned int rr_class);
|
||||
static mdn_result_t translate_domain(msgtrans_ctx_t *ctx);
|
||||
static mdn_result_t translate_name(mdn_msgtrans_param_t *param,
|
||||
char *from, char *to, size_t tolen);
|
||||
static mdn_result_t get_domainname(msgtrans_ctx_t *ctx, char *buf, size_t bufsize);
|
||||
static mdn_result_t put_domainname(msgtrans_ctx_t *ctx, char *name);
|
||||
static void ctx_init(msgtrans_ctx_t *ctx,
|
||||
mdn_msgtrans_param_t *param,
|
||||
const char *msg, size_t msglen,
|
||||
char *outbuf, size_t outbufsize);
|
||||
static mdn_result_t copy_rest(msgtrans_ctx_t *ctx);
|
||||
static mdn_result_t copy_message(msgtrans_ctx_t *ctx, size_t len);
|
||||
static size_t output_length(msgtrans_ctx_t *ctx);
|
||||
static void dump_message(const char *title, const char *p,
|
||||
size_t length);
|
||||
|
||||
|
||||
mdn_result_t
|
||||
mdn_msgtrans_translate(mdn_msgtrans_param_t *param,
|
||||
const char *msg, size_t msglen,
|
||||
char *outbuf, size_t outbufsize, size_t *outmsglenp)
|
||||
{
|
||||
mdn_result_t r;
|
||||
msgtrans_ctx_t ctx;
|
||||
mdn_msgheader_t header;
|
||||
int i;
|
||||
|
||||
assert(param != NULL && msg != NULL &&
|
||||
outbuf != NULL && outbufsize > 0 && outmsglenp != NULL);
|
||||
|
||||
TRACE(("mdn_msgtrans_translate(msg=<%s>,msglen=%d)\n",
|
||||
mdn_debug_hexdata(msg, msglen, 64), msglen));
|
||||
|
||||
if (LOGLEVEL >= mdn_log_level_dump)
|
||||
dump_message("before translation", msg, msglen);
|
||||
|
||||
/*
|
||||
* Check message length.
|
||||
*/
|
||||
if (msglen < DNS_HEADER_SIZE) {
|
||||
INFO(("mdn_msgtrans_translate: incoming packet too short "
|
||||
"(%d octets)\n", msglen));
|
||||
return (mdn_invalid_message);
|
||||
}
|
||||
|
||||
/*
|
||||
* Parse message header.
|
||||
*/
|
||||
if ((r = mdn_msgheader_parse(msg, msglen, &header)) != mdn_success) {
|
||||
WARNING(("mdn_msgtrans_translate: message header "
|
||||
"parsing failed: %s\n",
|
||||
mdn_result_tostring(r)));
|
||||
return (r);
|
||||
}
|
||||
|
||||
/*
|
||||
* Create translation context.
|
||||
*/
|
||||
ctx_init(&ctx, param, msg, msglen, outbuf, outbufsize);
|
||||
|
||||
/*
|
||||
* We handle only query, notify and update messages.
|
||||
* Do not process others.
|
||||
*/
|
||||
switch (header.opcode) {
|
||||
case opcode_query:
|
||||
case opcode_notify:
|
||||
case opcode_update:
|
||||
break;
|
||||
default:
|
||||
INFO(("mdn_msgtrans_translate: pass through message "
|
||||
"whose opcode is %d", header.opcode));
|
||||
if ((r = copy_rest(&ctx)) == mdn_success)
|
||||
*outmsglenp = output_length(&ctx);
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
/*
|
||||
* Copy header part verbatim.
|
||||
*/
|
||||
(void)copy_header(&ctx);
|
||||
|
||||
/*
|
||||
* Parse question/zone section.
|
||||
*/
|
||||
for (i = 0; i < header.qdcount; i++) {
|
||||
if ((r = translate_question(&ctx)) != mdn_success)
|
||||
return (r);
|
||||
}
|
||||
|
||||
/*
|
||||
* Translate other sections.
|
||||
*/
|
||||
for (i = 0;
|
||||
i < header.ancount + header.nscount + header.arcount;
|
||||
i++) {
|
||||
if ((r = translate_rr(&ctx)) != mdn_success)
|
||||
return (r);
|
||||
}
|
||||
|
||||
if (LOGLEVEL >= mdn_log_level_dump)
|
||||
dump_message("after translation",
|
||||
ctx.out, output_length(&ctx));
|
||||
|
||||
/*
|
||||
* Is there anything left out?
|
||||
*/
|
||||
if (ctx.in_remain != 0) {
|
||||
WARNING(("mdn_msgtrans_translate: garbage at the end "
|
||||
"(%d octets)\n", ctx.in_remain));
|
||||
/* don't consider this as an error. */
|
||||
/* return (mdn_invalid_message); */
|
||||
}
|
||||
|
||||
*outmsglenp = output_length(&ctx);
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
copy_header(msgtrans_ctx_t *ctx) {
|
||||
return (copy_message(ctx, DNS_HEADER_SIZE));
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
translate_question(msgtrans_ctx_t *ctx) {
|
||||
mdn_result_t r;
|
||||
mdn_msgtrans_param_t *param;
|
||||
char qname[DNAME_SIZE], qname_translated[DNAME_SIZE];
|
||||
|
||||
param = ctx->param;
|
||||
|
||||
/* Get QNAME. */
|
||||
if ((r = get_domainname(ctx, qname, sizeof(qname))) != mdn_success)
|
||||
return (r);
|
||||
|
||||
if (!ctx->determined) {
|
||||
/*
|
||||
* Determine ZLD and character set/encoding.
|
||||
*/
|
||||
r = mdn_zldrule_select(param->local_rule, qname,
|
||||
¶m->local_zld,
|
||||
¶m->local_converter);
|
||||
switch (r) {
|
||||
case mdn_success:
|
||||
ctx->determined = 1;
|
||||
break;
|
||||
case mdn_notfound:
|
||||
/*
|
||||
* No matching ZLD, no default.
|
||||
*/
|
||||
param->local_zld = NULL;
|
||||
param->local_converter = NULL;
|
||||
break;
|
||||
default:
|
||||
return (r);
|
||||
}
|
||||
}
|
||||
|
||||
/* Translate QNAME. */
|
||||
r = translate_name(param, qname, qname_translated,
|
||||
sizeof(qname_translated));
|
||||
if (r != mdn_success)
|
||||
return (r);
|
||||
|
||||
if ((r = put_domainname(ctx, qname_translated)) != mdn_success)
|
||||
return (r);
|
||||
|
||||
/* Copy QTYPE and QCLASS */
|
||||
return (copy_message(ctx, 4));
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
translate_rr(msgtrans_ctx_t *ctx) {
|
||||
mdn_result_t r;
|
||||
unsigned char *p;
|
||||
unsigned int rr_type, rr_class, rr_length;
|
||||
char dname[DNAME_SIZE], dname_translated[DNAME_SIZE];
|
||||
size_t length_before;
|
||||
|
||||
/* Get NAME. */
|
||||
if ((r = get_domainname(ctx, dname, sizeof(dname))) != mdn_success)
|
||||
return (r);
|
||||
|
||||
/* Translate NAME. */
|
||||
r = translate_name(ctx->param, dname, dname_translated,
|
||||
sizeof(dname_translated));
|
||||
if (r != mdn_success)
|
||||
return (r);
|
||||
|
||||
if ((r = put_domainname(ctx, dname_translated)) != mdn_success)
|
||||
return (r);
|
||||
|
||||
/* Get TYPE and CLASS */
|
||||
if (ctx->in_remain < 10)
|
||||
return (mdn_invalid_message);
|
||||
p = (unsigned char *)ctx->in_ptr;
|
||||
#define GET16(off) ((p[off]<<8)+p[(off)+1])
|
||||
rr_type = GET16(0);
|
||||
rr_class = GET16(2);
|
||||
rr_length = GET16(8);
|
||||
#undef GET16
|
||||
|
||||
/* Copy TYPE, CLASS, TTL and RDLENGTH. */
|
||||
if ((r = copy_message(ctx, 10)) != mdn_success)
|
||||
return (r);
|
||||
|
||||
/* Remember the current output length. */
|
||||
length_before = output_length(ctx);
|
||||
|
||||
/* Translate RDATA. */
|
||||
r = translate_rdata(ctx, rr_type, rr_class, rr_length);
|
||||
|
||||
if (r == mdn_success) {
|
||||
/* Reset RDLENGTH */
|
||||
rr_length = output_length(ctx) - length_before;
|
||||
ctx->out[length_before - 2] = (rr_length >> 8) & 0xff;
|
||||
ctx->out[length_before - 1] = rr_length & 0xff;
|
||||
}
|
||||
|
||||
return (r);
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
translate_rdata(msgtrans_ctx_t *ctx, unsigned int rr_type,
|
||||
unsigned int rr_class, unsigned int rr_length)
|
||||
{
|
||||
const char *format;
|
||||
int c;
|
||||
|
||||
if ((format = rdata_format(rr_type, rr_class)) == NULL) {
|
||||
INFO(("mdn_msgtrans: unknown resource record type %d "
|
||||
"pass through\n", rr_type));
|
||||
return (copy_message(ctx, rr_length));
|
||||
}
|
||||
|
||||
while ((c = *format++) != '\0') {
|
||||
int copy_len;
|
||||
mdn_result_t r;
|
||||
|
||||
switch (c) {
|
||||
case 'D': /* domain name */
|
||||
{
|
||||
int remain_org = ctx->in_remain;
|
||||
|
||||
if ((r = translate_domain(ctx)) != mdn_success)
|
||||
return (r);
|
||||
rr_length -= remain_org - ctx->in_remain;
|
||||
continue;
|
||||
}
|
||||
case 'T': /* character string */
|
||||
copy_len = *((unsigned char *)ctx->in_ptr) + 1;
|
||||
break;
|
||||
case 'C': /* 1-octet value */
|
||||
copy_len = 1;
|
||||
break;
|
||||
case 'S': /* 2-octet value */
|
||||
copy_len = 2;
|
||||
break;
|
||||
case 'L': /* 4-octet value */
|
||||
copy_len = 4;
|
||||
break;
|
||||
case 'H': /* 16-octet value (AAAA) */
|
||||
copy_len = 16;
|
||||
break;
|
||||
case 'R': /* the rest */
|
||||
copy_len = rr_length;
|
||||
break;
|
||||
default:
|
||||
copy_len = 0; /* for gcc -Wall */
|
||||
FATAL(("mdn_msgtrans: internal error -- "
|
||||
"unknown format character %c", c));
|
||||
/* NOTREACHED */
|
||||
break;
|
||||
}
|
||||
if ((r = copy_message(ctx, copy_len)) != mdn_success)
|
||||
return (r);
|
||||
rr_length -= copy_len;
|
||||
}
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
static const char *
|
||||
rdata_format(unsigned int rr_type, unsigned int rr_class) {
|
||||
static int initialized;
|
||||
struct rrformat *rp;
|
||||
int h;
|
||||
|
||||
if (!initialized) {
|
||||
/*
|
||||
* Build hash table.
|
||||
*/
|
||||
for (rp = rrformats; rp->format != NULL; rp++) {
|
||||
h = rp->type % RRFORMAT_HASH_SIZE;
|
||||
rp->next = rrformathash[h];
|
||||
rrformathash[h] = rp;
|
||||
}
|
||||
initialized = 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Find the element with the specified type and class.
|
||||
*/
|
||||
h = rr_type % RRFORMAT_HASH_SIZE;
|
||||
for (rp = rrformathash[h]; rp != NULL; rp = rp->next) {
|
||||
if (rp->type == rr_type &&
|
||||
(rp->class == rr_class || rp->class == rrclass_ANY))
|
||||
return (rp->format);
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
translate_domain(msgtrans_ctx_t *ctx) {
|
||||
mdn_result_t r;
|
||||
char dname[DNAME_SIZE], dname_translated[DNAME_SIZE];
|
||||
|
||||
/* Get NAME. */
|
||||
if ((r = get_domainname(ctx, dname, sizeof(dname))) != mdn_success)
|
||||
return (r);
|
||||
|
||||
/* Translate NAME. */
|
||||
r = translate_name(ctx->param, dname, dname_translated,
|
||||
sizeof(dname_translated));
|
||||
if (r != mdn_success)
|
||||
return (r);
|
||||
|
||||
if ((r = put_domainname(ctx, dname_translated)) != mdn_success)
|
||||
return (r);
|
||||
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
translate_name(mdn_msgtrans_param_t *param,
|
||||
char *from, char *to, size_t tolen)
|
||||
{
|
||||
if (param->local_converter == NULL) {
|
||||
/*
|
||||
* No translation is required.
|
||||
*/
|
||||
size_t fromlen = strlen(from) + 1;
|
||||
if (fromlen > tolen)
|
||||
return (mdn_buffer_overflow);
|
||||
(void)memcpy(to, from, fromlen);
|
||||
return (mdn_success);
|
||||
} else {
|
||||
return (mdn_translator_translate(param->local_converter,
|
||||
param->local_alt_converter,
|
||||
param->local_zld,
|
||||
param->normalizer,
|
||||
param->target_converter,
|
||||
param->target_alt_converter,
|
||||
param->target_zld,
|
||||
from, to, tolen));
|
||||
}
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
get_domainname(msgtrans_ctx_t *ctx, char *buf, size_t bufsize) {
|
||||
mdn_result_t r;
|
||||
size_t n;
|
||||
|
||||
r = mdn__dn_expand(ctx->in, ctx->in_len, ctx->in_ptr,
|
||||
buf, bufsize, &n);
|
||||
if (r == mdn_success) {
|
||||
ctx->in_ptr += n;
|
||||
ctx->in_remain -= n;
|
||||
}
|
||||
return (r);
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
put_domainname(msgtrans_ctx_t *ctx, char *name) {
|
||||
mdn_result_t r;
|
||||
size_t n;
|
||||
|
||||
r = mdn__dn_compress(name, ctx->out_ptr, ctx->out_remain,
|
||||
&ctx->dn_ctx, &n);
|
||||
if (r == mdn_success) {
|
||||
ctx->out_ptr += n;
|
||||
ctx->out_remain -= n;
|
||||
}
|
||||
return (r);
|
||||
}
|
||||
|
||||
static void
|
||||
ctx_init(msgtrans_ctx_t *ctx, mdn_msgtrans_param_t *param,
|
||||
const char *msg, size_t msglen, char *outbuf, size_t outbufsize)
|
||||
{
|
||||
ctx->in = ctx->in_ptr = msg;
|
||||
ctx->in_len = ctx->in_remain = msglen;
|
||||
ctx->out = ctx->out_ptr = outbuf;
|
||||
ctx->out_remain = outbufsize;
|
||||
ctx->determined = !param->use_local_rule;
|
||||
ctx->param = param;
|
||||
mdn__dn_initcompress(&ctx->dn_ctx, outbuf);
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
copy_rest(msgtrans_ctx_t *ctx) {
|
||||
return (copy_message(ctx, ctx->in_remain));
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
copy_message(msgtrans_ctx_t *ctx, size_t len) {
|
||||
assert(ctx != NULL);
|
||||
|
||||
if (ctx->in_remain < len)
|
||||
return (mdn_invalid_message);
|
||||
|
||||
if (ctx->out_remain < len)
|
||||
return (mdn_buffer_overflow);
|
||||
|
||||
(void)memcpy(ctx->out_ptr, ctx->in_ptr, len);
|
||||
|
||||
ctx->in_ptr += len;
|
||||
ctx->in_remain -= len;
|
||||
ctx->out_ptr += len;
|
||||
ctx->out_remain -= len;
|
||||
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
static size_t
|
||||
output_length(msgtrans_ctx_t *ctx) {
|
||||
return (ctx->out_ptr - ctx->out);
|
||||
}
|
||||
|
||||
static void
|
||||
dump_message(const char *title, const char *p, size_t length) {
|
||||
DUMP(("message (%s): length %d\n", title, length));
|
||||
while (length > 0) {
|
||||
int len = length < 16 ? length : 16;
|
||||
DUMP((" %s\n", mdn_debug_hexdata(p, len, 16)));
|
||||
p += len;
|
||||
length -= len;
|
||||
}
|
||||
}
|
||||
867
contrib/idn/mdnkit/lib/normalizer.c
Normal file
867
contrib/idn/mdnkit/lib/normalizer.c
Normal file
|
|
@ -0,0 +1,867 @@
|
|||
#ifndef lint
|
||||
static char *rcsid = "$Id: normalizer.c,v 1.16 2000/11/17 06:00:02 ishisone Exp $";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include <mdn/assert.h>
|
||||
#include <mdn/logmacro.h>
|
||||
#include <mdn/result.h>
|
||||
#include <mdn/normalizer.h>
|
||||
#include <mdn/strhash.h>
|
||||
#include <mdn/unormalize.h>
|
||||
#include <mdn/unicode.h>
|
||||
#include <mdn/utf8.h>
|
||||
#include <mdn/debug.h>
|
||||
|
||||
#define UNICODE_IDEOGRAPHIC_FULL_STOP 0x3002
|
||||
#define UNICODE_FULLWIDTH_FULL_STOP 0xff0e
|
||||
#define UNICODE_HALFWIDTH_IDEOGRAPHIC_FULL_STOP 0xff61
|
||||
#define UNICODE_HALFWIDTH_KATAKANA_SEMI_VOICED_SOUND_MARK 0xff9f
|
||||
#define UNICODE_MINUS_SIGN 0x2212
|
||||
#define UNICODE_FULLWIDTH_DIGIT_ZERO 0xff10
|
||||
#define UNICODE_FULLWIDTH_DIGIT_NINE 0xff19
|
||||
#define UNICODE_FULLWIDTH_LATIN_CAPITAL_LETTER_A 0xff21
|
||||
#define UNICODE_FULLWIDTH_LATIN_CAPITAL_LETTER_Z 0xff3a
|
||||
#define UNICODE_FULLWIDTH_LATIN_SMALL_LETTER_A 0xff41
|
||||
#define UNICODE_FULLWIDTH_LATIN_SMALL_LETTER_Z 0xff5a
|
||||
#define UNICODE_KATAKANA_HIRAGANA_VOICED_SOUND_MARK 0x309b
|
||||
#define UNICODE_KATAKANA_HIRAGANA_SEMI_VOICED_SOUND_MARK 0x309c
|
||||
#define UNICODE_VOICED_SOUND_CANDIDATE_BEGIN 0x304b /* ka */
|
||||
#define UNICODE_VOICED_SOUND_CANDIDATE_END 0x30dd /* ho */
|
||||
|
||||
#define MAX_LOCAL_SCHEME 3
|
||||
|
||||
#define INITIALIZED (scheme_hash != NULL)
|
||||
|
||||
typedef struct {
|
||||
char *name;
|
||||
mdn_normalizer_proc_t proc;
|
||||
} normalize_scheme_t;
|
||||
|
||||
struct mdn_normalizer {
|
||||
int nschemes;
|
||||
int scheme_size;
|
||||
normalize_scheme_t **schemes;
|
||||
normalize_scheme_t *local_buf[MAX_LOCAL_SCHEME];
|
||||
};
|
||||
|
||||
static unsigned long ja_half_to_full[] = {
|
||||
0x3002, 0x300c, 0x300d, 0x3001, 0x30fb, 0x30f2,
|
||||
0x30a1, 0x30a3, 0x30a5, 0x30a7, 0x30a9, 0x30e3,
|
||||
0x30e5, 0x30e7, 0x30c3, 0x30fc, 0x30a2, 0x30a4,
|
||||
0x30a6, 0x30a8, 0x30aa, 0x30ab, 0x30ad, 0x30af,
|
||||
0x30b1, 0x30b3, 0x30b5, 0x30b7, 0x30b9, 0x30bb,
|
||||
0x30bd, 0x30bf, 0x30c1, 0x30c4, 0x30c6, 0x30c8,
|
||||
0x30ca, 0x30cb, 0x30cc, 0x30cd, 0x30ce, 0x30cf,
|
||||
0x30d2, 0x30d5, 0x30d8, 0x30db, 0x30de, 0x30df,
|
||||
0x30e0, 0x30e1, 0x30e2, 0x30e4, 0x30e6, 0x30e8,
|
||||
0x30e9, 0x30ea, 0x30eb, 0x30ec, 0x30ed, 0x30ef,
|
||||
0x30f3, 0x309b, 0x309c,
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
unsigned long ucs;
|
||||
unsigned long composed_ucs;
|
||||
} voiced_sound_tbl_t;
|
||||
|
||||
static voiced_sound_tbl_t ja_voiced_sound[] = {
|
||||
{ 0x304b, 0x304c }, { 0x304d, 0x304e },
|
||||
{ 0x304f, 0x3050 }, { 0x3051, 0x3052 },
|
||||
{ 0x3053, 0x3054 }, { 0x3055, 0x3056 },
|
||||
{ 0x3057, 0x3058 }, { 0x3059, 0x305a },
|
||||
{ 0x305b, 0x305c }, { 0x305d, 0x305e },
|
||||
{ 0x305f, 0x3060 }, { 0x3061, 0x3062 },
|
||||
{ 0x3064, 0x3065 }, { 0x3066, 0x3067 },
|
||||
{ 0x3068, 0x3069 }, { 0x306f, 0x3070 },
|
||||
{ 0x3072, 0x3073 }, { 0x3075, 0x3076 },
|
||||
{ 0x3078, 0x3079 }, { 0x307b, 0x307c },
|
||||
{ 0x30a6, 0x30f4 }, { 0x30ab, 0x30ac },
|
||||
{ 0x30ad, 0x30ae }, { 0x30af, 0x30b0 },
|
||||
{ 0x30b1, 0x30b2 }, { 0x30b3, 0x30b4 },
|
||||
{ 0x30b5, 0x30b6 }, { 0x30b7, 0x30b8 },
|
||||
{ 0x30b9, 0x30ba }, { 0x30bb, 0x30bc },
|
||||
{ 0x30bd, 0x30be }, { 0x30bf, 0x30c0 },
|
||||
{ 0x30c1, 0x30c2 }, { 0x30c4, 0x30c5 },
|
||||
{ 0x30c6, 0x30c7 }, { 0x30c8, 0x30c9 },
|
||||
{ 0x30cf, 0x30d0 }, { 0x30d2, 0x30d3 },
|
||||
{ 0x30d5, 0x30d6 }, { 0x30d8, 0x30d9 },
|
||||
{ 0x30db, 0x30dc },
|
||||
};
|
||||
|
||||
static voiced_sound_tbl_t ja_semi_voiced_sound[] = {
|
||||
{ 0x306f, 0x3071 }, { 0x3072, 0x3074 },
|
||||
{ 0x3075, 0x3077 }, { 0x3078, 0x307a },
|
||||
{ 0x307b, 0x307d }, { 0x30cf, 0x30d1 },
|
||||
{ 0x30d2, 0x30d4 }, { 0x30d5, 0x30d7 },
|
||||
{ 0x30d8, 0x30da }, { 0x30db, 0x30dd },
|
||||
};
|
||||
|
||||
static mdn_strhash_t scheme_hash;
|
||||
|
||||
static mdn_result_t expand_schemes(mdn_normalizer_t ctx);
|
||||
static mdn_result_t register_standard_normalizers(void);
|
||||
static mdn_result_t normalizer_ascii_lowercase(const char *from,
|
||||
char *to, size_t tolen);
|
||||
static mdn_result_t normalizer_ascii_uppercase(const char *from,
|
||||
char *to, size_t tolen);
|
||||
static mdn_result_t normalizer_unicode_lowercase(const char *from,
|
||||
char *to, size_t tolen);
|
||||
static mdn_result_t normalizer_unicode_uppercase(const char *from,
|
||||
char *to, size_t tolen);
|
||||
static mdn_result_t normalizer_unicode_caseconv(mdn_result_t (*caseconv)(),
|
||||
const char *from,
|
||||
char *to, size_t tolen);
|
||||
static mdn__unicode_context_t get_casemap_context(const char *from,
|
||||
size_t fromlen);
|
||||
static mdn_result_t normalizer_ja_minus_hack(const char *from,
|
||||
char *to, size_t tolen);
|
||||
static mdn_result_t normalizer_ja_delimiter_hack(const char *from,
|
||||
char *to, size_t tolen);
|
||||
static mdn_result_t normalizer_ja_fullwidth(const char *from,
|
||||
char *to, size_t tolen);
|
||||
static mdn_result_t normalizer_ja_alnum_halfwidth(const char *from,
|
||||
char *to, size_t tolen);
|
||||
static mdn_result_t normalizer_ja_voicedsound(const char *from,
|
||||
char *to, size_t tolen);
|
||||
static int compose_voicedsound(unsigned long ucs1,
|
||||
unsigned long ucs2,
|
||||
unsigned long *composed);
|
||||
|
||||
static struct standard_normalizer {
|
||||
char *name;
|
||||
mdn_normalizer_proc_t proc;
|
||||
} standard_normalizer[] = {
|
||||
{ "ascii-lowercase", normalizer_ascii_lowercase },
|
||||
{ "ascii-uppercase", normalizer_ascii_uppercase },
|
||||
{ "unicode-lowercase", normalizer_unicode_lowercase },
|
||||
{ "unicode-uppercase", normalizer_unicode_uppercase },
|
||||
{ "unicode-form-c", mdn__unormalize_formc },
|
||||
{ "unicode-form-d", mdn__unormalize_formd },
|
||||
{ "unicode-form-kc", mdn__unormalize_formkc },
|
||||
{ "unicode-form-kd", mdn__unormalize_formkd },
|
||||
{ "ja-minus-hack", normalizer_ja_minus_hack },
|
||||
{ "ja-delimiter-hack", normalizer_ja_delimiter_hack },
|
||||
{ "ja-fullwidth", normalizer_ja_fullwidth },
|
||||
{ "ja-kana-fullwidth", normalizer_ja_fullwidth },
|
||||
{ "ja-alnum-halfwidth", normalizer_ja_alnum_halfwidth },
|
||||
{ "ja-compose-voiced-sound", normalizer_ja_voicedsound },
|
||||
{ NULL, NULL },
|
||||
};
|
||||
|
||||
mdn_result_t
|
||||
mdn_normalizer_initialize(void) {
|
||||
mdn_strhash_t hash;
|
||||
mdn_result_t r;
|
||||
|
||||
if (scheme_hash != NULL)
|
||||
return (mdn_success); /* already initialized */
|
||||
|
||||
if ((r = mdn_strhash_create(&hash)) != mdn_success) {
|
||||
WARNING(("mdn_normalizer_initialize: "
|
||||
"hash table creation failed\n"));
|
||||
return (r);
|
||||
}
|
||||
scheme_hash = hash;
|
||||
|
||||
/* Register standard normalizers */
|
||||
return (register_standard_normalizers());
|
||||
}
|
||||
|
||||
mdn_result_t
|
||||
mdn_normalizer_create(mdn_normalizer_t *ctxp) {
|
||||
mdn_normalizer_t ctx;
|
||||
|
||||
assert(ctxp != NULL);
|
||||
TRACE(("mdn_normalizer_create()\n"));
|
||||
|
||||
if ((ctx = malloc(sizeof(struct mdn_normalizer))) == NULL) {
|
||||
WARNING(("mdn_normalizer_create: malloc failed\n"));
|
||||
return (mdn_nomemory);
|
||||
}
|
||||
|
||||
ctx->nschemes = 0;
|
||||
ctx->scheme_size = MAX_LOCAL_SCHEME;
|
||||
ctx->schemes = ctx->local_buf;
|
||||
*ctxp = ctx;
|
||||
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
void
|
||||
mdn_normalizer_destroy(mdn_normalizer_t ctx) {
|
||||
assert(ctx != NULL);
|
||||
|
||||
TRACE(("mdn_normalizer_destroy()\n"));
|
||||
|
||||
if (ctx->schemes != ctx->local_buf)
|
||||
free(ctx->schemes);
|
||||
|
||||
free(ctx);
|
||||
}
|
||||
|
||||
mdn_result_t
|
||||
mdn_normalizer_add(mdn_normalizer_t ctx, const char *scheme_name) {
|
||||
mdn_result_t r;
|
||||
void *v;
|
||||
normalize_scheme_t *scheme;
|
||||
|
||||
assert(ctx != NULL && scheme_name != NULL);
|
||||
|
||||
TRACE(("mdn_normalizer_add(scheme_name=%s)\n", scheme_name));
|
||||
|
||||
assert(INITIALIZED);
|
||||
|
||||
if (mdn_strhash_get(scheme_hash, scheme_name, &v) != mdn_success) {
|
||||
WARNING(("mdn_normalizer_add: invalid scheme %s\n",
|
||||
scheme_name));
|
||||
return (mdn_invalid_name);
|
||||
}
|
||||
|
||||
scheme = v;
|
||||
|
||||
assert(ctx->nschemes <= ctx->scheme_size);
|
||||
|
||||
if (ctx->nschemes == ctx->scheme_size &&
|
||||
(r = expand_schemes(ctx)) != mdn_success) {
|
||||
WARNING(("mdn_normalizer_add: malloc failed\n"));
|
||||
return (r);
|
||||
}
|
||||
|
||||
ctx->schemes[ctx->nschemes++] = scheme;
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
|
||||
mdn_result_t
|
||||
mdn_normalizer_normalize(mdn_normalizer_t ctx, const char *from,
|
||||
char *to, size_t tolen)
|
||||
{
|
||||
assert(ctx != NULL && from != NULL && to != NULL);
|
||||
|
||||
TRACE(("mdn_normalizer_normalize(from=\"%s\")\n",
|
||||
mdn_debug_xstring(from, 20)));
|
||||
|
||||
if (ctx->nschemes == 0) {
|
||||
/* No normalization needed. */
|
||||
size_t flen = strlen(from);
|
||||
|
||||
if (tolen < flen + 1)
|
||||
return (mdn_buffer_overflow);
|
||||
memcpy(to, from, flen + 1); /* +1 for NUL */
|
||||
return (mdn_success);
|
||||
} else if (ctx->nschemes == 1) {
|
||||
/* No temporary buffer needed. */
|
||||
TRACE(("mdn_normalizer_normalize: nomalization %s\n",
|
||||
ctx->schemes[0]->name));
|
||||
return ((*ctx->schemes[0]->proc)(from, to, tolen));
|
||||
} else {
|
||||
/*
|
||||
* Allocate two intermediate buffers.
|
||||
*/
|
||||
char *buffer[2];
|
||||
char local_buf[2][1024]; /* usually big enough */
|
||||
size_t buffer_size[2];
|
||||
mdn_result_t r = mdn_success;
|
||||
int i;
|
||||
|
||||
/*
|
||||
* Initialize the buffers to use the local
|
||||
* storage (stack memory).
|
||||
*/
|
||||
buffer[0] = local_buf[0];
|
||||
buffer[1] = local_buf[1];
|
||||
buffer_size[0] = sizeof(local_buf[0]);
|
||||
buffer_size[1] = sizeof(local_buf[1]);
|
||||
|
||||
for (i = 0; i < ctx->nschemes; i++) {
|
||||
const char *f;
|
||||
char *t;
|
||||
size_t len;
|
||||
int f_idx = i % 2;
|
||||
int t_idx = !f_idx;
|
||||
|
||||
TRACE(("mdn_normalizer_normalize: nomalization %s\n",
|
||||
ctx->schemes[i]->name));
|
||||
|
||||
/*
|
||||
* Set up from/to buffers.
|
||||
*/
|
||||
retry:
|
||||
if (i == 0)
|
||||
f = from;
|
||||
else
|
||||
f = buffer[f_idx];
|
||||
if (i == ctx->nschemes - 1) {
|
||||
t = to;
|
||||
len = tolen;
|
||||
} else {
|
||||
t = buffer[t_idx];
|
||||
len = buffer_size[t_idx];
|
||||
}
|
||||
|
||||
/*
|
||||
* Call the normalize procedure.
|
||||
*/
|
||||
r = (*ctx->schemes[i]->proc)(f, t, len);
|
||||
|
||||
if (r == mdn_buffer_overflow && t != to) {
|
||||
/*
|
||||
* Temporary buffer is too small.
|
||||
* Make it bigger.
|
||||
*/
|
||||
char *p;
|
||||
|
||||
TRACE(("mdn_normalizer_normalize: "
|
||||
"allocating temporary buffer\n"));
|
||||
|
||||
/* Make it double. */
|
||||
buffer_size[t_idx] *= 2;
|
||||
|
||||
if (buffer[t_idx] == local_buf[t_idx]) {
|
||||
size_t flen = strlen(f) + 100;
|
||||
if (buffer_size[t_idx] < flen)
|
||||
buffer_size[t_idx] = flen;
|
||||
p = malloc(buffer_size[t_idx]);
|
||||
} else {
|
||||
p = realloc(buffer[t_idx],
|
||||
buffer_size[t_idx]);
|
||||
}
|
||||
if (p == NULL) {
|
||||
WARNING(("mdn_normalizer_normalize: "
|
||||
"malloc failed\n"));
|
||||
r = mdn_nomemory;
|
||||
goto ret;
|
||||
}
|
||||
buffer[t_idx] = p;
|
||||
/* Start it over again. */
|
||||
goto retry;
|
||||
} else if (r != mdn_success) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ret:
|
||||
if (buffer[0] != local_buf[0])
|
||||
free(buffer[0]);
|
||||
if (buffer[1] != local_buf[1])
|
||||
free(buffer[1]);
|
||||
|
||||
return (r);
|
||||
}
|
||||
}
|
||||
|
||||
mdn_result_t
|
||||
mdn_normalizer_register(const char *scheme_name, mdn_normalizer_proc_t proc) {
|
||||
mdn_result_t r;
|
||||
normalize_scheme_t *scheme;
|
||||
|
||||
assert(scheme_name != NULL && proc != NULL);
|
||||
|
||||
TRACE(("mdn_normalizer_register(scheme_name=%s)\n", scheme_name));
|
||||
|
||||
assert(INITIALIZED);
|
||||
|
||||
scheme = malloc(sizeof(*scheme) + strlen(scheme_name) + 1);
|
||||
if (scheme == NULL) {
|
||||
WARNING(("mdn_normalizer_register: malloc failed\n"));
|
||||
return (mdn_nomemory);
|
||||
}
|
||||
scheme->name = (char *)(scheme + 1);
|
||||
(void)strcpy(scheme->name, scheme_name);
|
||||
scheme->proc = proc;
|
||||
|
||||
r = mdn_strhash_put(scheme_hash, scheme_name, scheme);
|
||||
if (r != mdn_success)
|
||||
WARNING(("mdn_normalizer_register: registration failed\n"));
|
||||
|
||||
return (r);
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
expand_schemes(mdn_normalizer_t ctx) {
|
||||
normalize_scheme_t **new_schemes;
|
||||
int new_size = ctx->scheme_size * 2;
|
||||
|
||||
if (ctx->schemes == ctx->local_buf) {
|
||||
new_schemes = malloc(sizeof(normalize_scheme_t) * new_size);
|
||||
} else {
|
||||
new_schemes = realloc(ctx->schemes,
|
||||
sizeof(normalize_scheme_t) * new_size);
|
||||
}
|
||||
if (new_schemes == NULL)
|
||||
return (mdn_nomemory);
|
||||
|
||||
if (ctx->schemes == ctx->local_buf)
|
||||
memcpy(new_schemes, ctx->local_buf, sizeof(ctx->local_buf));
|
||||
|
||||
ctx->schemes = new_schemes;
|
||||
ctx->scheme_size = new_size;
|
||||
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
register_standard_normalizers(void) {
|
||||
int i;
|
||||
int failed = 0;
|
||||
|
||||
for (i = 0; standard_normalizer[i].name != NULL; i++) {
|
||||
mdn_result_t r;
|
||||
r = mdn_normalizer_register(standard_normalizer[i].name,
|
||||
standard_normalizer[i].proc);
|
||||
if (r != mdn_success) {
|
||||
WARNING(("mdn_normalizer_initialize: "
|
||||
"failed to register \"%-.100s\"\n",
|
||||
standard_normalizer[i].name));
|
||||
failed++;
|
||||
}
|
||||
}
|
||||
if (failed > 0)
|
||||
return (mdn_failure);
|
||||
else
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
/*
|
||||
* Standard Normalizer
|
||||
*/
|
||||
|
||||
static mdn_result_t
|
||||
normalizer_ascii_lowercase(const char *from, char *to, size_t tolen) {
|
||||
size_t fromlen = strlen(from);
|
||||
|
||||
while (fromlen > 0 && tolen > 0) {
|
||||
int w = mdn_utf8_mblen(from);
|
||||
|
||||
if (w == 0 || fromlen < w)
|
||||
return (mdn_invalid_encoding);
|
||||
else if (tolen < w)
|
||||
return (mdn_buffer_overflow);
|
||||
|
||||
if (w == 1 && isupper((unsigned char)*from)) {
|
||||
*to++ = tolower((unsigned char)(*from++));
|
||||
} else {
|
||||
int i = w;
|
||||
while (i-- > 0)
|
||||
*to++ = *from++;
|
||||
}
|
||||
fromlen -= w;
|
||||
tolen -= w;
|
||||
}
|
||||
if (tolen <= 0)
|
||||
return (mdn_buffer_overflow);
|
||||
|
||||
*to = '\0';
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
normalizer_ascii_uppercase(const char *from, char *to, size_t tolen) {
|
||||
size_t fromlen = strlen(from);
|
||||
|
||||
while (fromlen > 0 && tolen > 0) {
|
||||
int w = mdn_utf8_mblen(from);
|
||||
|
||||
if (w == 0 || fromlen < w)
|
||||
return (mdn_invalid_encoding);
|
||||
else if (tolen < w)
|
||||
return (mdn_buffer_overflow);
|
||||
|
||||
if (w == 1 && islower((unsigned char)*from)) {
|
||||
*to++ = toupper((unsigned char)(*from++));
|
||||
} else {
|
||||
int i = w;
|
||||
while (i-- > 0)
|
||||
*to++ = *from++;
|
||||
}
|
||||
fromlen -= w;
|
||||
tolen -= w;
|
||||
}
|
||||
if (tolen <= 0)
|
||||
return (mdn_buffer_overflow);
|
||||
|
||||
*to = '\0';
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
normalizer_unicode_lowercase(const char *from, char *to, size_t tolen) {
|
||||
return (normalizer_unicode_caseconv(mdn__unicode_tolower,
|
||||
from, to, tolen));
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
normalizer_unicode_uppercase(const char *from, char *to, size_t tolen) {
|
||||
return (normalizer_unicode_caseconv(mdn__unicode_toupper,
|
||||
from, to, tolen));
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
normalizer_unicode_caseconv(mdn_result_t (*caseconv)(),
|
||||
const char *from, char *to, size_t tolen)
|
||||
{
|
||||
size_t fromlen = strlen(from);
|
||||
|
||||
while (fromlen > 0 && tolen > 0) {
|
||||
#define CASEMAPBUFSZ 4
|
||||
unsigned long c;
|
||||
unsigned long v[CASEMAPBUFSZ];
|
||||
mdn_result_t r;
|
||||
mdn__unicode_context_t ctx = mdn__unicode_context_unknown;
|
||||
size_t vlen;
|
||||
int w;
|
||||
int i;
|
||||
|
||||
if ((w = mdn_utf8_getwc(from, fromlen, &c)) == 0)
|
||||
return (mdn_invalid_encoding);
|
||||
from += w;
|
||||
fromlen -= w;
|
||||
|
||||
redo:
|
||||
r = (*caseconv)(c, ctx, v, CASEMAPBUFSZ, &vlen);
|
||||
switch (r) {
|
||||
case mdn_success:
|
||||
break;
|
||||
case mdn_context_required:
|
||||
ctx = get_casemap_context(from, fromlen);
|
||||
goto redo;
|
||||
case mdn_buffer_overflow:
|
||||
FATAL(("mdn_normalizer_normalize: "
|
||||
"internal buffer overflow\n"));
|
||||
break;
|
||||
default:
|
||||
return (r);
|
||||
}
|
||||
|
||||
for (i = 0; i < vlen; i++) {
|
||||
if ((w = mdn_utf8_putwc(to, tolen, v[i])) == 0)
|
||||
return (mdn_buffer_overflow);
|
||||
to += w;
|
||||
tolen -= w;
|
||||
}
|
||||
}
|
||||
if (tolen <= 0)
|
||||
return (mdn_buffer_overflow);
|
||||
|
||||
*to = '\0';
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
static mdn__unicode_context_t
|
||||
get_casemap_context(const char *from, size_t fromlen) {
|
||||
while (fromlen > 0) {
|
||||
unsigned long v;
|
||||
mdn__unicode_context_t ctx;
|
||||
int w;
|
||||
|
||||
if ((w = mdn_utf8_getwc(from, fromlen, &v)) == 0)
|
||||
return (mdn_invalid_encoding);
|
||||
from += w;
|
||||
fromlen -= w;
|
||||
ctx = mdn__unicode_getcontext(v);
|
||||
if (ctx == mdn__unicode_context_nonfinal ||
|
||||
ctx == mdn__unicode_context_final)
|
||||
return (ctx);
|
||||
}
|
||||
return (mdn__unicode_context_final);
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
normalizer_ja_minus_hack(const char *from, char *to, size_t tolen) {
|
||||
size_t fromlen = strlen(from);
|
||||
|
||||
while (fromlen > 0 && tolen > 0) {
|
||||
unsigned long ucs;
|
||||
int width;
|
||||
|
||||
if ((width = mdn_utf8_getwc(from, fromlen, &ucs)) == 0)
|
||||
return (mdn_invalid_encoding);
|
||||
from += width;
|
||||
fromlen -= width;
|
||||
|
||||
if (ucs == UNICODE_MINUS_SIGN)
|
||||
ucs = '-';
|
||||
|
||||
if ((width = mdn_utf8_putwc(to, tolen, ucs)) == 0)
|
||||
return (mdn_buffer_overflow);
|
||||
to += width;
|
||||
tolen -= width;
|
||||
}
|
||||
|
||||
if (tolen <= 0)
|
||||
return (mdn_buffer_overflow);
|
||||
|
||||
*to = '\0';
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
normalizer_ja_delimiter_hack(const char *from, char *to, size_t tolen) {
|
||||
size_t fromlen = strlen(from);
|
||||
|
||||
while (fromlen > 0 && tolen > 0) {
|
||||
unsigned long ucs;
|
||||
int width;
|
||||
|
||||
if ((width = mdn_utf8_getwc(from, fromlen, &ucs)) == 0)
|
||||
return (mdn_invalid_encoding);
|
||||
from += width;
|
||||
fromlen -= width;
|
||||
|
||||
if (ucs == UNICODE_IDEOGRAPHIC_FULL_STOP ||
|
||||
ucs == UNICODE_FULLWIDTH_FULL_STOP)
|
||||
ucs = '.';
|
||||
|
||||
if ((width = mdn_utf8_putwc(to, tolen, ucs)) == 0)
|
||||
return (mdn_buffer_overflow);
|
||||
to += width;
|
||||
tolen -= width;
|
||||
}
|
||||
|
||||
if (tolen <= 0)
|
||||
return (mdn_buffer_overflow);
|
||||
|
||||
*to = '\0';
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
normalizer_ja_fullwidth(const char *from, char *to, size_t tolen) {
|
||||
size_t fromlen = strlen(from);
|
||||
|
||||
while (fromlen > 0 && tolen > 0) {
|
||||
unsigned long ucs;
|
||||
int width;
|
||||
|
||||
if ((width = mdn_utf8_getwc(from, fromlen, &ucs)) == 0)
|
||||
return (mdn_invalid_encoding);
|
||||
from += width;
|
||||
fromlen -= width;
|
||||
|
||||
if (UNICODE_HALFWIDTH_IDEOGRAPHIC_FULL_STOP <= ucs &&
|
||||
ucs <= UNICODE_HALFWIDTH_KATAKANA_SEMI_VOICED_SOUND_MARK) {
|
||||
ucs = ja_half_to_full[ucs - UNICODE_HALFWIDTH_IDEOGRAPHIC_FULL_STOP];
|
||||
}
|
||||
|
||||
if ((width = mdn_utf8_putwc(to, tolen, ucs)) == 0)
|
||||
return (mdn_buffer_overflow);
|
||||
to += width;
|
||||
tolen -= width;
|
||||
}
|
||||
|
||||
if (tolen <= 0)
|
||||
return (mdn_buffer_overflow);
|
||||
|
||||
*to = '\0';
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
normalizer_ja_alnum_halfwidth(const char *from, char *to, size_t tolen) {
|
||||
size_t fromlen = strlen(from);
|
||||
|
||||
while (fromlen > 0 && tolen > 0) {
|
||||
unsigned long ucs;
|
||||
int width;
|
||||
|
||||
if ((width = mdn_utf8_getwc(from, fromlen, &ucs)) == 0)
|
||||
return (mdn_invalid_encoding);
|
||||
from += width;
|
||||
fromlen -= width;
|
||||
|
||||
if (ucs >= UNICODE_FULLWIDTH_DIGIT_ZERO &&
|
||||
ucs <= UNICODE_FULLWIDTH_DIGIT_NINE) {
|
||||
ucs -= UNICODE_FULLWIDTH_DIGIT_ZERO;
|
||||
ucs += '0';
|
||||
} else if (ucs >= UNICODE_FULLWIDTH_LATIN_CAPITAL_LETTER_A &&
|
||||
ucs <= UNICODE_FULLWIDTH_LATIN_CAPITAL_LETTER_Z) {
|
||||
ucs -= UNICODE_FULLWIDTH_LATIN_CAPITAL_LETTER_A;
|
||||
ucs += 'A';
|
||||
} else if (ucs >= UNICODE_FULLWIDTH_LATIN_SMALL_LETTER_A &&
|
||||
ucs <= UNICODE_FULLWIDTH_LATIN_SMALL_LETTER_Z) {
|
||||
ucs -= UNICODE_FULLWIDTH_LATIN_SMALL_LETTER_A;
|
||||
ucs += 'a';
|
||||
} else if (ucs == UNICODE_MINUS_SIGN) {
|
||||
ucs = '-';
|
||||
}
|
||||
|
||||
if ((width = mdn_utf8_putwc(to, tolen, ucs)) == 0)
|
||||
return (mdn_buffer_overflow);
|
||||
to += width;
|
||||
tolen -= width;
|
||||
}
|
||||
|
||||
if (tolen <= 0)
|
||||
return (mdn_buffer_overflow);
|
||||
|
||||
*to = '\0';
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
normalizer_ja_voicedsound(const char *from, char *to, size_t tolen) {
|
||||
size_t fromlen = strlen(from);
|
||||
unsigned long ucs, last_ucs;
|
||||
int width;
|
||||
|
||||
#define VOID_UCS 0xffffffff /* not a valid UCS-4 character. */
|
||||
|
||||
for (last_ucs = VOID_UCS; fromlen > 0 && tolen > 0; last_ucs = ucs) {
|
||||
unsigned long composed_ucs;
|
||||
|
||||
if ((width = mdn_utf8_getwc(from, fromlen, &ucs)) == 0)
|
||||
return (mdn_invalid_encoding);
|
||||
from += width;
|
||||
fromlen -= width;
|
||||
|
||||
if (last_ucs == VOID_UCS)
|
||||
continue;
|
||||
|
||||
/*
|
||||
* See if 'ucs' can be composed with the previous character
|
||||
* 'last_ucs'.
|
||||
*/
|
||||
if ((ucs == UNICODE_KATAKANA_HIRAGANA_SEMI_VOICED_SOUND_MARK ||
|
||||
ucs == UNICODE_KATAKANA_HIRAGANA_VOICED_SOUND_MARK) &&
|
||||
compose_voicedsound(last_ucs, ucs, &composed_ucs)) {
|
||||
/*
|
||||
* They can be composed. Replace 'last_ucs'
|
||||
* with the composed character, and void 'ucs'.
|
||||
*/
|
||||
last_ucs = composed_ucs;
|
||||
ucs = VOID_UCS;
|
||||
}
|
||||
|
||||
/*
|
||||
* Append 'last_ucs' to the result buffer.
|
||||
*/
|
||||
if ((width = mdn_utf8_putwc(to, tolen, last_ucs)) == 0)
|
||||
return (mdn_buffer_overflow);
|
||||
to += width;
|
||||
tolen -= width;
|
||||
}
|
||||
|
||||
/*
|
||||
* If there is non-void 'last_ucs' character, append it to
|
||||
* the result buffer.
|
||||
*/
|
||||
if (last_ucs != VOID_UCS) {
|
||||
if ((width = mdn_utf8_putwc(to, tolen, last_ucs)) == 0)
|
||||
return (mdn_buffer_overflow);
|
||||
to += width;
|
||||
tolen -= width;
|
||||
}
|
||||
#undef VOID_UCS
|
||||
|
||||
/*
|
||||
* Terminate the result buffer with NUL.
|
||||
*/
|
||||
if (tolen <= 0)
|
||||
return (mdn_buffer_overflow);
|
||||
*to = '\0';
|
||||
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
static int
|
||||
compose_voicedsound(unsigned long ucs1, unsigned long ucs2,
|
||||
unsigned long *composed)
|
||||
{
|
||||
voiced_sound_tbl_t *tbl;
|
||||
size_t tblsize;
|
||||
int top, end;
|
||||
|
||||
assert(ucs2 == UNICODE_KATAKANA_HIRAGANA_VOICED_SOUND_MARK ||
|
||||
ucs2 == UNICODE_KATAKANA_HIRAGANA_SEMI_VOICED_SOUND_MARK);
|
||||
|
||||
if (ucs1 < UNICODE_VOICED_SOUND_CANDIDATE_BEGIN ||
|
||||
ucs1 > UNICODE_VOICED_SOUND_CANDIDATE_END)
|
||||
return (0);
|
||||
|
||||
if (ucs2 == UNICODE_KATAKANA_HIRAGANA_VOICED_SOUND_MARK) {
|
||||
tbl = ja_voiced_sound;
|
||||
tblsize = sizeof(ja_voiced_sound) / sizeof(tbl[0]);
|
||||
} else {
|
||||
tbl = ja_semi_voiced_sound;
|
||||
tblsize = sizeof(ja_semi_voiced_sound) / sizeof(tbl[0]);
|
||||
}
|
||||
|
||||
for (top = 0, end = tblsize - 1; top <= end;) {
|
||||
int mid = (top + end) / 2;
|
||||
unsigned long miducs = tbl[mid].ucs;
|
||||
|
||||
if (ucs1 == miducs) {
|
||||
*composed = tbl[mid].composed_ucs;
|
||||
return (1);
|
||||
} else if (ucs1 < miducs) {
|
||||
end = mid - 1;
|
||||
} else {
|
||||
top = mid + 1;
|
||||
}
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
539
contrib/idn/mdnkit/lib/race.c
Normal file
539
contrib/idn/mdnkit/lib/race.c
Normal file
|
|
@ -0,0 +1,539 @@
|
|||
#ifndef lint
|
||||
static char *rcsid = "$Id: race.c,v 1.14 2000/11/22 01:52:18 ishisone Exp $";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <mdn/result.h>
|
||||
#include <mdn/assert.h>
|
||||
#include <mdn/logmacro.h>
|
||||
#include <mdn/converter.h>
|
||||
#include <mdn/utf8.h>
|
||||
#include <mdn/debug.h>
|
||||
#include <mdn/race.h>
|
||||
#include <mdn/util.h>
|
||||
|
||||
#ifndef MDN_RACE_PREFIX
|
||||
#define MDN_RACE_PREFIX "bq--"
|
||||
#endif
|
||||
#define RACE_PREFIX_LEN (strlen(MDN_RACE_PREFIX))
|
||||
#define RACE_2OCTET_MODE 0xd8
|
||||
#define RACE_ESCAPE 0xff
|
||||
#define RACE_ESCAPE_2ND 0x99
|
||||
|
||||
#define RACE_BUF_SIZE 128 /* more than enough */
|
||||
|
||||
/*
|
||||
* Unicode surrogate pair.
|
||||
*/
|
||||
#define IS_SURROGATE_HIGH(v) (0xd800 <= (v) && (v) <= 0xdbff)
|
||||
#define IS_SURROGATE_LOW(v) (0xdc00 <= (v) && (v) <= 0xdfff)
|
||||
#define SURROGATE_HIGH(v) (SURROGATE_H_OFF + (((v) - 0x10000) >> 10))
|
||||
#define SURROGATE_LOW(v) (SURROGATE_L_OFF + ((v) & 0x3ff))
|
||||
#define SURROGATE_BASE 0x10000
|
||||
#define SURROGATE_H_OFF 0xd800
|
||||
#define SURROGATE_L_OFF 0xdc00
|
||||
#define COMBINE_SURROGATE(h, l) \
|
||||
(SURROGATE_BASE + (((h)-SURROGATE_H_OFF)<<10) + ((l)-SURROGATE_L_OFF))
|
||||
|
||||
/*
|
||||
* Compression type.
|
||||
*/
|
||||
enum {
|
||||
compress_one, /* all characters are in a single row */
|
||||
compress_two, /* row 0 and another row */
|
||||
compress_none, /* nope */
|
||||
};
|
||||
|
||||
static mdn_result_t race_l2u(const char *from, const char *end,
|
||||
char *to, size_t tolen, size_t *clenp);
|
||||
static mdn_result_t race_u2l(const char *from, const char *end,
|
||||
char *to, size_t tolen, size_t *clenp);
|
||||
static mdn_result_t race_decode(const char *from, size_t fromlen,
|
||||
char *to, size_t tolen);
|
||||
static mdn_result_t race_decode_decompress(const char *from,
|
||||
size_t fromlen,
|
||||
unsigned short *buf,
|
||||
size_t *lenp);
|
||||
static mdn_result_t race_encode(const char *from, size_t fromlen,
|
||||
char *to, size_t tolen);
|
||||
static mdn_result_t race_compress_encode(const unsigned short *p,
|
||||
size_t len, int compress_mode,
|
||||
char *to, size_t tolen);
|
||||
static int get_compress_mode(unsigned short *p, size_t len);
|
||||
|
||||
/* ARGSUSED */
|
||||
mdn_result_t
|
||||
mdn__race_open(mdn_converter_t ctx, mdn_converter_dir_t dir) {
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
/* ARGSUSED */
|
||||
mdn_result_t
|
||||
mdn__race_close(mdn_converter_t ctx, mdn_converter_dir_t dir) {
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
mdn_result_t
|
||||
mdn__race_convert(mdn_converter_t ctx, mdn_converter_dir_t dir,
|
||||
const char *from, char *toorg, size_t tolen)
|
||||
{
|
||||
char *to = toorg;
|
||||
|
||||
assert(ctx != NULL &&
|
||||
(dir == mdn_converter_l2u || dir == mdn_converter_u2l));
|
||||
|
||||
TRACE(("mdn__race_convert(dir=%s,from=\"%s\")\n",
|
||||
dir == mdn_converter_l2u ? "l2u" : "u2l",
|
||||
mdn_debug_xstring(from, 20)));
|
||||
|
||||
for (;;) {
|
||||
const char *end;
|
||||
size_t convlen;
|
||||
mdn_result_t r;
|
||||
|
||||
/*
|
||||
* Find the end of this component (label).
|
||||
*/
|
||||
if ((end = strchr(from, '.')) == NULL)
|
||||
end = from + strlen(from);
|
||||
|
||||
/*
|
||||
* Convert it.
|
||||
*/
|
||||
if (dir == mdn_converter_l2u)
|
||||
r = race_l2u(from, end, to, tolen, &convlen);
|
||||
else
|
||||
r = race_u2l(from, end, to, tolen, &convlen);
|
||||
if (r != mdn_success)
|
||||
return (r);
|
||||
|
||||
/*
|
||||
* Copy '.' or NUL.
|
||||
*/
|
||||
if (tolen <= convlen)
|
||||
return (mdn_buffer_overflow);
|
||||
|
||||
to += convlen;
|
||||
*to++ = *end;
|
||||
tolen -= convlen + 1;
|
||||
|
||||
if (*end == '\0')
|
||||
break;
|
||||
|
||||
from = end + 1;
|
||||
}
|
||||
|
||||
DUMP(("mdn__race_convert: \"%s\"\n", mdn_debug_xstring(toorg, 70)));
|
||||
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
race_l2u(const char *from, const char *end,
|
||||
char *to, size_t tolen, size_t *clenp) {
|
||||
size_t len = end - from;
|
||||
|
||||
if (len >= RACE_PREFIX_LEN &&
|
||||
mdn_util_casematch(from, MDN_RACE_PREFIX, RACE_PREFIX_LEN)) {
|
||||
/*
|
||||
* RACE encoding prefix found.
|
||||
*/
|
||||
mdn_result_t r;
|
||||
|
||||
r = race_decode(from + RACE_PREFIX_LEN,
|
||||
len - RACE_PREFIX_LEN, to, tolen);
|
||||
if (r == mdn_invalid_encoding)
|
||||
goto copy;
|
||||
else if (r != mdn_success)
|
||||
return (r);
|
||||
|
||||
len = strlen(to);
|
||||
} else {
|
||||
/*
|
||||
* Not RACE encoded. Copy verbatim.
|
||||
*/
|
||||
copy:
|
||||
if (mdn_util_domainspan(from, end) < end) {
|
||||
/* invalid character found */
|
||||
return (mdn_invalid_encoding);
|
||||
}
|
||||
|
||||
if (tolen < len)
|
||||
return (mdn_buffer_overflow);
|
||||
|
||||
(void)memcpy(to, from, len);
|
||||
}
|
||||
*clenp = len;
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
race_u2l(const char *from, const char *end,
|
||||
char *to, size_t tolen, size_t *clenp) {
|
||||
size_t len = end - from;
|
||||
|
||||
/*
|
||||
* See if encoding is necessary.
|
||||
*/
|
||||
if (mdn_util_domainspan(from, end) < end) {
|
||||
/*
|
||||
* Conversion is necessary.
|
||||
*/
|
||||
mdn_result_t r;
|
||||
|
||||
/* Set prefix. */
|
||||
if (tolen < RACE_PREFIX_LEN)
|
||||
return (mdn_buffer_overflow);
|
||||
(void)memcpy(to, MDN_RACE_PREFIX, RACE_PREFIX_LEN);
|
||||
to += RACE_PREFIX_LEN;
|
||||
tolen -= RACE_PREFIX_LEN;
|
||||
|
||||
r = race_encode(from, len, to, tolen);
|
||||
if (r != mdn_success)
|
||||
return (r);
|
||||
|
||||
len = RACE_PREFIX_LEN + strlen(to);
|
||||
} else {
|
||||
/*
|
||||
* Conversion is NOT necessary.
|
||||
* Copy verbatim.
|
||||
*/
|
||||
|
||||
if (tolen < len)
|
||||
return (mdn_buffer_overflow);
|
||||
|
||||
(void)memcpy(to, from, len);
|
||||
}
|
||||
*clenp = len;
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
race_decode(const char *from, size_t fromlen, char *to, size_t tolen) {
|
||||
unsigned short *buf;
|
||||
unsigned short local_buf[RACE_BUF_SIZE];
|
||||
size_t len, reslen;
|
||||
mdn_result_t r;
|
||||
|
||||
/*
|
||||
* Allocate sufficient buffer.
|
||||
*/
|
||||
if (fromlen > RACE_BUF_SIZE) {
|
||||
if ((buf = malloc(sizeof(*buf) * fromlen)) == NULL)
|
||||
return (mdn_nomemory);
|
||||
} else {
|
||||
/* Use local buffer. */
|
||||
buf = local_buf;
|
||||
}
|
||||
|
||||
/*
|
||||
* Decode base32 and decompress.
|
||||
*/
|
||||
r = race_decode_decompress(from, fromlen, buf, &len);
|
||||
if (r != mdn_success)
|
||||
goto ret;
|
||||
|
||||
/*
|
||||
* Now 'buf' points the decompressed string, which must contain
|
||||
* UTF-16 characters.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Convert to UTF-8.
|
||||
*/
|
||||
r = mdn_util_utf16toutf8(buf, len, to, tolen, &reslen);
|
||||
if (r != mdn_success)
|
||||
goto ret;
|
||||
|
||||
if (tolen <= reslen) {
|
||||
r = mdn_buffer_overflow;
|
||||
goto ret;
|
||||
}
|
||||
to += reslen;
|
||||
*to = '\0';
|
||||
tolen -= reslen;
|
||||
|
||||
r = mdn_success;
|
||||
|
||||
ret:
|
||||
if (buf != local_buf)
|
||||
free(buf);
|
||||
return (r);
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
race_decode_decompress(const char *from, size_t fromlen,
|
||||
unsigned short *buf, size_t *lenp)
|
||||
{
|
||||
unsigned short *p = buf;
|
||||
unsigned int bitbuf = 0;
|
||||
int bitlen = 0;
|
||||
int i, j;
|
||||
size_t len;
|
||||
|
||||
while (fromlen-- > 0) {
|
||||
int c = *from++;
|
||||
int x;
|
||||
|
||||
if ('a' <= c && c <= 'z')
|
||||
x = c - 'a';
|
||||
else if ('A' <= c && c <= 'Z')
|
||||
x = c - 'A';
|
||||
else if ('2' <= c && c <= '7')
|
||||
x = c - '2' + 26;
|
||||
else
|
||||
return (mdn_invalid_encoding);
|
||||
|
||||
bitbuf = (bitbuf << 5) + x;
|
||||
bitlen += 5;
|
||||
if (bitlen >= 8) {
|
||||
*p++ = (bitbuf >> (bitlen - 8)) & 0xff;
|
||||
bitlen -= 8;
|
||||
}
|
||||
}
|
||||
len = p - buf;
|
||||
|
||||
/*
|
||||
* Now 'buf' holds the decoded string.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Decompress.
|
||||
*/
|
||||
if (buf[0] == RACE_2OCTET_MODE) {
|
||||
if ((len - 1) % 2 != 0)
|
||||
return (mdn_invalid_encoding);
|
||||
for (i = 1, j = 0; i < len; i += 2, j++)
|
||||
buf[j] = (buf[i] << 8) + buf[i + 1];
|
||||
len = j;
|
||||
} else {
|
||||
unsigned short c = buf[0] << 8; /* higher octet */
|
||||
|
||||
for (i = 1, j = 0; i < len; j++) {
|
||||
if (buf[i] == RACE_ESCAPE) {
|
||||
if (i + 1 >= len)
|
||||
return (mdn_invalid_encoding);
|
||||
else if (buf[i + 1] == RACE_ESCAPE_2ND)
|
||||
buf[j] = c | 0xff;
|
||||
else
|
||||
buf[j] = buf[i + 1];
|
||||
i += 2;
|
||||
} else {
|
||||
buf[j] = c | buf[i++];
|
||||
}
|
||||
}
|
||||
len = j;
|
||||
}
|
||||
*lenp = len;
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
race_encode(const char *from, size_t fromlen, char *to, size_t tolen) {
|
||||
unsigned short *p, *buf;
|
||||
unsigned short local_buf[RACE_BUF_SIZE]; /* UTF-16 */
|
||||
mdn_result_t r;
|
||||
size_t len, buflen;
|
||||
int compress_mode;
|
||||
|
||||
/*
|
||||
* Convert to UTF-16.
|
||||
* Preserve space for a character at the top of the buffer.
|
||||
*/
|
||||
buf = local_buf;
|
||||
buflen = RACE_BUF_SIZE;
|
||||
for (;;) {
|
||||
r = mdn_util_utf8toutf16(from, fromlen,
|
||||
buf + 1, buflen - 1, &len);
|
||||
if (r == mdn_buffer_overflow) {
|
||||
buflen *= 2;
|
||||
if (buf == local_buf)
|
||||
buf = malloc(sizeof(*buf) * buflen);
|
||||
else
|
||||
buf = realloc(buf, sizeof(*buf) * buflen);
|
||||
if (buf == NULL)
|
||||
return (mdn_nomemory);
|
||||
} else if (r == mdn_success) {
|
||||
break;
|
||||
} else {
|
||||
goto ret;
|
||||
}
|
||||
}
|
||||
p = buf + 1;
|
||||
|
||||
/*
|
||||
* Now 'p' contains UTF-16 encoded string.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Compress, encode in base-32 and output.
|
||||
*/
|
||||
compress_mode = get_compress_mode(p, len);
|
||||
r = race_compress_encode(buf, len + 1, compress_mode, to, tolen);
|
||||
|
||||
ret:
|
||||
if (buf != local_buf)
|
||||
free(buf);
|
||||
return (r);
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
race_compress_encode(const unsigned short *p, size_t len, int compress_mode,
|
||||
char *to, size_t tolen)
|
||||
{
|
||||
unsigned long bitbuf = 0; /* bit stream buffer */
|
||||
int bitlen = 0; /* # of bits in 'bitbuf' */
|
||||
int i;
|
||||
|
||||
for (i = 0; i <= len; i++) {
|
||||
if (i == len) {
|
||||
/* End of data. Flush. */
|
||||
if (bitlen == 0)
|
||||
break;
|
||||
bitbuf <<= (5 - bitlen);
|
||||
bitlen = 5;
|
||||
} else if (i == 0 || compress_mode == compress_one) {
|
||||
/* Push 8 bit data into bitbuf. */
|
||||
bitbuf = (bitbuf << 8) | (p[i] & 0xff);
|
||||
bitlen += 8;
|
||||
} else if (compress_mode == compress_two) {
|
||||
/* Push 8 or 16 bit data. */
|
||||
if ((p[i] & 0xff00) == 0) {
|
||||
/* Upper octet is zero. */
|
||||
bitbuf = (bitbuf << 16) | 0xff00 | p[i];
|
||||
bitlen += 16;
|
||||
} else if ((p[i] & 0xff) == 0xff) {
|
||||
/* Lower octet is 0xff. */
|
||||
bitbuf = (bitbuf << 16) |
|
||||
(RACE_ESCAPE << 8) | RACE_ESCAPE_2ND;
|
||||
bitlen += 16;
|
||||
} else {
|
||||
bitbuf = (bitbuf << 8) | (p[i] & 0xff);
|
||||
bitlen += 8;
|
||||
}
|
||||
} else { /* compresss_mode == compress_none */
|
||||
/* Push 16 bit data. */
|
||||
bitbuf = (bitbuf << 16) | p[i];
|
||||
bitlen += 16;
|
||||
}
|
||||
|
||||
/*
|
||||
* Output bits in 'bitbuf' in 5-bit unit.
|
||||
*/
|
||||
while (bitlen >= 5) {
|
||||
int x;
|
||||
|
||||
/* Get top 5 bits. */
|
||||
x = (bitbuf >> (bitlen - 5)) & 0x1f;
|
||||
bitlen -= 5;
|
||||
|
||||
/* Encode. */
|
||||
if (x < 26)
|
||||
x += 'a';
|
||||
else
|
||||
x = (x - 26) + '2';
|
||||
|
||||
if (tolen < 1)
|
||||
return (mdn_buffer_overflow);
|
||||
|
||||
*to++ = x;
|
||||
tolen--;
|
||||
}
|
||||
}
|
||||
|
||||
if (tolen <= 0)
|
||||
return (mdn_buffer_overflow);
|
||||
|
||||
*to = '\0';
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
static int
|
||||
get_compress_mode(unsigned short *p, size_t len) {
|
||||
int zero = 0;
|
||||
unsigned int upper = 0;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
unsigned int hi = p[i] & 0xff00;
|
||||
|
||||
if (hi == 0) {
|
||||
zero++;
|
||||
} else if (hi == upper) {
|
||||
;
|
||||
} else if (upper == 0) {
|
||||
upper = hi;
|
||||
} else {
|
||||
p[-1] = RACE_2OCTET_MODE;
|
||||
return (compress_none);
|
||||
}
|
||||
}
|
||||
p[-1] = upper >> 8;
|
||||
if (upper > 0 && zero > 0)
|
||||
return (compress_two);
|
||||
else
|
||||
return (compress_one);
|
||||
}
|
||||
285
contrib/idn/mdnkit/lib/res.c
Normal file
285
contrib/idn/mdnkit/lib/res.c
Normal file
|
|
@ -0,0 +1,285 @@
|
|||
#ifndef lint
|
||||
static char *rcsid = "$Id: res.c,v 1.5 2000/09/20 02:47:32 ishisone Exp $";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <mdn/result.h>
|
||||
#include <mdn/assert.h>
|
||||
#include <mdn/logmacro.h>
|
||||
#include <mdn/converter.h>
|
||||
#include <mdn/normalizer.h>
|
||||
#include <mdn/translator.h>
|
||||
#include <mdn/resconf.h>
|
||||
#include <mdn/res.h>
|
||||
#include <mdn/debug.h>
|
||||
|
||||
static mdn_result_t copy_verbatim(const char *from, char *to,
|
||||
size_t tolen);
|
||||
static int contain_invalid_char(const char *name);
|
||||
|
||||
mdn_result_t
|
||||
mdn_res_localtoucs(mdn_resconf_t conf, const char *local_name,
|
||||
char *ucs_name, size_t ucs_name_len)
|
||||
{
|
||||
mdn_converter_t conv;
|
||||
mdn_result_t r;
|
||||
|
||||
assert(local_name != NULL && ucs_name != NULL);
|
||||
|
||||
TRACE(("mdn_res_localtoucs(local_name=\"%-.20s\")\n", local_name));
|
||||
|
||||
if (conf == NULL)
|
||||
return (copy_verbatim(local_name, ucs_name, ucs_name_len));
|
||||
|
||||
if (!contain_invalid_char(local_name) &&
|
||||
(conv = mdn_resconf_alternateconverter(conf)) != NULL) {
|
||||
TRACE(("mdn_res_localtoucs: trying alternate converter..\n"));
|
||||
r = mdn_converter_convert(conv, mdn_converter_l2u,
|
||||
local_name, ucs_name, ucs_name_len);
|
||||
if (r == mdn_success)
|
||||
return (r);
|
||||
}
|
||||
|
||||
if ((conv = mdn_resconf_localconverter(conf)) == NULL)
|
||||
return (copy_verbatim(local_name, ucs_name, ucs_name_len));
|
||||
|
||||
TRACE(("mdn_res_localtoucs: using local converter..\n"));
|
||||
return (mdn_converter_convert(conv, mdn_converter_l2u,
|
||||
local_name, ucs_name, ucs_name_len));
|
||||
}
|
||||
|
||||
mdn_result_t
|
||||
mdn_res_ucstolocal(mdn_resconf_t conf, const char *ucs_name,
|
||||
char *local_name, size_t local_name_len)
|
||||
{
|
||||
mdn_converter_t conv;
|
||||
mdn_result_t r;
|
||||
|
||||
assert(ucs_name != NULL && local_name != NULL);
|
||||
|
||||
TRACE(("mdn_res_ucstolocal(ucs_name=\"%s\")\n",
|
||||
mdn_debug_xstring(ucs_name, 20)));
|
||||
|
||||
if (conf == NULL ||
|
||||
(conv = mdn_resconf_localconverter(conf)) == NULL)
|
||||
return (copy_verbatim(ucs_name, local_name, local_name_len));
|
||||
|
||||
r = mdn_converter_convert(conv, mdn_converter_u2l,
|
||||
ucs_name, local_name, local_name_len);
|
||||
|
||||
if (r == mdn_nomapping &&
|
||||
(conv = mdn_resconf_alternateconverter(conf)) != NULL) {
|
||||
TRACE(("mdn_res_ucstolocal: switched to alternate converter\n"));
|
||||
r = mdn_converter_convert(conv, mdn_converter_u2l,
|
||||
ucs_name, local_name,
|
||||
local_name_len);
|
||||
}
|
||||
return (r);
|
||||
}
|
||||
|
||||
mdn_result_t
|
||||
mdn_res_normalize(mdn_resconf_t conf, const char *name,
|
||||
char *normalized_name, size_t normalized_name_len)
|
||||
{
|
||||
mdn_normalizer_t norm;
|
||||
|
||||
assert(name != NULL && normalized_name != NULL);
|
||||
|
||||
TRACE(("mdn_res_normalize(name=\"%s\")\n",
|
||||
mdn_debug_xstring(name, 20)));
|
||||
|
||||
if (conf == NULL ||
|
||||
(norm = mdn_resconf_normalizer(conf)) == NULL)
|
||||
return (copy_verbatim(name, normalized_name,
|
||||
normalized_name_len));
|
||||
return (mdn_normalizer_normalize(norm, name, normalized_name,
|
||||
normalized_name_len));
|
||||
}
|
||||
|
||||
mdn_result_t
|
||||
mdn_res_ucstodns(mdn_resconf_t conf, const char *ucs_name, char *dns_name,
|
||||
size_t dns_name_len)
|
||||
{
|
||||
mdn_converter_t conv;
|
||||
mdn_result_t r;
|
||||
const char *zld;
|
||||
|
||||
assert(ucs_name != NULL && dns_name != NULL);
|
||||
|
||||
TRACE(("mdn_res_ucstodns(ucs_name=\"%s\")\n",
|
||||
mdn_debug_xstring(ucs_name, 20)));
|
||||
|
||||
if (conf == NULL ||
|
||||
(conv = mdn_resconf_serverconverter(conf)) == NULL ||
|
||||
!contain_invalid_char(ucs_name))
|
||||
return (copy_verbatim(ucs_name, dns_name, dns_name_len));
|
||||
|
||||
r = mdn_converter_convert(conv, mdn_converter_u2l,
|
||||
ucs_name, dns_name, dns_name_len);
|
||||
if (r != mdn_success)
|
||||
return (r);
|
||||
|
||||
if ((zld = mdn_resconf_zld(conf)) != NULL) {
|
||||
size_t len;
|
||||
|
||||
TRACE(("mdn_res_ucstodns: adding ZLD\n"));
|
||||
len = strlen(dns_name);
|
||||
if (len > 0 && dns_name[len - 1] != '.') {
|
||||
if (len + 1 >= dns_name_len)
|
||||
return (mdn_buffer_overflow);
|
||||
strcpy(dns_name + len, ".");
|
||||
len++;
|
||||
}
|
||||
if (len + strlen(zld) >= dns_name_len)
|
||||
return (mdn_buffer_overflow);
|
||||
(void)strcat(dns_name, zld);
|
||||
}
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
mdn_result_t
|
||||
mdn_res_dnstoucs(mdn_resconf_t conf, const char *dns_name, char *ucs_name,
|
||||
size_t ucs_name_len)
|
||||
{
|
||||
const char *zld;
|
||||
mdn_converter_t conv;
|
||||
char domainbuf[512];
|
||||
int convert;
|
||||
|
||||
assert(dns_name != NULL && ucs_name != NULL);
|
||||
|
||||
TRACE(("mdn_res_dnstoucs(dns_name=\"%s\")\n",
|
||||
mdn_debug_xstring(dns_name, 20)));
|
||||
|
||||
if (conf == NULL ||
|
||||
(conv = mdn_resconf_serverconverter(conf)) == NULL)
|
||||
return (copy_verbatim(dns_name, ucs_name, ucs_name_len));
|
||||
|
||||
if ((zld = mdn_resconf_zld(conf)) != NULL) {
|
||||
if (mdn_translator_matchzld(dns_name, zld)) {
|
||||
/*
|
||||
* Strip 'zld' from 'dns_name'.
|
||||
*/
|
||||
size_t namelen = strlen(dns_name);
|
||||
|
||||
TRACE(("mdn_res_dnstoucs: ZLD matched\n"));
|
||||
/* 'zld' must end with dot, but 'dns_name' may not. */
|
||||
if (namelen > 0 && dns_name[namelen - 1] != '.')
|
||||
namelen++;
|
||||
namelen -= strlen(zld);
|
||||
if (namelen >= sizeof(domainbuf))
|
||||
return (mdn_invalid_name);
|
||||
(void)strncpy(domainbuf, dns_name, namelen);
|
||||
domainbuf[namelen] = '\0';
|
||||
dns_name = domainbuf;
|
||||
convert = 1;
|
||||
} else if (contain_invalid_char(dns_name)) {
|
||||
TRACE(("mdn_res_dnstoucs: contain invalid char\n"));
|
||||
return (mdn_invalid_name);
|
||||
} else {
|
||||
convert = 0;
|
||||
}
|
||||
} else if (!mdn_converter_isasciicompatible(conv) &&
|
||||
!contain_invalid_char(dns_name)) {
|
||||
convert = 0;
|
||||
} else {
|
||||
convert = 1;
|
||||
}
|
||||
|
||||
if (convert) {
|
||||
TRACE(("mdn_res_dnstoucs: convert to ucs\n"));
|
||||
return (mdn_converter_convert(conv, mdn_converter_l2u,
|
||||
dns_name, ucs_name,
|
||||
ucs_name_len));
|
||||
} else {
|
||||
return (copy_verbatim(dns_name, ucs_name, ucs_name_len));
|
||||
}
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
copy_verbatim(const char *from, char *to, size_t tolen) {
|
||||
size_t fromlen = strlen(from) + 1;
|
||||
|
||||
if (tolen < fromlen)
|
||||
return (mdn_buffer_overflow);
|
||||
(void)memcpy(to, from, fromlen);
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
static int
|
||||
contain_invalid_char(const char *name) {
|
||||
int c;
|
||||
|
||||
while ((c = *name++) != '\0') {
|
||||
if (('a' <= c && c <= 'z') ||
|
||||
('A' <= c && c <= 'Z') ||
|
||||
('0' <= c && c <= '9') ||
|
||||
c == '.' || c == '-')
|
||||
continue; /* valid character */
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
468
contrib/idn/mdnkit/lib/resconf.c
Normal file
468
contrib/idn/mdnkit/lib/resconf.c
Normal file
|
|
@ -0,0 +1,468 @@
|
|||
#ifndef lint
|
||||
static char *rcsid = "$Id: resconf.c,v 1.4 2000/09/20 02:47:32 ishisone Exp $";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <mdn/result.h>
|
||||
#include <mdn/assert.h>
|
||||
#include <mdn/logmacro.h>
|
||||
#include <mdn/converter.h>
|
||||
#include <mdn/normalizer.h>
|
||||
#include <mdn/translator.h>
|
||||
#include <mdn/localencoding.h>
|
||||
#include <mdn/resconf.h>
|
||||
#include <mdn/debug.h>
|
||||
|
||||
#ifndef MDN_RESCONF_DIR
|
||||
#define MDN_RESCONF_DIR "/etc"
|
||||
#endif
|
||||
#define MDN_RESCONF_FILE MDN_RESCONF_DIR "/mdnres.conf"
|
||||
|
||||
struct mdn_resconf {
|
||||
char *local_encoding;
|
||||
mdn_converter_t local_converter;
|
||||
mdn_converter_t alternate_converter;
|
||||
mdn_converter_t server_converter;
|
||||
mdn_normalizer_t normalizer;
|
||||
char *zld;
|
||||
int edns0;
|
||||
};
|
||||
|
||||
static mdn_result_t parse_conf(mdn_resconf_t ctx, FILE *fp);
|
||||
static mdn_result_t parse_normalize(mdn_resconf_t ctx, int argc,
|
||||
char **argv);
|
||||
static mdn_result_t parse_alias_file(mdn_resconf_t ctx, int argc,
|
||||
char **argv);
|
||||
static mdn_result_t parse_server_encoding(mdn_resconf_t ctx, int argc,
|
||||
char **argv);
|
||||
static mdn_result_t parse_server_zld(mdn_resconf_t ctx, int argc,
|
||||
char **argv);
|
||||
static mdn_result_t parse_alternate_encoding(mdn_resconf_t ctx, int argc,
|
||||
char **argv);
|
||||
static int split_args(char *s, char **av, int nav);
|
||||
static void resetconf(mdn_resconf_t ctx);
|
||||
static mdn_result_t update_local_converter(mdn_resconf_t ctx);
|
||||
static mdn_result_t mystrdup(const char *from, char **top);
|
||||
|
||||
mdn_result_t
|
||||
mdn_resconf_initialize(void) {
|
||||
mdn_result_t r;
|
||||
|
||||
TRACE(("mdn_resconf_initialize()\n"));
|
||||
|
||||
if ((r = mdn_converter_initialize()) != mdn_success)
|
||||
return (r);
|
||||
if ((r = mdn_normalizer_initialize()) != mdn_success)
|
||||
return (r);
|
||||
return (r);
|
||||
}
|
||||
|
||||
mdn_result_t
|
||||
mdn_resconf_create(mdn_resconf_t *ctxp) {
|
||||
mdn_resconf_t ctx = NULL;
|
||||
|
||||
assert(ctxp != NULL);
|
||||
|
||||
TRACE(("mdn_resconf_create()\n"));
|
||||
|
||||
if ((ctx = malloc(sizeof(*ctx))) == NULL)
|
||||
return (mdn_nomemory);
|
||||
ctx->local_encoding = NULL;
|
||||
ctx->local_converter = NULL;
|
||||
ctx->server_converter = NULL;
|
||||
ctx->alternate_converter = NULL;
|
||||
ctx->normalizer = NULL;
|
||||
ctx->zld = NULL;
|
||||
ctx->edns0 = 0;
|
||||
*ctxp = ctx;
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
char *
|
||||
mdn_resconf_defaultfile() {
|
||||
return MDN_RESCONF_FILE;
|
||||
}
|
||||
|
||||
mdn_result_t
|
||||
mdn_resconf_loadfile(mdn_resconf_t ctx, const char *file) {
|
||||
FILE *fp;
|
||||
mdn_result_t r;
|
||||
|
||||
assert(ctx != NULL);
|
||||
|
||||
TRACE(("mdn_resconf_loadfile(file=%s)\n",
|
||||
file == NULL ? "<null>" : file));
|
||||
|
||||
if ((r = mdn_converter_resetalias()) != mdn_success)
|
||||
return (r);
|
||||
|
||||
resetconf(ctx);
|
||||
|
||||
if (file == NULL)
|
||||
file = mdn_resconf_defaultfile();
|
||||
if ((fp = fopen(file, "r")) == NULL) {
|
||||
TRACE(("mdn_resconf_loadfile: cannot open %-.40s\n", file));
|
||||
return (mdn_nofile);
|
||||
}
|
||||
|
||||
r = parse_conf(ctx, fp);
|
||||
fclose(fp);
|
||||
|
||||
return (r);
|
||||
}
|
||||
|
||||
void
|
||||
mdn_resconf_destroy(mdn_resconf_t ctx) {
|
||||
TRACE(("mdn_resconf_destroy()\n"));
|
||||
resetconf(ctx);
|
||||
free(ctx);
|
||||
}
|
||||
|
||||
mdn_converter_t
|
||||
mdn_resconf_localconverter(mdn_resconf_t ctx) {
|
||||
TRACE(("mdn_resconf_localconverter()\n"));
|
||||
if (update_local_converter(ctx) != mdn_success)
|
||||
return (NULL);
|
||||
return (ctx->local_converter);
|
||||
}
|
||||
|
||||
mdn_converter_t
|
||||
mdn_resconf_serverconverter(mdn_resconf_t ctx) {
|
||||
TRACE(("mdn_resconf_serverconverter()\n"));
|
||||
return (ctx->server_converter);
|
||||
}
|
||||
|
||||
mdn_converter_t
|
||||
mdn_resconf_alternateconverter(mdn_resconf_t ctx) {
|
||||
TRACE(("mdn_resconf_alternateconverter()\n"));
|
||||
return (ctx->alternate_converter);
|
||||
}
|
||||
|
||||
const char *
|
||||
mdn_resconf_zld(mdn_resconf_t ctx) {
|
||||
TRACE(("mdn_resconf_zld()\n"));
|
||||
return (ctx->zld);
|
||||
}
|
||||
|
||||
mdn_normalizer_t
|
||||
mdn_resconf_normalizer(mdn_resconf_t ctx) {
|
||||
TRACE(("mdn_resconf_normalizer()\n"));
|
||||
return (ctx->normalizer);
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
parse_conf(mdn_resconf_t ctx, FILE *fp) {
|
||||
char line[256];
|
||||
char *argv[20];
|
||||
int argc;
|
||||
mdn_result_t r;
|
||||
char *sencoding_line = NULL;
|
||||
char *fencoding_line = NULL;
|
||||
|
||||
/*
|
||||
* Parse config file. parsing of 'server-encoding' and
|
||||
* 'alternate-encoding' lines are postponed because
|
||||
* 'alias-file' line must be processed before them.
|
||||
*/
|
||||
while (fgets(line, sizeof(line), fp) != NULL) {
|
||||
char buf[256];
|
||||
|
||||
if (line[0] == '\n')
|
||||
continue;
|
||||
|
||||
(void)strcpy(buf, line);
|
||||
argc = split_args(buf, argv, 20);
|
||||
if (argc == 0 || argv[0][0] == '#')
|
||||
continue;
|
||||
if (strcmp(argv[0], "normalize") == 0)
|
||||
r = parse_normalize(ctx, argc, argv);
|
||||
else if (strcmp(argv[0], "alias-file") == 0)
|
||||
r = parse_alias_file(ctx, argc, argv);
|
||||
else if (strcmp(argv[0], "server-zld") == 0)
|
||||
r = parse_server_zld(ctx, argc, argv);
|
||||
else if (strcmp(argv[0], "server-encoding") == 0)
|
||||
r = mystrdup(line, &sencoding_line);
|
||||
else if (strcmp(argv[0], "alternate-encoding") == 0)
|
||||
r = mystrdup(line, &fencoding_line);
|
||||
else {
|
||||
mdn_log_error("mdnres: unrecognized command "
|
||||
"\"%-.30s\"\n", argv[0]);
|
||||
r = mdn_invalid_syntax;
|
||||
}
|
||||
if (r != mdn_success)
|
||||
return (r);
|
||||
}
|
||||
|
||||
if (sencoding_line != NULL) {
|
||||
argc = split_args(sencoding_line, argv, 50);
|
||||
r = parse_server_encoding(ctx, argc, argv);
|
||||
free(sencoding_line);
|
||||
if (r != mdn_success)
|
||||
return (r);
|
||||
}
|
||||
if (fencoding_line != NULL) {
|
||||
argc = split_args(fencoding_line, argv, 50);
|
||||
r = parse_alternate_encoding(ctx, argc, argv);
|
||||
free(fencoding_line);
|
||||
if (r != mdn_success)
|
||||
return (r);
|
||||
}
|
||||
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
parse_normalize(mdn_resconf_t ctx, int argc, char **argv) {
|
||||
mdn_result_t r;
|
||||
int i;
|
||||
|
||||
if (ctx->normalizer == NULL) {
|
||||
r = mdn_normalizer_create(&ctx->normalizer);
|
||||
if (r != mdn_success)
|
||||
return (r);
|
||||
}
|
||||
for (i = 1; i < argc; i++) {
|
||||
r = mdn_normalizer_add(ctx->normalizer, argv[i]);
|
||||
if (r != mdn_success) {
|
||||
if (r == mdn_invalid_name)
|
||||
mdn_log_error("mdnres: unknown "
|
||||
"normalization scheme %-.30s\n",
|
||||
argv[i]);
|
||||
return (r);
|
||||
}
|
||||
}
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
parse_alias_file(mdn_resconf_t ctx, int argc, char **argv) {
|
||||
if (argc != 2) {
|
||||
mdn_log_error("mdnres: wrong # of args for %s\n", argv[0]);
|
||||
return (mdn_invalid_syntax);
|
||||
}
|
||||
return (mdn_converter_aliasfile(argv[1]));
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
parse_server_encoding(mdn_resconf_t ctx, int argc, char **argv) {
|
||||
if (argc != 2) {
|
||||
mdn_log_error("mdnres: wrong # of args for %s\n", argv[0]);
|
||||
return (mdn_invalid_syntax);
|
||||
}
|
||||
return (mdn_converter_create(argv[1], &ctx->server_converter,
|
||||
MDN_CONVERTER_DELAYEDOPEN));
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
parse_server_zld(mdn_resconf_t ctx, int argc, char **argv) {
|
||||
#ifdef MDN_SUPPORT_ZLD
|
||||
mdn_result_t r;
|
||||
|
||||
if (argc != 2) {
|
||||
mdn_log_error("mdnres: wrong # of args for %s\n", argv[0]);
|
||||
return (mdn_invalid_syntax);
|
||||
}
|
||||
r = mdn_translator_canonicalzld(argv[1], &ctx->zld);
|
||||
if (r != mdn_success)
|
||||
return (r);
|
||||
|
||||
return (mdn_success);
|
||||
#else
|
||||
mdn_log_warning("mdnres: ZLD support is disabled -- ignored\n");
|
||||
return (mdn_success);
|
||||
#endif /* MDN_SUPPORT_ZLD */
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
parse_alternate_encoding(mdn_resconf_t ctx, int argc, char **argv) {
|
||||
mdn_result_t r;
|
||||
|
||||
if (argc != 2) {
|
||||
mdn_log_error("mdnres: wrong # of args for %s\n", argv[0]);
|
||||
return (mdn_invalid_syntax);
|
||||
}
|
||||
r = mdn_converter_create(argv[1], &ctx->alternate_converter,
|
||||
MDN_CONVERTER_DELAYEDOPEN);
|
||||
if (r == mdn_success &&
|
||||
!mdn_converter_isasciicompatible(ctx->alternate_converter)) {
|
||||
mdn_log_error("mdnres: alternate encoding must be "
|
||||
"ASCII-compatible\n");
|
||||
mdn_converter_destroy(ctx->alternate_converter);
|
||||
ctx->alternate_converter = NULL;
|
||||
return (mdn_invalid_name);
|
||||
}
|
||||
return (r);
|
||||
}
|
||||
|
||||
static int
|
||||
split_args(char *s, char **av, int nav) {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < nav; i++) {
|
||||
while (isspace((unsigned char)*s))
|
||||
s++;
|
||||
if (*s == '\0')
|
||||
break;
|
||||
if (*s == '"' || *s == '\'') {
|
||||
int qc = *s++;
|
||||
av[i] = s;
|
||||
while (*s != '\0' && *s != qc)
|
||||
s++;
|
||||
} else {
|
||||
av[i] = s;
|
||||
while (*s != '\0' && !isspace((unsigned char)*s))
|
||||
s++;
|
||||
}
|
||||
if (*s == '\0')
|
||||
return (i + 1);
|
||||
*s++ = '\0';
|
||||
}
|
||||
return (i);
|
||||
}
|
||||
|
||||
static void
|
||||
resetconf(mdn_resconf_t ctx) {
|
||||
if (ctx->local_encoding != NULL) {
|
||||
free(ctx->local_encoding);
|
||||
ctx->local_encoding = NULL;
|
||||
}
|
||||
if (ctx->local_converter != NULL) {
|
||||
mdn_converter_destroy(ctx->local_converter);
|
||||
ctx->local_converter = NULL;
|
||||
}
|
||||
if (ctx->server_converter != NULL) {
|
||||
mdn_converter_destroy(ctx->server_converter);
|
||||
ctx->server_converter = NULL;
|
||||
}
|
||||
if (ctx->alternate_converter != NULL) {
|
||||
mdn_converter_destroy(ctx->alternate_converter);
|
||||
ctx->alternate_converter = NULL;
|
||||
}
|
||||
if (ctx->normalizer != NULL) {
|
||||
mdn_normalizer_destroy(ctx->normalizer);
|
||||
ctx->normalizer = NULL;
|
||||
}
|
||||
if (ctx->zld != NULL) {
|
||||
free(ctx->zld);
|
||||
ctx->zld = NULL;
|
||||
}
|
||||
ctx->edns0 = 0;
|
||||
}
|
||||
|
||||
|
||||
static mdn_result_t
|
||||
update_local_converter(mdn_resconf_t ctx) {
|
||||
mdn_result_t r;
|
||||
const char *local_encoding = mdn_localencoding_name();
|
||||
|
||||
if (local_encoding == NULL) {
|
||||
mdn_log_error("cannot determine local codeset name\n");
|
||||
return (mdn_notfound);
|
||||
}
|
||||
|
||||
if (ctx->local_encoding != NULL &&
|
||||
strcmp(ctx->local_encoding, local_encoding) == 0 &&
|
||||
ctx->local_converter != NULL) {
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
if (ctx->local_encoding != NULL) {
|
||||
free(ctx->local_encoding);
|
||||
ctx->local_encoding = NULL;
|
||||
}
|
||||
if (ctx->local_converter != NULL) {
|
||||
mdn_converter_destroy(ctx->local_converter);
|
||||
ctx->local_converter = NULL;
|
||||
}
|
||||
|
||||
r = mystrdup(local_encoding, &ctx->local_encoding);
|
||||
if (r != mdn_success)
|
||||
return (r);
|
||||
r = mdn_converter_create(ctx->local_encoding,
|
||||
&ctx->local_converter,
|
||||
MDN_CONVERTER_RTCHECK);
|
||||
return (r);
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
mystrdup(const char *from, char **top) {
|
||||
char *s = malloc(strlen(from) + 1);
|
||||
|
||||
if (*top != NULL) {
|
||||
free(*top);
|
||||
*top = NULL;
|
||||
}
|
||||
|
||||
if (s == NULL)
|
||||
return (mdn_nomemory);
|
||||
(void)strcpy(s, from);
|
||||
*top = s;
|
||||
return (mdn_success);
|
||||
}
|
||||
88
contrib/idn/mdnkit/lib/result.c
Normal file
88
contrib/idn/mdnkit/lib/result.c
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
#ifndef lint
|
||||
static char *rcsid = "$Id: result.c,v 1.9 2000/09/27 02:55:38 ishisone Exp $";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <mdn/result.h>
|
||||
|
||||
static char *result_string[] = {
|
||||
"success",
|
||||
"not found",
|
||||
"invalid encoding found",
|
||||
"syntax error",
|
||||
"invalid name",
|
||||
"invalid message",
|
||||
"buffer overflow",
|
||||
"no such entry",
|
||||
"out of memory",
|
||||
"no such file",
|
||||
"no mapping to output codeset",
|
||||
"context information required",
|
||||
"generic failure",
|
||||
};
|
||||
|
||||
char *
|
||||
mdn_result_tostring(mdn_result_t result) {
|
||||
if (result < 0 || result > mdn_failure)
|
||||
return ("unknown result code");
|
||||
|
||||
return (result_string[result]);
|
||||
}
|
||||
140
contrib/idn/mdnkit/lib/selectiveencode.c
Normal file
140
contrib/idn/mdnkit/lib/selectiveencode.c
Normal file
|
|
@ -0,0 +1,140 @@
|
|||
#ifndef lint
|
||||
static char *rcsid = "$Id: selectiveencode.c,v 1.7 2000/09/20 02:47:32 ishisone Exp $";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include <mdn/assert.h>
|
||||
#include <mdn/logmacro.h>
|
||||
#include <mdn/result.h>
|
||||
#include <mdn/utf8.h>
|
||||
#include <mdn/debug.h>
|
||||
|
||||
static int is_domain_delimiter(char c);
|
||||
static char *find_nonascii(const char *s);
|
||||
|
||||
mdn_result_t
|
||||
mdn_selectiveencode_findregion(const char *s,
|
||||
char **startp, char **endp)
|
||||
{
|
||||
char *non_ascii;
|
||||
char *start, *end;
|
||||
|
||||
assert(s != NULL && startp != NULL && endp != NULL);
|
||||
|
||||
TRACE(("mdn_selectiveencode_findregion(s=\"%s\")\n",
|
||||
mdn_debug_xstring(s, 20)));
|
||||
|
||||
/*
|
||||
* Scan the specified string looking for non-ascii character.
|
||||
*/
|
||||
if ((non_ascii = find_nonascii(s)) == NULL)
|
||||
return (mdn_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 = mdn_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 + mdn_utf8_mblen(non_ascii);
|
||||
while (!is_domain_delimiter(*end))
|
||||
end += mdn_utf8_mblen(end);
|
||||
*endp = end;
|
||||
|
||||
return (mdn_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);
|
||||
}
|
||||
299
contrib/idn/mdnkit/lib/strhash.c
Normal file
299
contrib/idn/mdnkit/lib/strhash.c
Normal file
|
|
@ -0,0 +1,299 @@
|
|||
#ifndef lint
|
||||
static char *rcsid = "$Id: strhash.c,v 1.8 2000/09/20 02:47:32 ishisone Exp $";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <mdn/assert.h>
|
||||
#include <mdn/logmacro.h>
|
||||
#include <mdn/result.h>
|
||||
#include <mdn/strhash.h>
|
||||
|
||||
/*
|
||||
* Initially, the number of hash buckets is INITIAL_HASH_SIZE.
|
||||
* As the more elements are put in the hash, the number of elements
|
||||
* per bucket will exceed THRESHOLD eventually. When it happens,
|
||||
* the number of buckets will be multiplied by FACTOR.
|
||||
*/
|
||||
#define INITIAL_HASH_SIZE 67
|
||||
#define FACTOR 7
|
||||
#define THRESHOLD 5
|
||||
|
||||
#define HASH_MULT 31
|
||||
|
||||
typedef struct strhash_entry {
|
||||
struct strhash_entry *next;
|
||||
unsigned long hash_value;
|
||||
char *key;
|
||||
void *value;
|
||||
} strhash_entry_t;
|
||||
|
||||
struct mdn_strhash {
|
||||
int nbins;
|
||||
int nelements;
|
||||
strhash_entry_t **bins;
|
||||
};
|
||||
|
||||
static unsigned long hash_value(const char *key);
|
||||
static strhash_entry_t *find_entry(strhash_entry_t *entry, const char *key,
|
||||
unsigned long hash);
|
||||
static strhash_entry_t *new_entry(const char *key, void *value);
|
||||
static mdn_result_t expand_bins(mdn_strhash_t hash, int new_size);
|
||||
|
||||
mdn_result_t
|
||||
mdn_strhash_create(mdn_strhash_t *hashp) {
|
||||
mdn_strhash_t hash;
|
||||
mdn_result_t r;
|
||||
|
||||
TRACE(("mdn_strhash_create()\n"));
|
||||
|
||||
assert(hashp != NULL);
|
||||
|
||||
*hashp = NULL;
|
||||
|
||||
if ((hash = malloc(sizeof(struct mdn_strhash))) == NULL) {
|
||||
WARNING(("mdn_strhash_create: malloc failed (hash)\n"));
|
||||
return (mdn_nomemory);
|
||||
}
|
||||
hash->nbins = 0;
|
||||
hash->nelements = 0;
|
||||
hash->bins = NULL;
|
||||
if ((r = expand_bins(hash, INITIAL_HASH_SIZE)) != mdn_success) {
|
||||
WARNING(("mdn_strhash_create: malloc failed (bins)\n"));
|
||||
free(hash);
|
||||
return (r);
|
||||
}
|
||||
|
||||
*hashp = hash;
|
||||
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
void
|
||||
mdn_strhash_destroy(mdn_strhash_t hash, mdn_strhash_freeproc_t proc) {
|
||||
int i;
|
||||
|
||||
assert(hash != NULL && hash->bins != NULL);
|
||||
|
||||
for (i = 0; i < hash->nbins; i++) {
|
||||
strhash_entry_t *bin = hash->bins[i];
|
||||
strhash_entry_t *next;
|
||||
|
||||
while (bin != NULL) {
|
||||
next = bin->next;
|
||||
if (proc != NULL)
|
||||
(*proc)(bin->value);
|
||||
free(bin);
|
||||
bin = next;
|
||||
}
|
||||
}
|
||||
free(hash->bins);
|
||||
free(hash);
|
||||
}
|
||||
|
||||
mdn_result_t
|
||||
mdn_strhash_put(mdn_strhash_t hash, const char *key, void *value) {
|
||||
unsigned long h, h_index;
|
||||
strhash_entry_t *entry;
|
||||
|
||||
assert(hash != NULL && key != NULL);
|
||||
|
||||
h = hash_value(key);
|
||||
h_index = h % hash->nbins;
|
||||
|
||||
if ((entry = find_entry(hash->bins[h_index], key, h)) != NULL) {
|
||||
/* Entry exists. Replace the value. */
|
||||
entry->value = value;
|
||||
} else {
|
||||
/* Create new entry. */
|
||||
if ((entry = new_entry(key, value)) == NULL) {
|
||||
return (mdn_nomemory);
|
||||
}
|
||||
/* Insert it to the list. */
|
||||
entry->next = hash->bins[h_index];
|
||||
hash->bins[h_index] = entry;
|
||||
hash->nelements++;
|
||||
|
||||
if (hash->nelements > hash->nbins * THRESHOLD) {
|
||||
mdn_result_t r;
|
||||
r = expand_bins(hash, hash->nbins * FACTOR);
|
||||
if (r != mdn_success) {
|
||||
TRACE(("mdn_strhash_put: hash table "
|
||||
"expansion failed\n"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
mdn_result_t
|
||||
mdn_strhash_get(mdn_strhash_t hash, const char *key, void **valuep) {
|
||||
unsigned long h;
|
||||
strhash_entry_t *entry;
|
||||
|
||||
assert(hash != NULL && key != NULL && valuep != NULL);
|
||||
|
||||
h = hash_value(key);
|
||||
entry = find_entry(hash->bins[h % hash->nbins], key, h);
|
||||
if (entry == NULL)
|
||||
return (mdn_noentry);
|
||||
|
||||
*valuep = entry->value;
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
int
|
||||
mdn_strhash_exists(mdn_strhash_t hash, const char *key) {
|
||||
unsigned long h;
|
||||
|
||||
assert(hash != NULL && key != NULL);
|
||||
|
||||
h = hash_value(key);
|
||||
return (find_entry(hash->bins[h % hash->nbins], key, h) != NULL);
|
||||
}
|
||||
|
||||
static unsigned long
|
||||
hash_value(const char *key) {
|
||||
unsigned long h = 0;
|
||||
unsigned char *p = (unsigned char *)key;
|
||||
int c;
|
||||
|
||||
while ((c = *p++) != '\0') {
|
||||
h = h * HASH_MULT + c;
|
||||
}
|
||||
return (h);
|
||||
}
|
||||
|
||||
static strhash_entry_t *
|
||||
find_entry(strhash_entry_t *entry, const char *key, unsigned long hash) {
|
||||
assert(key != NULL);
|
||||
|
||||
while (entry != NULL) {
|
||||
if (entry->hash_value == hash && strcmp(key, entry->key) == 0)
|
||||
return (entry);
|
||||
entry = entry->next;
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
static strhash_entry_t *
|
||||
new_entry(const char *key, void *value) {
|
||||
strhash_entry_t *entry;
|
||||
int len;
|
||||
|
||||
assert(key != NULL);
|
||||
|
||||
len = strlen(key) + 1;
|
||||
if ((entry = malloc(sizeof(strhash_entry_t) + len)) == NULL) {
|
||||
return (NULL);
|
||||
}
|
||||
entry->next = NULL;
|
||||
entry->hash_value = hash_value(key);
|
||||
entry->key = (char *)(entry + 1);
|
||||
(void)strcpy(entry->key, key);
|
||||
entry->value = value;
|
||||
|
||||
return (entry);
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
expand_bins(mdn_strhash_t hash, int new_size) {
|
||||
strhash_entry_t **old_bins, **new_bins;
|
||||
int old_size;
|
||||
int old_index, new_index;
|
||||
|
||||
new_bins = malloc(sizeof(strhash_entry_t *) * new_size);
|
||||
if (new_bins == NULL)
|
||||
return (mdn_nomemory);
|
||||
|
||||
memset(new_bins, 0, sizeof(strhash_entry_t *) * new_size);
|
||||
|
||||
old_bins = hash->bins;
|
||||
old_size = hash->nbins;
|
||||
for (old_index = 0; old_index < old_size; old_index++) {
|
||||
strhash_entry_t *entries = old_bins[old_index];
|
||||
|
||||
while (entries != NULL) {
|
||||
strhash_entry_t *e = entries;
|
||||
|
||||
/* Remove the top element from the linked list. */
|
||||
entries = entries->next;
|
||||
|
||||
/* ..and move to the new hash. */
|
||||
new_index = e->hash_value % new_size;
|
||||
e->next = new_bins[new_index];
|
||||
new_bins[new_index] = e;
|
||||
}
|
||||
}
|
||||
|
||||
hash->nbins = new_size;
|
||||
hash->bins = new_bins;
|
||||
|
||||
if (old_bins != NULL)
|
||||
free(old_bins);
|
||||
|
||||
return (mdn_success);
|
||||
}
|
||||
376
contrib/idn/mdnkit/lib/translator.c
Normal file
376
contrib/idn/mdnkit/lib/translator.c
Normal file
|
|
@ -0,0 +1,376 @@
|
|||
#ifndef lint
|
||||
static char *rcsid = "$Id: translator.c,v 1.17 2000/11/21 02:09:05 ishisone Exp $";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <mdn/result.h>
|
||||
#include <mdn/assert.h>
|
||||
#include <mdn/logmacro.h>
|
||||
#include <mdn/converter.h>
|
||||
#include <mdn/normalizer.h>
|
||||
#include <mdn/translator.h>
|
||||
#include <mdn/debug.h>
|
||||
|
||||
static int numdots(const char *s);
|
||||
static int contain_invalid_char(const char *s);
|
||||
static mdn_result_t append_zld(char *s, size_t len, const char *zld);
|
||||
|
||||
mdn_result_t
|
||||
mdn_translator_translate(mdn_converter_t local_converter,
|
||||
mdn_converter_t local_alternate_converter,
|
||||
const char *local_zld,
|
||||
mdn_normalizer_t normalizer,
|
||||
mdn_converter_t target_converter,
|
||||
mdn_converter_t target_alternate_converter,
|
||||
const char *target_zld,
|
||||
const char *from, char *to, size_t tolen)
|
||||
{
|
||||
mdn_result_t r;
|
||||
size_t fromlen;
|
||||
int process;
|
||||
char domainbuf1[512], domainbuf2[512]; /* enough */
|
||||
|
||||
assert(local_converter != NULL && target_converter != NULL &&
|
||||
from != NULL && to != NULL && tolen >= 0);
|
||||
|
||||
TRACE(("mdn_translator_translate(local_encoding=%s,local_zld=%s,"
|
||||
"target_encoding=%s,target_zld=%s,from=\"%s\")\n",
|
||||
mdn_converter_localencoding(local_converter),
|
||||
local_zld == NULL ? "(none)" : local_zld,
|
||||
mdn_converter_localencoding(target_converter),
|
||||
target_zld == NULL ? "(none)" : target_zld,
|
||||
mdn_debug_xstring(from, 30)));
|
||||
|
||||
fromlen = strlen(from);
|
||||
if (fromlen + 1 > sizeof(domainbuf1)) {
|
||||
WARNING(("mdn_translator_translate: "
|
||||
"given domainname too long\n"));
|
||||
return (mdn_invalid_name);
|
||||
}
|
||||
|
||||
(void)strcpy(domainbuf1, from);
|
||||
|
||||
DUMP(("mdn_translator_translate: before translation \"%s\"\n",
|
||||
mdn_debug_xstring(domainbuf1, 200)));
|
||||
|
||||
#define PROCESS_LOCAL 1
|
||||
#define PROCESS_LOCALALT 2
|
||||
#define PROCESS_DONE 4
|
||||
|
||||
process = 0;
|
||||
|
||||
if (local_zld != NULL) {
|
||||
/*
|
||||
* Check if the domain name matches the local ZLD.
|
||||
* If it does, strip ZLD and continue translation.
|
||||
* Otherwise, no further processing is needed.
|
||||
*/
|
||||
if (mdn_translator_matchzld(domainbuf1, local_zld)) {
|
||||
/* Remove ZLD. */
|
||||
domainbuf1[fromlen - strlen(local_zld)] = '\0';
|
||||
process |= PROCESS_LOCAL;
|
||||
if (local_alternate_converter != NULL &&
|
||||
!contain_invalid_char(domainbuf1))
|
||||
process |= PROCESS_LOCALALT;
|
||||
}
|
||||
} else if (contain_invalid_char(domainbuf1)) {
|
||||
/*
|
||||
* The name contains invalid characters (as a legal
|
||||
* traditional domain name). So there's no point in
|
||||
* trying local-alt codeset.
|
||||
*/
|
||||
process |= PROCESS_LOCAL;
|
||||
} else {
|
||||
/*
|
||||
* The given name is a valid ASCII domain name.
|
||||
*/
|
||||
if (mdn_converter_isasciicompatible(local_converter))
|
||||
process |= PROCESS_LOCAL;
|
||||
if (local_alternate_converter != NULL)
|
||||
process |= PROCESS_LOCALALT;
|
||||
}
|
||||
|
||||
if ((process & PROCESS_LOCALALT) != 0) {
|
||||
/*
|
||||
* First, try converting from the alternate encoding to UTF-8.
|
||||
*/
|
||||
TRACE(("mdn_translator_translate: %s to UTF-8\n",
|
||||
mdn_converter_localencoding(
|
||||
local_alternate_converter)));
|
||||
r = mdn_converter_convert(local_alternate_converter,
|
||||
mdn_converter_l2u,
|
||||
domainbuf1, domainbuf2,
|
||||
sizeof(domainbuf2));
|
||||
if (r == mdn_success)
|
||||
process |= PROCESS_DONE;
|
||||
else if (r != mdn_invalid_encoding)
|
||||
return (r);
|
||||
}
|
||||
if ((process & PROCESS_DONE) == 0 && (process & PROCESS_LOCAL) != 0) {
|
||||
/*
|
||||
* Convert from local encoding to UTF-8.
|
||||
*/
|
||||
TRACE(("mdn_translator_translate: %s to UTF-8\n",
|
||||
mdn_converter_localencoding(local_converter)));
|
||||
r = mdn_converter_convert(local_converter,
|
||||
mdn_converter_l2u,
|
||||
domainbuf1, domainbuf2,
|
||||
sizeof(domainbuf2));
|
||||
if (r == mdn_success)
|
||||
process |= PROCESS_DONE;
|
||||
else if (r != mdn_invalid_encoding)
|
||||
return (r);
|
||||
}
|
||||
if ((process & PROCESS_DONE) == 0) {
|
||||
/*
|
||||
* Not converted. Copy verbatim.
|
||||
*/
|
||||
TRACE(("mdn_translator_translate: no translation required\n"));
|
||||
if (tolen < fromlen + 1)
|
||||
return (mdn_buffer_overflow);
|
||||
(void)memcpy(to, from, fromlen + 1);
|
||||
return (mdn_success);
|
||||
}
|
||||
#undef PROCESS_LOCAL
|
||||
#undef PROCESS_LOCALALT
|
||||
#undef PROCESS_DONE
|
||||
|
||||
DUMP(("mdn_translator_translate: UTF-8 string \"%s\"\n",
|
||||
mdn_debug_xstring(domainbuf2, 200)));
|
||||
|
||||
/*
|
||||
* Normalize, if normalizer is specified.
|
||||
*/
|
||||
if (normalizer != NULL) {
|
||||
r = mdn_normalizer_normalize(normalizer,
|
||||
domainbuf2, domainbuf1,
|
||||
sizeof(domainbuf1));
|
||||
if (r != mdn_success)
|
||||
return (r);
|
||||
|
||||
DUMP(("mdn_translator_translate: after normalization \"%s\"\n",
|
||||
mdn_debug_xstring(domainbuf1, 200)));
|
||||
|
||||
if (numdots(domainbuf2) != numdots(domainbuf1)) {
|
||||
INFO(("mdn_translator_translate: "
|
||||
"number of labels has been changed by "
|
||||
"normalization\n"));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert from UTF-8 to target encoding.
|
||||
*/
|
||||
TRACE(("mdn_translator_translate: UTF-8 to %s\n",
|
||||
mdn_converter_localencoding(target_converter)));
|
||||
r = mdn_converter_convert(target_converter,
|
||||
mdn_converter_u2l,
|
||||
normalizer == NULL ?
|
||||
domainbuf2 : domainbuf1,
|
||||
to, tolen);
|
||||
if (r == mdn_nomapping && target_alternate_converter != NULL) {
|
||||
TRACE(("mdn_translator_translate: use alternate encoding\n"));
|
||||
r = mdn_converter_convert(target_alternate_converter,
|
||||
mdn_converter_u2l,
|
||||
normalizer == NULL ?
|
||||
domainbuf2 : domainbuf1,
|
||||
to, tolen);
|
||||
}
|
||||
if (r != mdn_success)
|
||||
return (r);
|
||||
|
||||
/*
|
||||
* Append ZLD, if any.
|
||||
*/
|
||||
if (target_zld != NULL)
|
||||
r = append_zld(to, tolen, target_zld);
|
||||
|
||||
DUMP(("mdn_translator_translate: after translation \"%s\"\n",
|
||||
mdn_debug_xstring(to, 200)));
|
||||
|
||||
return (r);
|
||||
}
|
||||
|
||||
int
|
||||
mdn_translator_matchzld(const char *domain, const char *zld) {
|
||||
int dlen;
|
||||
int zlen;
|
||||
const char *p;
|
||||
int i;
|
||||
|
||||
/* An empty ZLD can match everything. */
|
||||
if (zld == NULL)
|
||||
return (1);
|
||||
|
||||
dlen = strlen(domain);
|
||||
zlen = strlen(zld);
|
||||
|
||||
/*
|
||||
* Since ZLD is canonicalized, it must end with dot.
|
||||
* DOMAIN may or may not end with dot.
|
||||
*/
|
||||
if (dlen > 0 && domain[dlen - 1] != '.')
|
||||
zlen--;
|
||||
|
||||
/* If ZLD is longer than domain, no way. */
|
||||
if (zlen > dlen)
|
||||
return (0);
|
||||
|
||||
p = domain + dlen - zlen;
|
||||
for (i = 0; p[i] != '\0'; i++) {
|
||||
/* ZLD is canonicalized (i.e. uppercase letters) */
|
||||
if (p[i] == zld[i] ||
|
||||
('a' <= p[i] && p[i] <= 'z' && p[i] - 'a' + 'A' == zld[i]))
|
||||
continue;
|
||||
else
|
||||
return (0);
|
||||
}
|
||||
|
||||
if (p > domain && p[-1] != '.')
|
||||
return (0);
|
||||
|
||||
return (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Canonicalize ZLD.
|
||||
* -- empty ZLD are nullified.
|
||||
* -- leading dot is removed.
|
||||
* -- append dot if it does not end with dot.
|
||||
* -- lowercase characters are converted to uppercase.
|
||||
*/
|
||||
mdn_result_t
|
||||
mdn_translator_canonicalzld(const char *zld, char **canonicalizedp) {
|
||||
size_t len;
|
||||
int append_dot = 0;
|
||||
char *canonicalized, *p;
|
||||
int c;
|
||||
|
||||
/* Remove leading '.' */
|
||||
if (zld != NULL && zld[0] == '.')
|
||||
zld++;
|
||||
|
||||
/* Is it empty? */
|
||||
if (zld == NULL || strcmp(zld, "") == 0) {
|
||||
*canonicalizedp = NULL;
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
len = strlen(zld);
|
||||
if (zld[len - 1] != '.')
|
||||
append_dot = 1;
|
||||
|
||||
if ((canonicalized = malloc(len + 1 + append_dot)) == NULL)
|
||||
return (mdn_nomemory);
|
||||
*canonicalizedp = canonicalized;
|
||||
|
||||
for (p = canonicalized; (c = *zld) != '\0'; zld++, p++) {
|
||||
if ('a' <= c && c <= 'z')
|
||||
c += 'A' - 'a';
|
||||
*p = c;
|
||||
}
|
||||
if (append_dot)
|
||||
*p++ = '.';
|
||||
*p = '\0';
|
||||
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
static int
|
||||
numdots(const char *s) {
|
||||
int n = 0;
|
||||
|
||||
while ((s = strchr(s, '.')) != NULL) {
|
||||
n++;
|
||||
s++;
|
||||
}
|
||||
return (n);
|
||||
}
|
||||
|
||||
static int
|
||||
contain_invalid_char(const char *s) {
|
||||
int c;
|
||||
|
||||
while ((c = *s++) != '\0') {
|
||||
if (('a' <= c && c <= 'z') ||
|
||||
('A' <= c && c <= 'Z') ||
|
||||
('0' <= c && c <= '9') ||
|
||||
c == '.' || c == '-')
|
||||
continue; /* valid character */
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
append_zld(char *s, size_t len, const char *zld) {
|
||||
size_t slen = strlen(s);
|
||||
|
||||
if (slen + strlen(zld) + 1 > len)
|
||||
return (mdn_buffer_overflow);
|
||||
(void)strcpy(s + slen, zld);
|
||||
return (mdn_success);
|
||||
}
|
||||
625
contrib/idn/mdnkit/lib/unicode.c
Normal file
625
contrib/idn/mdnkit/lib/unicode.c
Normal file
|
|
@ -0,0 +1,625 @@
|
|||
#ifndef lint
|
||||
static char *rcsid = "$Id: unicode.c,v 1.11 2000/10/16 07:50:53 ishisone Exp $";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#ifdef DEBUG_HASHSTAT
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#include <mdn/result.h>
|
||||
#include <mdn/logmacro.h>
|
||||
#include <mdn/assert.h>
|
||||
#include <mdn/unicode.h>
|
||||
|
||||
#ifndef CANON_CLASS_NBUCKETS
|
||||
#define CANON_CLASS_NBUCKETS 121
|
||||
#endif
|
||||
#ifndef COMPOSITION_NBUCKETS
|
||||
#define COMPOSITION_NBUCKETS 332
|
||||
#endif
|
||||
#ifndef DECOMPOSITION_NBUCKETS
|
||||
#define DECOMPOSITION_NBUCKETS 731
|
||||
#endif
|
||||
#ifndef CASEMAP_NBUCKETS
|
||||
#define CASEMAP_NBUCKETS 269
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Some constants for Hangul decomposition/composition.
|
||||
*/
|
||||
#define SBase 0xac00
|
||||
#define LBase 0x1100
|
||||
#define VBase 0x1161
|
||||
#define TBase 0x11a7
|
||||
#define LCount 19
|
||||
#define VCount 21
|
||||
#define TCount 28
|
||||
#define SLast (SBase + LCount * VCount * TCount)
|
||||
|
||||
typedef unsigned short unicode_t; /* 16bit unsigned integer is suffice */
|
||||
|
||||
struct canon_class {
|
||||
unicode_t c;
|
||||
unsigned short class;
|
||||
struct canon_class *next;
|
||||
};
|
||||
|
||||
struct composition {
|
||||
unicode_t c1;
|
||||
unicode_t c2;
|
||||
unicode_t composed;
|
||||
struct composition *next;
|
||||
};
|
||||
|
||||
struct decomposition {
|
||||
unicode_t c;
|
||||
unsigned short offset;
|
||||
unsigned short length;
|
||||
struct decomposition *next;
|
||||
};
|
||||
|
||||
struct casemap {
|
||||
unicode_t c;
|
||||
unicode_t map;
|
||||
unsigned short flags;
|
||||
unsigned short length;
|
||||
struct casemap *next;
|
||||
};
|
||||
|
||||
#include "unicodedata.c"
|
||||
|
||||
/*
|
||||
* Hash tables.
|
||||
*/
|
||||
|
||||
static struct canon_class *canon_class_hash[CANON_CLASS_NBUCKETS];
|
||||
static struct composition *composition_hash[COMPOSITION_NBUCKETS];
|
||||
static struct decomposition *canon_decomposition_hash[DECOMPOSITION_NBUCKETS];
|
||||
static struct decomposition *compat_decomposition_hash[DECOMPOSITION_NBUCKETS];
|
||||
static struct casemap *toupper_hash[CASEMAP_NBUCKETS];
|
||||
static struct casemap *tolower_hash[CASEMAP_NBUCKETS];
|
||||
|
||||
static int initialized = 0;
|
||||
|
||||
static mdn_result_t casemap(unsigned long c, mdn__unicode_context_t ctx,
|
||||
unsigned long *v, size_t vlen, int *convlenp,
|
||||
unsigned long *bitmap, struct casemap **hash);
|
||||
static int canon_class_hashval(unicode_t c);
|
||||
static int composition_hashval(unicode_t c1, unicode_t c2);
|
||||
static int decomposition_hashval(unicode_t c);
|
||||
static int casemap_hashval(unicode_t c);
|
||||
static void initialize(void);
|
||||
|
||||
|
||||
#define CHECKBIT(v, bitmap, shift) \
|
||||
(((bitmap)[((v)>>(shift)) / 32] & (1 << (((v)>>(shift)) & 31))) != 0)
|
||||
|
||||
int
|
||||
mdn__unicode_canonicalclass(unsigned long c) {
|
||||
struct canon_class *hp;
|
||||
|
||||
#if 0
|
||||
TRACE(("mdn__unicode_canonicalclass(c=%lx)\n", c));
|
||||
#endif
|
||||
|
||||
initialize();
|
||||
|
||||
if (c > 0xffff)
|
||||
return (0);
|
||||
|
||||
if (!CHECKBIT(c, canon_class_bitmap, CANON_CLASS_BM_SHIFT))
|
||||
return (0);
|
||||
|
||||
hp = canon_class_hash[canon_class_hashval((unicode_t)c)];
|
||||
while (hp != NULL) {
|
||||
if (hp->c == c)
|
||||
return (hp->class);
|
||||
hp = hp->next;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
mdn_result_t
|
||||
mdn__unicode_decompose(int compat, unsigned long *v, size_t vlen,
|
||||
unsigned long c, int *decomp_lenp)
|
||||
{
|
||||
unsigned long *vorg = v;
|
||||
int h;
|
||||
struct decomposition *hp;
|
||||
unicode_t *base;
|
||||
int i;
|
||||
|
||||
assert(v != NULL && vlen >= 0 && decomp_lenp != NULL);
|
||||
|
||||
#if 0
|
||||
TRACE(("mdn__unicode_decompose(compat=%d,vlen=%d,c=%lx)\n",
|
||||
compat, vlen, c));
|
||||
#endif
|
||||
|
||||
initialize();
|
||||
|
||||
/*
|
||||
* First, check for Hangul.
|
||||
*/
|
||||
if (SBase <= c && c < SLast) {
|
||||
int idx, t_offset, v_offset, l_offset;
|
||||
|
||||
idx = c - SBase;
|
||||
t_offset = idx % TCount;
|
||||
idx /= TCount;
|
||||
v_offset = idx % VCount;
|
||||
l_offset = idx / VCount;
|
||||
if ((t_offset == 0 && vlen < 2) || (t_offset > 0 && vlen < 3))
|
||||
return (mdn_buffer_overflow);
|
||||
*v++ = LBase + l_offset;
|
||||
*v++ = VBase + v_offset;
|
||||
if (t_offset > 0)
|
||||
*v++ = TBase + t_offset;
|
||||
*decomp_lenp = v - vorg;
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
/*
|
||||
* Check bitmap.
|
||||
*/
|
||||
if (c > 0xffff ||
|
||||
(compat &&
|
||||
!CHECKBIT(c, compat_decompose_bitmap, DECOMPOSE_BM_SHIFT)) ||
|
||||
(!compat &&
|
||||
!CHECKBIT(c, canon_decompose_bitmap, DECOMPOSE_BM_SHIFT)))
|
||||
return (mdn_notfound);
|
||||
|
||||
/*
|
||||
* Now, C is a decomposition candidate.
|
||||
* Search the hash tables.
|
||||
*/
|
||||
h = decomposition_hashval((unicode_t)c);
|
||||
|
||||
/*
|
||||
* First, look for canonical decomposition.
|
||||
*/
|
||||
base = canon_decompose_data;
|
||||
hp = canon_decomposition_hash[h];
|
||||
while (hp != NULL) {
|
||||
if (hp->c == c)
|
||||
goto found;
|
||||
hp = hp->next;
|
||||
}
|
||||
|
||||
if (!compat)
|
||||
return (mdn_notfound);
|
||||
|
||||
/*
|
||||
* Then, compatibility decomposition.
|
||||
*/
|
||||
base = compat_decompose_data;
|
||||
hp = compat_decomposition_hash[h];
|
||||
while (hp != NULL) {
|
||||
if (hp->c == c)
|
||||
goto found;
|
||||
hp = hp->next;
|
||||
}
|
||||
|
||||
return (mdn_notfound);
|
||||
|
||||
found:
|
||||
/* Do we have enough space? */
|
||||
if (vlen < hp->length)
|
||||
return (mdn_buffer_overflow);
|
||||
|
||||
base += hp->offset;
|
||||
for (i = 0; i < hp->length; i++) {
|
||||
mdn_result_t r;
|
||||
int len;
|
||||
|
||||
/* Decompose recursively. */
|
||||
r = mdn__unicode_decompose(compat, v, vlen, base[i], &len);
|
||||
|
||||
if (r == mdn_success) {
|
||||
v += len;
|
||||
vlen -= len;
|
||||
} else {
|
||||
*v++ = base[i];
|
||||
vlen--;
|
||||
}
|
||||
}
|
||||
*decomp_lenp = v - vorg;
|
||||
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
int
|
||||
mdn__unicode_iscompositecandidate(unsigned long c) {
|
||||
#if 0
|
||||
TRACE(("mdn__unicode_iscompositecandidate(c=%lx)\n", c));
|
||||
#endif
|
||||
return (c <= 0xffff &&
|
||||
((LBase <= c && c < LBase + LCount) ||
|
||||
(SBase <= c && c < SLast) ||
|
||||
CHECKBIT(c, compose_bitmap, COMPOSE_BM_SHIFT)));
|
||||
}
|
||||
|
||||
mdn_result_t
|
||||
mdn__unicode_compose(unsigned long c1, unsigned long c2, unsigned long *compp)
|
||||
{
|
||||
struct composition *hp;
|
||||
|
||||
assert(compp != NULL);
|
||||
|
||||
#if 0
|
||||
TRACE(("mdn__unicode_compose(c1=%lx,c2=%lx)\n", c1, c2));
|
||||
#endif
|
||||
|
||||
initialize();
|
||||
|
||||
/*
|
||||
* Check for Hangul.
|
||||
*/
|
||||
if (LBase <= c1 && c1 < LBase + LCount &&
|
||||
VBase <= c2 && c2 < VBase + VCount) {
|
||||
/*
|
||||
* Hangul L and V.
|
||||
*/
|
||||
*compp = SBase +
|
||||
((c1 - LBase) * VCount + (c2 - VBase)) * TCount;
|
||||
return (mdn_success);
|
||||
} else if (SBase <= c1 && c1 < SLast &&
|
||||
TBase <= c2 && c2 < TBase + TCount &&
|
||||
(c1 - SBase) % TCount == 0) {
|
||||
/*
|
||||
* Hangul LV and T.
|
||||
*/
|
||||
*compp = c1 + (c2 - TBase);
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
/*
|
||||
* Check bitmap.
|
||||
*/
|
||||
if (c1 > 0xffff || c2 > 0xffff ||
|
||||
!CHECKBIT(c1, compose_bitmap, COMPOSE_BM_SHIFT))
|
||||
return (mdn_notfound);
|
||||
|
||||
/*
|
||||
* Composition candidate. Search the hash table.
|
||||
*/
|
||||
hp = composition_hash[composition_hashval((unicode_t)c1,
|
||||
(unicode_t)c2)];
|
||||
while (hp != NULL) {
|
||||
if (hp->c1 == c1 && hp->c2 == c2) {
|
||||
*compp = hp->composed;
|
||||
return (mdn_success);
|
||||
}
|
||||
hp = hp->next;
|
||||
}
|
||||
return (mdn_notfound);
|
||||
}
|
||||
|
||||
mdn_result_t
|
||||
mdn__unicode_toupper(unsigned long c, mdn__unicode_context_t ctx,
|
||||
unsigned long *v, size_t vlen, int *convlenp)
|
||||
{
|
||||
#if 0
|
||||
TRACE(("mdn__unicode_toupper(c=%lx)\n", c));
|
||||
#endif
|
||||
initialize();
|
||||
return (casemap(c, ctx, v, vlen, convlenp,
|
||||
toupper_bitmap, toupper_hash));
|
||||
}
|
||||
|
||||
mdn_result_t
|
||||
mdn__unicode_tolower(unsigned long c, mdn__unicode_context_t ctx,
|
||||
unsigned long *v, size_t vlen, int *convlenp)
|
||||
{
|
||||
#if 0
|
||||
TRACE(("mdn__unicode_tolower(c=%lx)\n", c));
|
||||
#endif
|
||||
initialize();
|
||||
return (casemap(c, ctx, v, vlen, convlenp,
|
||||
tolower_bitmap, tolower_hash));
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
casemap(unsigned long c, mdn__unicode_context_t ctx,
|
||||
unsigned long *v, size_t vlen, int *convlenp,
|
||||
unsigned long *bitmap, struct casemap **hash)
|
||||
{
|
||||
struct casemap *hp;
|
||||
|
||||
if (vlen < 1)
|
||||
return (mdn_buffer_overflow);
|
||||
|
||||
if (c > 0xffff)
|
||||
goto one_to_one;
|
||||
|
||||
if (!CHECKBIT(c, bitmap, CASEMAP_BM_SHIFT))
|
||||
goto one_to_one;
|
||||
|
||||
hp = hash[casemap_hashval((unicode_t)c)];
|
||||
while (hp != NULL) {
|
||||
if (hp->c == c) {
|
||||
if ((hp->flags & CMF_CTXDEP) == 0) {
|
||||
found:
|
||||
if (hp->flags & CMF_MULTICHAR) {
|
||||
int len = hp->length;
|
||||
unicode_t *up;
|
||||
|
||||
if (vlen < hp->length)
|
||||
return (mdn_buffer_overflow);
|
||||
up = multichar_casemap_data +
|
||||
(unsigned int)hp->map;
|
||||
*convlenp = len;
|
||||
while (len-- > 0)
|
||||
*v++ = (unsigned long)*up++;
|
||||
return (mdn_success);
|
||||
} else {
|
||||
c = hp->map;
|
||||
goto one_to_one;
|
||||
}
|
||||
} else if (ctx == mdn__unicode_context_unknown) {
|
||||
return (mdn_context_required);
|
||||
} else if (((hp->flags & CMF_FINAL) &&
|
||||
ctx == mdn__unicode_context_final) ||
|
||||
((hp->flags & CMF_NONFINAL) &&
|
||||
ctx == mdn__unicode_context_nonfinal)) {
|
||||
goto found;
|
||||
}
|
||||
}
|
||||
hp = hp->next;
|
||||
}
|
||||
|
||||
one_to_one:
|
||||
*convlenp = 1;
|
||||
*v = c;
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
mdn__unicode_context_t
|
||||
mdn__unicode_getcontext(unsigned long c) {
|
||||
int idx;
|
||||
int offset;
|
||||
unsigned long *bm;
|
||||
int v;
|
||||
|
||||
#if 0
|
||||
TRACE(("mdn__unicode_getcontext(c=%lx)\n", c));
|
||||
#endif
|
||||
|
||||
if (c > 0xffff) {
|
||||
return (mdn__unicode_context_final);
|
||||
}
|
||||
idx = c / CTX_BLOCK_SZ;
|
||||
offset = c % CTX_BLOCK_SZ;
|
||||
if ((bm = casemap_ctx_sections[idx]) == NULL) {
|
||||
return (mdn__unicode_context_final);
|
||||
}
|
||||
v = (bm[(offset * 2) / 32] >> ((offset * 2) % 32)) & 3;
|
||||
if (v & CTX_NSM)
|
||||
return (mdn__unicode_context_unknown);
|
||||
else if (v & CTX_CASED)
|
||||
return (mdn__unicode_context_nonfinal);
|
||||
else
|
||||
return (mdn__unicode_context_final);
|
||||
}
|
||||
|
||||
static int
|
||||
canon_class_hashval(unicode_t c) {
|
||||
return c % CANON_CLASS_NBUCKETS;
|
||||
}
|
||||
|
||||
static int
|
||||
composition_hashval(unicode_t c1, unicode_t c2) {
|
||||
return (c1 * 11 + c2) % COMPOSITION_NBUCKETS;
|
||||
}
|
||||
|
||||
static int
|
||||
decomposition_hashval(unicode_t c) {
|
||||
return c % DECOMPOSITION_NBUCKETS;
|
||||
}
|
||||
|
||||
static int
|
||||
casemap_hashval(unicode_t c) {
|
||||
return c % CASEMAP_NBUCKETS;
|
||||
}
|
||||
|
||||
static void
|
||||
initialize(void) {
|
||||
int i;
|
||||
|
||||
if (initialized)
|
||||
return;
|
||||
|
||||
#define ARRAYSIZE(var) (sizeof(var) / sizeof((var)[0]))
|
||||
#define INSERT(tbl, h, what) \
|
||||
(what).next = (tbl)[h]; \
|
||||
(tbl)[h] = &(what)
|
||||
|
||||
for (i = 0; i < ARRAYSIZE(canon_class); i++) {
|
||||
int h = canon_class_hashval(canon_class[i].c);
|
||||
INSERT(canon_class_hash, h, canon_class[i]);
|
||||
}
|
||||
for (i = 0; i < ARRAYSIZE(compose_seq); i++) {
|
||||
int h = composition_hashval(compose_seq[i].c1,
|
||||
compose_seq[i].c2);
|
||||
INSERT(composition_hash, h, compose_seq[i]);
|
||||
}
|
||||
for (i = 0; i < ARRAYSIZE(canon_decompose_seq); i++) {
|
||||
int h = decomposition_hashval(canon_decompose_seq[i].c);
|
||||
INSERT(canon_decomposition_hash, h, canon_decompose_seq[i]);
|
||||
}
|
||||
for (i = 0; i < ARRAYSIZE(compat_decompose_seq); i++) {
|
||||
int h = decomposition_hashval(compat_decompose_seq[i].c);
|
||||
INSERT(compat_decomposition_hash, h, compat_decompose_seq[i]);
|
||||
}
|
||||
for (i = 0; i < ARRAYSIZE(toupper_map); i++) {
|
||||
int h = casemap_hashval(toupper_map[i].c);
|
||||
INSERT(toupper_hash, h, toupper_map[i]);
|
||||
}
|
||||
for (i = 0; i < ARRAYSIZE(tolower_map); i++) {
|
||||
int h = casemap_hashval(tolower_map[i].c);
|
||||
INSERT(tolower_hash, h, tolower_map[i]);
|
||||
}
|
||||
#undef ARRAYSIZE
|
||||
#undef INSERT
|
||||
|
||||
initialized = 1;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_HASHSTAT
|
||||
|
||||
#define DEFINE_GETLENGTH(name, type) \
|
||||
static int \
|
||||
name(type p) { \
|
||||
int len = 0; \
|
||||
while (p != NULL) { \
|
||||
len++; \
|
||||
p = p->next; \
|
||||
} \
|
||||
return (len); \
|
||||
}
|
||||
|
||||
DEFINE_GETLENGTH(getlength_canon_class, struct canon_class *)
|
||||
DEFINE_GETLENGTH(getlength_composition, struct composition *)
|
||||
DEFINE_GETLENGTH(getlength_decomposition, struct decomposition *)
|
||||
DEFINE_GETLENGTH(getlength_casemap, struct casemap *)
|
||||
|
||||
static void
|
||||
print_hash_stat(void) {
|
||||
int i;
|
||||
int len;
|
||||
int total, max;
|
||||
|
||||
#define LENGTH(n) total += (n); if ((n) > max) {max = (n);}
|
||||
#define PRINT(nb) \
|
||||
printf("\n nbuckets=%d, total=%d, max=%d (avr=%f)\n", \
|
||||
nb, total, max, (double)total / nb)
|
||||
|
||||
#if 1
|
||||
printf("canon_class hash:\n ");
|
||||
for (i = total = max = 0; i < CANON_CLASS_NBUCKETS; i++) {
|
||||
len = getlength_canon_class(canon_class_hash[i]);
|
||||
LENGTH(len);
|
||||
printf("%d ", len);
|
||||
}
|
||||
PRINT(CANON_CLASS_NBUCKETS);
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
printf("composition hash:\n ");
|
||||
for (i = total = max = 0; i < COMPOSITION_NBUCKETS; i++) {
|
||||
len = getlength_composition(composition_hash[i]);
|
||||
LENGTH(len);
|
||||
printf("%d ", len);
|
||||
}
|
||||
PRINT(COMPOSITION_NBUCKETS);
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
printf("canonical decomposition hash:\n ");
|
||||
for (i = total = max = 0; i < DECOMPOSITION_NBUCKETS; i++) {
|
||||
len = getlength_decomposition(canon_decomposition_hash[i]);
|
||||
LENGTH(len);
|
||||
printf("%d ", len);
|
||||
}
|
||||
PRINT(DECOMPOSITION_NBUCKETS);
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
printf("compatibility decomposition hash:\n ");
|
||||
for (i = total = max = 0; i < DECOMPOSITION_NBUCKETS; i++) {
|
||||
len = getlength_decomposition(compat_decomposition_hash[i]);
|
||||
LENGTH(len);
|
||||
printf("%d ", len);
|
||||
}
|
||||
PRINT(DECOMPOSITION_NBUCKETS);
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
printf("toupper hash:\n ");
|
||||
for (i = total = max = 0; i < CASEMAP_NBUCKETS; i++) {
|
||||
len = getlength_casemap(toupper_hash[i]);
|
||||
LENGTH(len);
|
||||
printf("%d ", len);
|
||||
}
|
||||
PRINT(CASEMAP_NBUCKETS);
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
printf("tolower hash:\n ");
|
||||
for (i = total = max = 0; i < CASEMAP_NBUCKETS; i++) {
|
||||
len = getlength_casemap(tolower_hash[i]);
|
||||
LENGTH(len);
|
||||
printf("%d ", len);
|
||||
}
|
||||
PRINT(CASEMAP_NBUCKETS);
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
main(int ac, char **av) {
|
||||
initialize();
|
||||
print_hash_stat();
|
||||
}
|
||||
#endif /* DEBUG_HASHSTAT */
|
||||
3209
contrib/idn/mdnkit/lib/unicodedata.c
Normal file
3209
contrib/idn/mdnkit/lib/unicodedata.c
Normal file
File diff suppressed because it is too large
Load diff
459
contrib/idn/mdnkit/lib/unormalize.c
Normal file
459
contrib/idn/mdnkit/lib/unormalize.c
Normal file
|
|
@ -0,0 +1,459 @@
|
|||
#ifndef lint
|
||||
static char *rcsid = "$Id: unormalize.c,v 1.14 2000/10/13 05:34:48 ishisone Exp $";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#ifdef DEBUG_HASHSTAT
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#include <mdn/result.h>
|
||||
#include <mdn/assert.h>
|
||||
#include <mdn/logmacro.h>
|
||||
#include <mdn/utf8.h>
|
||||
#include <mdn/unicode.h>
|
||||
#include <mdn/unormalize.h>
|
||||
#include <mdn/debug.h>
|
||||
|
||||
#if !defined(HAVE_MEMMOVE) && defined(HAVE_BCOPY)
|
||||
#define memmove(a,b,c) bcopy((char *)(b),(char *)(a),(int)(c))
|
||||
#endif
|
||||
|
||||
#define WORKBUF_SIZE 128
|
||||
#define WORKBUF_SIZE_MAX 10000
|
||||
|
||||
typedef struct {
|
||||
int cur; /* pointing now processing character */
|
||||
int last; /* pointing just after the last character */
|
||||
int size; /* size of UCS and CLASS array */
|
||||
unsigned long *ucs; /* UCS-4 characters */
|
||||
int *class; /* and their canonical classes */
|
||||
unsigned long ucs_buf[WORKBUF_SIZE]; /* local buffer */
|
||||
int class_buf[WORKBUF_SIZE]; /* ditto */
|
||||
} workbuf_t;
|
||||
|
||||
static mdn_result_t normalize(int do_composition, int compat,
|
||||
const char *from, char *to, size_t tolen);
|
||||
static mdn_result_t decompose(workbuf_t *wb, unsigned long c, int compat);
|
||||
static void get_class(workbuf_t *wb);
|
||||
static void reorder(workbuf_t *wb);
|
||||
static void compose(workbuf_t *wb);
|
||||
static mdn_result_t flush_before_cur(workbuf_t *wb,
|
||||
char **top, size_t *tolenp);
|
||||
static void workbuf_init(workbuf_t *wb);
|
||||
static void workbuf_free(workbuf_t *wb);
|
||||
static mdn_result_t workbuf_extend(workbuf_t *wb);
|
||||
static mdn_result_t workbuf_append(workbuf_t *wb, unsigned long c);
|
||||
static void workbuf_shift(workbuf_t *wb, int shift);
|
||||
static void workbuf_removevoid(workbuf_t *wb);
|
||||
|
||||
|
||||
mdn_result_t
|
||||
mdn__unormalize_formc(const char *from, char *to, size_t tolen) {
|
||||
assert(from != NULL && to != NULL && tolen >= 0);
|
||||
TRACE(("mdn__unormalize_formc(from=\"%s\", tolen=%d)\n",
|
||||
mdn_debug_xstring(from, 20), tolen));
|
||||
return (normalize(1, 0, from, to, tolen));
|
||||
}
|
||||
|
||||
mdn_result_t
|
||||
mdn__unormalize_formd(const char *from, char *to, size_t tolen) {
|
||||
assert(from != NULL && to != NULL && tolen >= 0);
|
||||
TRACE(("mdn__unormalize_formd(from=\"%s\", tolen=%d)\n",
|
||||
mdn_debug_xstring(from, 20), tolen));
|
||||
return (normalize(0, 0, from, to, tolen));
|
||||
}
|
||||
|
||||
mdn_result_t
|
||||
mdn__unormalize_formkc(const char *from, char *to, size_t tolen) {
|
||||
assert(from != NULL && to != NULL && tolen >= 0);
|
||||
TRACE(("mdn__unormalize_formkc(from=\"%s\", tolen=%d)\n",
|
||||
mdn_debug_xstring(from, 20), tolen));
|
||||
return (normalize(1, 1, from, to, tolen));
|
||||
}
|
||||
|
||||
mdn_result_t
|
||||
mdn__unormalize_formkd(const char *from, char *to, size_t tolen) {
|
||||
assert(from != NULL && to != NULL && tolen >= 0);
|
||||
TRACE(("mdn__unormalize_formkd(from=\"%s\", tolen=%d)\n",
|
||||
mdn_debug_xstring(from, 20), tolen));
|
||||
return (normalize(0, 1, from, to, tolen));
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
normalize(int do_composition, int compat,
|
||||
const char *from, char *to, size_t tolen)
|
||||
{
|
||||
workbuf_t wb;
|
||||
size_t fromlen = strlen(from);
|
||||
mdn_result_t r = mdn_success;
|
||||
|
||||
/*
|
||||
* Initialize working buffer.
|
||||
*/
|
||||
workbuf_init(&wb);
|
||||
|
||||
while (fromlen > 0) {
|
||||
unsigned long c;
|
||||
int mblen;
|
||||
|
||||
assert(wb.cur == wb.last);
|
||||
|
||||
/*
|
||||
* Get one character from 'from'.
|
||||
*/
|
||||
if ((mblen = mdn_utf8_getwc(from, fromlen, &c)) == 0) {
|
||||
r = mdn_invalid_encoding;
|
||||
break;
|
||||
}
|
||||
from += mblen;
|
||||
fromlen -= mblen;
|
||||
|
||||
/*
|
||||
* Decompose it.
|
||||
*/
|
||||
if ((r = decompose(&wb, c, compat)) != mdn_success)
|
||||
break;
|
||||
|
||||
/*
|
||||
* Get canonical class.
|
||||
*/
|
||||
get_class(&wb);
|
||||
|
||||
/*
|
||||
* Reorder & compose.
|
||||
*/
|
||||
for (; wb.cur < wb.last; wb.cur++) {
|
||||
if (wb.cur == 0) {
|
||||
continue;
|
||||
} else if (wb.class[wb.cur] > 0) {
|
||||
/*
|
||||
* This is not a starter. Try reordering.
|
||||
* Note that characters up to it are
|
||||
* already in canonical order.
|
||||
*/
|
||||
reorder(&wb);
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
* This is a starter character, and there are
|
||||
* some characters before it. Those characters
|
||||
* have been reordered properly, and
|
||||
* ready for composition.
|
||||
*/
|
||||
if (do_composition && wb.class[0] == 0)
|
||||
compose(&wb);
|
||||
|
||||
/*
|
||||
* If CUR points to a starter character,
|
||||
* then process of characters before CUR are
|
||||
* already finished, because any further
|
||||
* reordering/composition for them are blocked
|
||||
* by the starter CUR points.
|
||||
*/
|
||||
if (wb.cur > 0 && wb.class[wb.cur] == 0) {
|
||||
/* Flush everything before CUR. */
|
||||
r = flush_before_cur(&wb, &to, &tolen);
|
||||
if (r != mdn_success)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (r == mdn_success) {
|
||||
if (do_composition && wb.cur > 0 && wb.class[0] == 0) {
|
||||
/*
|
||||
* There is some characters left in WB.
|
||||
* They are ordered, but not composed yet.
|
||||
* Now CUR points just after the last character in WB,
|
||||
* and since compose() tries to compose characters
|
||||
* between top and CUR inclusive, we must make CUR
|
||||
* one character back during compose().
|
||||
*/
|
||||
wb.cur--;
|
||||
compose(&wb);
|
||||
wb.cur++;
|
||||
}
|
||||
/*
|
||||
* Call this even when WB.CUR == 0, to make TO
|
||||
* NUL-terminated.
|
||||
*/
|
||||
r = flush_before_cur(&wb, &to, &tolen);
|
||||
}
|
||||
|
||||
workbuf_free(&wb);
|
||||
return (r);
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
decompose(workbuf_t *wb, unsigned long c, int compat) {
|
||||
mdn_result_t r;
|
||||
int dec_len;
|
||||
|
||||
again:
|
||||
r = mdn__unicode_decompose(compat, wb->ucs + wb->last,
|
||||
wb->size - wb->last,
|
||||
c, &dec_len);
|
||||
switch (r) {
|
||||
case mdn_success:
|
||||
wb->last += dec_len;
|
||||
return (mdn_success);
|
||||
case mdn_notfound:
|
||||
return (workbuf_append(wb, c));
|
||||
case mdn_buffer_overflow:
|
||||
if ((r = workbuf_extend(wb)) != mdn_success)
|
||||
return (r);
|
||||
if (wb->size > WORKBUF_SIZE_MAX) {
|
||||
WARNING(("mdn__unormalize_form*: "
|
||||
"working buffer too large\n"));
|
||||
return (mdn_nomemory);
|
||||
}
|
||||
goto again;
|
||||
default:
|
||||
return (r);
|
||||
}
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
static void
|
||||
get_class(workbuf_t *wb) {
|
||||
int i;
|
||||
|
||||
for (i = wb->cur; i < wb->last; i++)
|
||||
wb->class[i] = mdn__unicode_canonicalclass(wb->ucs[i]);
|
||||
}
|
||||
|
||||
static void
|
||||
reorder(workbuf_t *wb) {
|
||||
unsigned long c;
|
||||
int i;
|
||||
int class;
|
||||
|
||||
assert(wb != NULL);
|
||||
|
||||
i = wb->cur;
|
||||
c = wb->ucs[i];
|
||||
class = wb->class[i];
|
||||
|
||||
while (i > 0 && wb->class[i - 1] > class) {
|
||||
wb->ucs[i] = wb->ucs[i - 1];
|
||||
wb->class[i] =wb->class[i - 1];
|
||||
i--;
|
||||
wb->ucs[i] = c;
|
||||
wb->class[i] = class;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
compose(workbuf_t *wb) {
|
||||
int cur;
|
||||
unsigned long *ucs;
|
||||
int *class;
|
||||
int last_class;
|
||||
int nvoids;
|
||||
int i;
|
||||
|
||||
assert(wb != NULL && wb->class[0] == 0);
|
||||
|
||||
cur = wb->cur;
|
||||
ucs = wb->ucs;
|
||||
class = wb->class;
|
||||
|
||||
/*
|
||||
* If there are no decomposition sequence that begins with
|
||||
* the top character, composition is impossible.
|
||||
*/
|
||||
if (!mdn__unicode_iscompositecandidate(ucs[0]))
|
||||
return;
|
||||
|
||||
last_class = 0;
|
||||
nvoids = 0;
|
||||
for (i = 1; i <= cur; i++) {
|
||||
unsigned long c;
|
||||
int cl = class[i];
|
||||
|
||||
if ((last_class < cl || cl == 0) &&
|
||||
mdn__unicode_compose(ucs[0], ucs[i], &c) == mdn_success) {
|
||||
/*
|
||||
* Replace the top character with the composed one.
|
||||
*/
|
||||
ucs[0] = c;
|
||||
class[0] = mdn__unicode_canonicalclass(c);
|
||||
|
||||
class[i] = -1; /* void this character */
|
||||
nvoids++;
|
||||
} else {
|
||||
last_class = cl;
|
||||
}
|
||||
}
|
||||
|
||||
/* Purge void characters, if any. */
|
||||
if (nvoids > 0)
|
||||
workbuf_removevoid(wb);
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
flush_before_cur(workbuf_t *wb, char **top, size_t *tolenp) {
|
||||
int cur = wb->cur;
|
||||
char *to = *top;
|
||||
size_t tolen = *tolenp;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < cur; i++) {
|
||||
int len = mdn_utf8_putwc(to, tolen, wb->ucs[i]);
|
||||
if (len == 0)
|
||||
return (mdn_buffer_overflow);
|
||||
to += len;
|
||||
tolen -= len;
|
||||
}
|
||||
if (tolen < 1)
|
||||
return (mdn_buffer_overflow);
|
||||
*to = '\0';
|
||||
|
||||
*top = to;
|
||||
*tolenp = tolen;
|
||||
|
||||
workbuf_shift(wb, cur);
|
||||
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
static void
|
||||
workbuf_init(workbuf_t *wb) {
|
||||
wb->cur = 0;
|
||||
wb->last = 0;
|
||||
wb->size = WORKBUF_SIZE;
|
||||
wb->ucs = wb->ucs_buf;
|
||||
wb->class = wb->class_buf;
|
||||
}
|
||||
|
||||
static void
|
||||
workbuf_free(workbuf_t *wb) {
|
||||
if (wb->ucs != wb->ucs_buf) {
|
||||
free(wb->ucs);
|
||||
free(wb->class);
|
||||
}
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
workbuf_extend(workbuf_t *wb) {
|
||||
int newsize = wb->size * 3;
|
||||
|
||||
if (wb->ucs == wb->ucs_buf) {
|
||||
wb->ucs = malloc(sizeof(wb->ucs[0]) * newsize);
|
||||
wb->class = malloc(sizeof(wb->class[0]) * newsize);
|
||||
} else {
|
||||
wb->ucs = realloc(wb->ucs, sizeof(wb->ucs[0]) * newsize);
|
||||
wb->class = realloc(wb->class, sizeof(wb->class[0]) * newsize);
|
||||
}
|
||||
if (wb->ucs == NULL || wb->class == NULL)
|
||||
return (mdn_nomemory);
|
||||
else
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
static mdn_result_t
|
||||
workbuf_append(workbuf_t *wb, unsigned long c) {
|
||||
mdn_result_t r;
|
||||
|
||||
if (wb->last >= wb->size && (r = workbuf_extend(wb)) != mdn_success)
|
||||
return (r);
|
||||
wb->ucs[wb->last++] = c;
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
static void
|
||||
workbuf_shift(workbuf_t *wb, int shift) {
|
||||
int nmove;
|
||||
|
||||
assert(wb != NULL && wb->cur >= shift);
|
||||
|
||||
nmove = wb->last - shift;
|
||||
(void)memmove(&wb->ucs[0], &wb->ucs[shift],
|
||||
nmove * sizeof(wb->ucs[0]));
|
||||
(void)memmove(&wb->class[0], &wb->class[shift],
|
||||
nmove * sizeof(wb->class[0]));
|
||||
wb->cur -= shift;
|
||||
wb->last -= shift;
|
||||
}
|
||||
|
||||
static void
|
||||
workbuf_removevoid(workbuf_t *wb) {
|
||||
int i, j;
|
||||
int last = wb->last;
|
||||
|
||||
for (i = j = 0; i < last; i++) {
|
||||
if (wb->class[i] >= 0) {
|
||||
if (j < i) {
|
||||
wb->ucs[j] = wb->ucs[i];
|
||||
wb->class[j] = wb->class[i];
|
||||
}
|
||||
j++;
|
||||
}
|
||||
}
|
||||
wb->cur -= last - j;
|
||||
wb->last = j;
|
||||
}
|
||||
175
contrib/idn/mdnkit/lib/utf5.c
Normal file
175
contrib/idn/mdnkit/lib/utf5.c
Normal file
|
|
@ -0,0 +1,175 @@
|
|||
#ifndef lint
|
||||
static char *rcsid = "$Id: utf5.c,v 1.10 2000/09/20 02:47:33 ishisone Exp $";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include <mdn/assert.h>
|
||||
#include <mdn/logmacro.h>
|
||||
#include <mdn/utf5.h>
|
||||
#include <mdn/debug.h>
|
||||
|
||||
int
|
||||
mdn_utf5_getwc(const char *s, size_t len, unsigned long *vp) {
|
||||
int top = 1;
|
||||
size_t orglen = len;
|
||||
unsigned long v = 0;
|
||||
|
||||
assert(s != NULL && len >= 0 && vp != NULL);
|
||||
|
||||
#if 0
|
||||
TRACE(("mdn_utf5_getwc(s=<%s>,len=%d)\n",
|
||||
mdn_debug_hexstring(s, 10), len));
|
||||
#endif
|
||||
|
||||
if (len == 0)
|
||||
return (0);
|
||||
|
||||
/* Special case for domain name handling. */
|
||||
if (*s == '.') {
|
||||
*vp = '.';
|
||||
return (1);
|
||||
}
|
||||
|
||||
while (len > 0) {
|
||||
int c = *s++;
|
||||
|
||||
if (top) {
|
||||
if ('G' <= c && c <= 'V')
|
||||
v = c - 'G';
|
||||
else if ('g' <= c && c <= 'v')
|
||||
v = c - 'g';
|
||||
else
|
||||
return (0);
|
||||
top = 0;
|
||||
} else {
|
||||
if ('0' <= c && c <= '9')
|
||||
v = (v << 4) + (c - '0');
|
||||
else if ('A' <= c && c <= 'F')
|
||||
v = (v << 4) + (c - 'A' + 10);
|
||||
else if ('a' <= c && c <= 'f')
|
||||
v = (v << 4) + (c - 'a' + 10);
|
||||
else
|
||||
break;
|
||||
}
|
||||
len--;
|
||||
}
|
||||
*vp = v;
|
||||
return (orglen - len);
|
||||
}
|
||||
|
||||
int
|
||||
mdn_utf5_putwc(char *s, size_t len, unsigned long v) {
|
||||
int w;
|
||||
int off;
|
||||
|
||||
assert(s != NULL);
|
||||
|
||||
#if 0
|
||||
TRACE(("mdn_utf5_putwc(v=%lx)\n", v));
|
||||
#endif
|
||||
|
||||
/* Special handling for domain delimiter '.' */
|
||||
if (v == '.') {
|
||||
if (len < 1)
|
||||
return (0);
|
||||
*s = v;
|
||||
return (1);
|
||||
}
|
||||
|
||||
if (v < 0x10) {
|
||||
w = 1;
|
||||
} else if (v < 0x100) {
|
||||
w = 2;
|
||||
} else if (v < 0x1000) {
|
||||
w = 3;
|
||||
} else if (v < 0x10000) {
|
||||
w = 4;
|
||||
} else if (v < 0x100000) {
|
||||
w = 5;
|
||||
} else if (v < 0x1000000) {
|
||||
w = 6;
|
||||
} else if (v < 0x10000000) {
|
||||
w = 7;
|
||||
} else if (v < 0x80000000) {
|
||||
w = 8;
|
||||
} else {
|
||||
return (0);
|
||||
}
|
||||
|
||||
if (len < w)
|
||||
return (0);
|
||||
|
||||
off = (w - 1) * 4;
|
||||
*s++ = 'G' + ((v >> off) & 0xf);
|
||||
off -= 4;
|
||||
while (off >= 0) {
|
||||
int x = (v >> off) & 0xf;
|
||||
if (x < 10)
|
||||
*s++ = '0' + x;
|
||||
else
|
||||
*s++ = 'A' + x - 10;
|
||||
off -= 4;
|
||||
}
|
||||
return (w);
|
||||
}
|
||||
292
contrib/idn/mdnkit/lib/utf8.c
Normal file
292
contrib/idn/mdnkit/lib/utf8.c
Normal file
|
|
@ -0,0 +1,292 @@
|
|||
#ifndef lint
|
||||
static char *rcsid = "$Id: utf8.c,v 1.12 2000/10/25 06:43:00 ishisone Exp $";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include <mdn/assert.h>
|
||||
#include <mdn/logmacro.h>
|
||||
#include <mdn/utf8.h>
|
||||
#include <mdn/debug.h>
|
||||
|
||||
#define UTF8_WIDTH(c) \
|
||||
(((c) < 0x80) ? 1 : \
|
||||
((c) < 0xc0) ? 0 : \
|
||||
((c) < 0xe0) ? 2 : \
|
||||
((c) < 0xf0) ? 3 : \
|
||||
((c) < 0xf8) ? 4 : \
|
||||
((c) < 0xfc) ? 5 : \
|
||||
((c) < 0xfe) ? 6 : 0)
|
||||
|
||||
#define VALID_CONT_BYTE(c) (0x80 <= (c) && (c) < 0xc0)
|
||||
|
||||
int
|
||||
mdn_utf8_mblen(const char *s) {
|
||||
int c = *(unsigned char *)s;
|
||||
|
||||
assert(s != NULL);
|
||||
|
||||
#if 0
|
||||
TRACE(("mdn_utf8_mblen(s=<%s>)\n", mdn_debug_hexstring(s, 6)));
|
||||
#endif
|
||||
|
||||
return UTF8_WIDTH(c);
|
||||
}
|
||||
|
||||
int
|
||||
mdn_utf8_getmb(const char *s, size_t len, char *buf) {
|
||||
/* buf must be at least 7-bytes long */
|
||||
const unsigned char *p = (const unsigned char *)s;
|
||||
unsigned char *q = (unsigned char *)buf;
|
||||
int width = UTF8_WIDTH(*p);
|
||||
int w;
|
||||
|
||||
assert(s != NULL);
|
||||
|
||||
#if 0
|
||||
TRACE(("mdn_utf8_getmb(s=<%s>,len=%d)\n",
|
||||
mdn_debug_hexstring(s, 6), len));
|
||||
#endif
|
||||
|
||||
if (width == 0 || len < width)
|
||||
return (0);
|
||||
|
||||
/* Copy the first byte. */
|
||||
*q++ = *p++;
|
||||
|
||||
/* .. and the rest. */
|
||||
w = width;
|
||||
while (--w > 0) {
|
||||
if (!VALID_CONT_BYTE(*p))
|
||||
return (0);
|
||||
*q++ = *p++;
|
||||
}
|
||||
return (width);
|
||||
}
|
||||
|
||||
extern int
|
||||
mdn_utf8_getwc(const char *s, size_t len, unsigned long *vp) {
|
||||
unsigned long v;
|
||||
unsigned long min;
|
||||
const unsigned char *p = (const unsigned char *)s;
|
||||
int c;
|
||||
int width;
|
||||
int rest;
|
||||
|
||||
assert(s != NULL);
|
||||
|
||||
#if 0
|
||||
TRACE(("mdn_utf8_getwc(s=<%s>,len=%d)\n",
|
||||
mdn_debug_hexstring(s, 10), len));
|
||||
#endif
|
||||
|
||||
c = *p++;
|
||||
width = UTF8_WIDTH(c);
|
||||
|
||||
switch (width) {
|
||||
case 0:
|
||||
return (0);
|
||||
case 1:
|
||||
v = c;
|
||||
min = 0;
|
||||
break;
|
||||
case 2:
|
||||
v = c & 0x1f;
|
||||
min = 0x80;
|
||||
break;
|
||||
case 3:
|
||||
v = c & 0xf;
|
||||
min = 0x800;
|
||||
break;
|
||||
case 4:
|
||||
v = c & 0x7;
|
||||
min = 0x10000;
|
||||
break;
|
||||
case 5:
|
||||
v = c & 3;
|
||||
min = 0x200000;
|
||||
break;
|
||||
case 6:
|
||||
v = c & 1;
|
||||
min = 0x4000000;
|
||||
break;
|
||||
default:
|
||||
FATAL(("mdn_utf8_getint: internal error\n"));
|
||||
return (0);
|
||||
}
|
||||
|
||||
if (len < width)
|
||||
return (0);
|
||||
|
||||
rest = width - 1;
|
||||
while (rest-- > 0) {
|
||||
if (!VALID_CONT_BYTE(*p))
|
||||
return (0);
|
||||
v = (v << 6) | (*p & 0x3f);
|
||||
p++;
|
||||
}
|
||||
|
||||
if (v < min)
|
||||
return (0);
|
||||
|
||||
*vp = v;
|
||||
return (width);
|
||||
}
|
||||
|
||||
extern int
|
||||
mdn_utf8_putwc(char *s, size_t len, unsigned long v) {
|
||||
unsigned char *p = (unsigned char *)s;
|
||||
int mask;
|
||||
int off;
|
||||
int l;
|
||||
|
||||
assert(s != NULL);
|
||||
|
||||
#if 0
|
||||
TRACE(("mdn_utf8_putwc(v=%lx)\n", v));
|
||||
#endif
|
||||
|
||||
if (v < 0x80) {
|
||||
mask = 0;
|
||||
l = 1;
|
||||
} else if (v < 0x800) {
|
||||
mask = 0xc0;
|
||||
l = 2;
|
||||
} else if (v < 0x10000) {
|
||||
mask = 0xe0;
|
||||
l = 3;
|
||||
} else if (v < 0x200000) {
|
||||
mask = 0xf0;
|
||||
l = 4;
|
||||
} else if (v < 0x4000000) {
|
||||
mask = 0xf8;
|
||||
l = 5;
|
||||
} else if (v < 0x80000000) {
|
||||
mask = 0xfc;
|
||||
l = 6;
|
||||
} else {
|
||||
return (0);
|
||||
}
|
||||
|
||||
if (len < l)
|
||||
return (0);
|
||||
|
||||
off = 6 * (l - 1);
|
||||
*p++ = (v >> off) | mask;
|
||||
mask = 0x80;
|
||||
while (off > 0) {
|
||||
off -= 6;
|
||||
*p++ = ((v >> off) & 0x3f) | mask;
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
int
|
||||
mdn_utf8_isvalidchar(const char *s) {
|
||||
unsigned long dummy;
|
||||
|
||||
TRACE(("mdn_utf8_isvalidchar(s=<%s>)\n",
|
||||
mdn_debug_hexstring(s, 6)));
|
||||
|
||||
return (mdn_utf8_getwc(s, 6, &dummy) > 0);
|
||||
}
|
||||
|
||||
int
|
||||
mdn_utf8_isvalidstring(const char *s) {
|
||||
unsigned long dummy;
|
||||
int width;
|
||||
|
||||
assert(s != NULL);
|
||||
|
||||
TRACE(("mdn_utf8_isvalidstring(s=<%s>)\n",
|
||||
mdn_debug_hexstring(s, 20)));
|
||||
|
||||
while (*s != '\0') {
|
||||
width = mdn_utf8_getwc(s, 6, &dummy);
|
||||
if (width == 0)
|
||||
return (0);
|
||||
s += width;
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
char *
|
||||
mdn_utf8_findfirstbyte(const char *s, const char *known_top) {
|
||||
const unsigned char *p = (const unsigned char *)s;
|
||||
const unsigned char *t = (const unsigned char *)known_top;
|
||||
|
||||
assert(s != NULL && known_top != NULL && known_top <= s);
|
||||
|
||||
TRACE(("mdn_utf8_findfirstbyte(s=<%s>)\n",
|
||||
mdn_debug_hexstring(s, 8)));
|
||||
|
||||
while (p >= t) {
|
||||
if (!VALID_CONT_BYTE(*p))
|
||||
break;
|
||||
p--;
|
||||
}
|
||||
if (p < t || UTF8_WIDTH(*p) == 0)
|
||||
return (NULL);
|
||||
|
||||
return ((char *)p);
|
||||
}
|
||||
193
contrib/idn/mdnkit/lib/util.c
Normal file
193
contrib/idn/mdnkit/lib/util.c
Normal file
|
|
@ -0,0 +1,193 @@
|
|||
#ifndef lint
|
||||
static char *rcsid = "$Id: util.c,v 1.2 2000/11/14 00:15:36 ishisone Exp $";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include <mdn/assert.h>
|
||||
#include <mdn/result.h>
|
||||
#include <mdn/logmacro.h>
|
||||
#include <mdn/utf8.h>
|
||||
|
||||
/*
|
||||
* ASCII tolower() macro.
|
||||
* Note that this macro evaluates the argument multiple times. Be careful.
|
||||
*/
|
||||
#define ASCII_TOLOWER(c) \
|
||||
(('A' <= (c) && (c) <= 'Z') ? ((c) - 'A' + 'a') : (c))
|
||||
|
||||
/*
|
||||
* Unicode surrogate pair.
|
||||
*/
|
||||
#define IS_SURROGATE_HIGH(v) (0xd800 <= (v) && (v) <= 0xdbff)
|
||||
#define IS_SURROGATE_LOW(v) (0xdc00 <= (v) && (v) <= 0xdfff)
|
||||
#define SURROGATE_HIGH(v) (SURROGATE_H_OFF + (((v) - 0x10000) >> 10))
|
||||
#define SURROGATE_LOW(v) (SURROGATE_L_OFF + ((v) & 0x3ff))
|
||||
#define SURROGATE_BASE 0x10000
|
||||
#define SURROGATE_H_OFF 0xd800
|
||||
#define SURROGATE_L_OFF 0xdc00
|
||||
#define COMBINE_SURROGATE(h, l) \
|
||||
(SURROGATE_BASE + (((h)-SURROGATE_H_OFF)<<10) + ((l)-SURROGATE_L_OFF))
|
||||
|
||||
int
|
||||
mdn_util_casematch(const char *s1, const char *s2, size_t n) {
|
||||
assert(s1 != NULL && s2 != NULL);
|
||||
|
||||
while (n-- > 0) {
|
||||
if (*s1 != *s2 && ASCII_TOLOWER(*s1) != ASCII_TOLOWER(*s2))
|
||||
return (0);
|
||||
else if (*s1 == '\0')
|
||||
break;
|
||||
s1++;
|
||||
s2++;
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
const char *
|
||||
mdn_util_domainspan(const char *s, const char *end) {
|
||||
while (s < end &&
|
||||
(('a' <= *s && *s <= 'z') ||
|
||||
('A' <= *s && *s <= 'Z') ||
|
||||
('0' <= *s && *s <= '9') ||
|
||||
*s == '-'))
|
||||
s++;
|
||||
return (s);
|
||||
}
|
||||
|
||||
mdn_result_t
|
||||
mdn_util_utf8toutf16(const char *utf8, size_t fromlen,
|
||||
unsigned short *utf16, size_t tolen, size_t *reslenp)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
while (fromlen > 0) {
|
||||
unsigned long v;
|
||||
int flen;
|
||||
|
||||
flen = mdn_utf8_getwc(utf8, fromlen, &v);
|
||||
if (flen == 0) {
|
||||
WARNING(("mdn_util_utf8toutf16: "
|
||||
"invalid character\n"));
|
||||
return (mdn_invalid_encoding);
|
||||
}
|
||||
utf8 += flen;
|
||||
fromlen -= flen;
|
||||
|
||||
if (tolen < 1)
|
||||
return (mdn_buffer_overflow);
|
||||
|
||||
if (IS_SURROGATE_LOW(v) || IS_SURROGATE_HIGH(v)) {
|
||||
WARNING(("mdn_util_utf8toutf16: UTF-8 string contains "
|
||||
"surrogate pair\n"));
|
||||
return (mdn_invalid_encoding);
|
||||
} else if (v > 0xffff) {
|
||||
/* Convert to surrogate pair */
|
||||
if (v >= 0x110000)
|
||||
return (mdn_invalid_encoding);
|
||||
if (tolen < 2)
|
||||
return (mdn_buffer_overflow);
|
||||
utf16[i++] = SURROGATE_HIGH(v);
|
||||
utf16[i++] = SURROGATE_LOW(v);
|
||||
tolen -= 2;
|
||||
} else {
|
||||
utf16[i++] = v;
|
||||
tolen--;
|
||||
}
|
||||
}
|
||||
*reslenp = i;
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
mdn_result_t
|
||||
mdn_util_utf16toutf8(const unsigned short *utf16, size_t fromlen,
|
||||
char *utf8, size_t tolen, size_t *reslenp)
|
||||
{
|
||||
int i;
|
||||
char *org = utf8;
|
||||
|
||||
for (i = 0; i < fromlen; i++) {
|
||||
unsigned long v;
|
||||
int w;
|
||||
|
||||
if (IS_SURROGATE_HIGH(utf16[i])) {
|
||||
if (i + 1 >= fromlen ||
|
||||
!IS_SURROGATE_LOW(utf16[i + 1])) {
|
||||
WARNING(("mdn_util_utf16toutf8: "
|
||||
"corrupted surrogate pair\n"));
|
||||
return (mdn_invalid_encoding);
|
||||
}
|
||||
v = COMBINE_SURROGATE(utf16[i], utf16[i + 1]);
|
||||
i++;
|
||||
} else {
|
||||
v = utf16[i];
|
||||
}
|
||||
w = mdn_utf8_putwc(utf8, tolen, v);
|
||||
if (w == 0)
|
||||
return (mdn_buffer_overflow);
|
||||
utf8 += w;
|
||||
tolen -= w;
|
||||
}
|
||||
*reslenp = utf8 - org;
|
||||
return (mdn_success);
|
||||
}
|
||||
262
contrib/idn/mdnkit/lib/zldrule.c
Normal file
262
contrib/idn/mdnkit/lib/zldrule.c
Normal file
|
|
@ -0,0 +1,262 @@
|
|||
#ifndef lint
|
||||
static char *rcsid = "$Id: zldrule.c,v 1.10 2000/09/20 02:47:33 ishisone Exp $";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
* Tokyo, Japan.
|
||||
*
|
||||
* 1. Use, Modification and Redistribution (including distribution of any
|
||||
* modified or derived work) in source and/or binary forms is permitted
|
||||
* under this License Terms and Conditions.
|
||||
*
|
||||
* 2. Redistribution of source code must retain the copyright notices as they
|
||||
* appear in each source code file, this License Terms and Conditions.
|
||||
*
|
||||
* 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
* this License Terms and Conditions, in the documentation and/or other
|
||||
* materials provided with the distribution. For the purposes of binary
|
||||
* distribution the "Copyright Notice" refers to the following language:
|
||||
* "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
*
|
||||
* 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
* derived from this Software without specific prior written approval of
|
||||
* JPNIC.
|
||||
*
|
||||
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* 6. Indemnification by Licensee
|
||||
* Any person or entities using and/or redistributing this Software under
|
||||
* this License Terms and Conditions shall defend indemnify and hold
|
||||
* harmless JPNIC from and against any and all judgements damages,
|
||||
* expenses, settlement liabilities, cost and other liabilities of any
|
||||
* kind as a result of use and redistribution of this Software or any
|
||||
* claim, suite, action, litigation or proceeding by any third party
|
||||
* arising out of or relates to this License Terms and Conditions.
|
||||
*
|
||||
* 7. Governing Law, Jurisdiction and Venue
|
||||
* This License Terms and Conditions shall be governed by and and
|
||||
* construed in accordance with the law of Japan. Any person or entities
|
||||
* using and/or redistributing this Software under this License Terms and
|
||||
* Conditions hereby agrees and consent to the personal and exclusive
|
||||
* jurisdiction and venue of Tokyo District Court of Japan.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <mdn/result.h>
|
||||
#include <mdn/assert.h>
|
||||
#include <mdn/logmacro.h>
|
||||
#include <mdn/converter.h>
|
||||
#include <mdn/translator.h>
|
||||
#include <mdn/zldrule.h>
|
||||
#include <mdn/debug.h>
|
||||
|
||||
typedef struct zld_rule {
|
||||
struct zld_rule *next;
|
||||
char *zld;
|
||||
int zld_depth;
|
||||
int nencodings;
|
||||
mdn_converter_t ctx[1]; /* actually, a variable sized array */
|
||||
} zld_rule_t;
|
||||
|
||||
struct mdn_zldrule {
|
||||
zld_rule_t *rules;
|
||||
};
|
||||
|
||||
static int delayedopen = MDN_CONVERTER_RTCHECK; /* XXX */
|
||||
|
||||
static void insert_rule(mdn_zldrule_t ctx, zld_rule_t *rule);
|
||||
static int domain_depth(const char *domain);
|
||||
|
||||
|
||||
mdn_result_t
|
||||
mdn_zldrule_create(mdn_zldrule_t *ctxp) {
|
||||
mdn_zldrule_t ctx;
|
||||
|
||||
assert(ctxp != NULL);
|
||||
|
||||
TRACE(("mdn_zldrule_create()\n"));
|
||||
|
||||
*ctxp = NULL;
|
||||
|
||||
if ((ctx = malloc(sizeof(*ctx))) == NULL) {
|
||||
WARNING(("mdn_zldrule_create: malloc failed\n"));
|
||||
return (mdn_nomemory);
|
||||
}
|
||||
|
||||
ctx->rules = NULL;
|
||||
|
||||
*ctxp = ctx;
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
void
|
||||
mdn_zldrule_destroy(mdn_zldrule_t ctx) {
|
||||
zld_rule_t *rule;
|
||||
|
||||
assert(ctx != NULL);
|
||||
|
||||
TRACE(("mdn_zldrule_destroy()\n"));
|
||||
|
||||
rule = ctx->rules;
|
||||
while (rule != NULL) {
|
||||
zld_rule_t *next = rule->next;
|
||||
int i;
|
||||
|
||||
free(rule->zld);
|
||||
for (i = 0; i < rule->nencodings; i++)
|
||||
mdn_converter_destroy(rule->ctx[i]);
|
||||
free(rule);
|
||||
rule = next;
|
||||
}
|
||||
|
||||
free(ctx);
|
||||
}
|
||||
|
||||
mdn_result_t
|
||||
mdn_zldrule_add(mdn_zldrule_t ctx, const char *zld,
|
||||
const char **encodings, int nencodings)
|
||||
{
|
||||
mdn_result_t r;
|
||||
zld_rule_t *rule;
|
||||
size_t sz;
|
||||
int i;
|
||||
|
||||
assert(ctx != NULL && zld != NULL && encodings != NULL &&
|
||||
nencodings > 0);
|
||||
|
||||
TRACE(("mdn_zldrule_add(zld=%s)\n", zld));
|
||||
|
||||
sz = sizeof(*rule) + sizeof(mdn_converter_t) * nencodings;
|
||||
if ((rule = malloc(sz)) == NULL) {
|
||||
WARNING(("mdn_zldrule_add: malloc failed\n"));
|
||||
return (mdn_nomemory);
|
||||
}
|
||||
rule->next = NULL;
|
||||
rule->zld = NULL;
|
||||
rule->zld_depth = 0;
|
||||
rule->nencodings = 0;
|
||||
|
||||
r = mdn_translator_canonicalzld(zld, &rule->zld);
|
||||
if (r != mdn_success)
|
||||
goto error;
|
||||
|
||||
rule->zld_depth = domain_depth(rule->zld);
|
||||
|
||||
for (i = 0; i < nencodings; i++) {
|
||||
r = mdn_converter_create(encodings[i], &rule->ctx[i],
|
||||
delayedopen);
|
||||
if (r != mdn_success)
|
||||
goto error;
|
||||
}
|
||||
|
||||
insert_rule(ctx, rule);
|
||||
|
||||
return (mdn_success);
|
||||
|
||||
error:
|
||||
free(rule);
|
||||
return (r);
|
||||
}
|
||||
|
||||
mdn_result_t
|
||||
mdn_zldrule_select(mdn_zldrule_t ctx, const char *domain,
|
||||
char **zldp, mdn_converter_t *convctxp)
|
||||
{
|
||||
char dummy[1024];
|
||||
zld_rule_t *rule;
|
||||
int i;
|
||||
mdn_result_t r;
|
||||
|
||||
assert(ctx != NULL && domain != NULL &&
|
||||
zldp != NULL && convctxp != NULL);
|
||||
|
||||
TRACE(("mdn_zldrule_select(domain=\"%s\")\n",
|
||||
mdn_debug_xstring(domain, 30)));
|
||||
|
||||
for (rule = ctx->rules; rule != NULL; rule = rule->next) {
|
||||
if (mdn_translator_matchzld(domain, rule->zld))
|
||||
goto found;
|
||||
}
|
||||
return (mdn_notfound);
|
||||
|
||||
found:
|
||||
*zldp = rule->zld;
|
||||
if (rule->nencodings > 1) {
|
||||
for (i = 0; i < rule->nencodings; i++) {
|
||||
mdn_converter_t convctx = rule->ctx[i];
|
||||
r = mdn_converter_convert(convctx, mdn_converter_l2u,
|
||||
domain, dummy,
|
||||
sizeof(dummy));
|
||||
if (r != mdn_success)
|
||||
continue;
|
||||
*convctxp = rule->ctx[i];
|
||||
return (mdn_success);
|
||||
}
|
||||
return (mdn_invalid_encoding);
|
||||
} else {
|
||||
*convctxp = rule->ctx[0];
|
||||
}
|
||||
|
||||
return (mdn_success);
|
||||
}
|
||||
|
||||
static void
|
||||
insert_rule(mdn_zldrule_t ctx, zld_rule_t *rule) {
|
||||
zld_rule_t *prev, *cur;
|
||||
|
||||
for (prev = NULL, cur = ctx->rules;
|
||||
cur != NULL;
|
||||
prev = cur, cur = cur->next) {
|
||||
if (cur->zld_depth <= rule->zld_depth) {
|
||||
rule->next = cur;
|
||||
if (prev == NULL)
|
||||
ctx->rules = rule;
|
||||
else
|
||||
prev->next = rule;
|
||||
return;
|
||||
}
|
||||
}
|
||||
rule ->next = NULL;
|
||||
if (prev == NULL)
|
||||
ctx->rules = rule;
|
||||
else
|
||||
prev->next = rule;
|
||||
}
|
||||
|
||||
static int
|
||||
domain_depth(const char *s) {
|
||||
int n = 0;
|
||||
|
||||
if (s == NULL)
|
||||
return (0);
|
||||
|
||||
while ((s = strchr(s, '.')) != NULL) {
|
||||
n++;
|
||||
s++;
|
||||
}
|
||||
return (n);
|
||||
}
|
||||
4284
contrib/idn/mdnkit/libtool
Executable file
4284
contrib/idn/mdnkit/libtool
Executable file
File diff suppressed because it is too large
Load diff
3114
contrib/idn/mdnkit/ltconfig
Normal file
3114
contrib/idn/mdnkit/ltconfig
Normal file
File diff suppressed because it is too large
Load diff
4024
contrib/idn/mdnkit/ltmain.sh
Normal file
4024
contrib/idn/mdnkit/ltmain.sh
Normal file
File diff suppressed because it is too large
Load diff
90
contrib/idn/mdnkit/man/Makefile.in
Normal file
90
contrib/idn/mdnkit/man/Makefile.in
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
# $Id: Makefile.in,v 1.1 2000/09/08 03:17:31 ishisone 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
# Tokyo, Japan.
|
||||
#
|
||||
# 1. Use, Modification and Redistribution (including distribution of any
|
||||
# modified or derived work) in source and/or binary forms is permitted
|
||||
# under this License Terms and Conditions.
|
||||
#
|
||||
# 2. Redistribution of source code must retain the copyright notices as they
|
||||
# appear in each source code file, this License Terms and Conditions.
|
||||
#
|
||||
# 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
# this License Terms and Conditions, in the documentation and/or other
|
||||
# materials provided with the distribution. For the purposes of binary
|
||||
# distribution the "Copyright Notice" refers to the following language:
|
||||
# "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
#
|
||||
# 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
# derived from this Software without specific prior written approval of
|
||||
# JPNIC.
|
||||
#
|
||||
# 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
#
|
||||
# 6. Indemnification by Licensee
|
||||
# Any person or entities using and/or redistributing this Software under
|
||||
# this License Terms and Conditions shall defend indemnify and hold
|
||||
# harmless JPNIC from and against any and all judgements damages,
|
||||
# expenses, settlement liabilities, cost and other liabilities of any
|
||||
# kind as a result of use and redistribution of this Software or any
|
||||
# claim, suite, action, litigation or proceeding by any third party
|
||||
# arising out of or relates to this License Terms and Conditions.
|
||||
#
|
||||
# 7. Governing Law, Jurisdiction and Venue
|
||||
# This License Terms and Conditions shall be governed by and and
|
||||
# construed in accordance with the law of Japan. Any person or entities
|
||||
# using and/or redistributing this Software under this License Terms and
|
||||
# Conditions hereby agrees and consent to the personal and exclusive
|
||||
# jurisdiction and venue of Tokyo District Court of Japan.
|
||||
|
||||
top_builddir = ..
|
||||
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
prefix = @prefix@
|
||||
exec_prefix = @exec_prefix@
|
||||
|
||||
ETCDIR = @sysconfdir@
|
||||
MANDIR = @mandir@
|
||||
|
||||
INSTALL = @INSTALL@
|
||||
INSTALL_PROGRAM = @INSTALL_PROGRAM@
|
||||
INSTALL_DATA = @INSTALL_DATA@
|
||||
|
||||
GEN_FILES = mdnres.conf.5
|
||||
MAN5 = mdnres.conf.5
|
||||
|
||||
all: $(GEN_FILES)
|
||||
|
||||
install: install-man
|
||||
|
||||
install-man:
|
||||
[ -d $(MANDIR) ] || mkdir $(MANDIR)
|
||||
[ -d $(MANDIR)/man5 ] || mkdir $(MANDIR)/man5
|
||||
$(INSTALL_DATA) $(MAN5) $(MANDIR)/man5
|
||||
|
||||
mdnres.conf.5: mdnres.conf.5.in
|
||||
sed 's%@ETCDIR@%$(ETCDIR)%' < $(srcdir)/mdnres.conf.5.in > $@
|
||||
|
||||
clean:
|
||||
rm -f *~ $(GEN_FILES)
|
||||
296
contrib/idn/mdnkit/man/mdnres.conf.5.in
Normal file
296
contrib/idn/mdnkit/man/mdnres.conf.5.in
Normal file
|
|
@ -0,0 +1,296 @@
|
|||
.\" $Id: mdnres.conf.5.in,v 1.6 2000/11/17 07:18:57 ishisone 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
.\" Tokyo, Japan.
|
||||
.\"
|
||||
.\" 1. Use, Modification and Redistribution (including distribution of any
|
||||
.\" modified or derived work) in source and/or binary forms is permitted
|
||||
.\" under this License Terms and Conditions.
|
||||
.\"
|
||||
.\" 2. Redistribution of source code must retain the copyright notices as they
|
||||
.\" appear in each source code file, this License Terms and Conditions.
|
||||
.\"
|
||||
.\" 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
.\" this License Terms and Conditions, in the documentation and/or other
|
||||
.\" materials provided with the distribution. For the purposes of binary
|
||||
.\" distribution the "Copyright Notice" refers to the following language:
|
||||
.\" "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
.\"
|
||||
.\" 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
.\" derived from this Software without specific prior written approval of
|
||||
.\" JPNIC.
|
||||
.\"
|
||||
.\" 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
.\" "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
.\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
.\" PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
.\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
.\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
.\"
|
||||
.\" 6. Indemnification by Licensee
|
||||
.\" Any person or entities using and/or redistributing this Software under
|
||||
.\" this License Terms and Conditions shall defend indemnify and hold
|
||||
.\" harmless JPNIC from and against any and all judgements damages,
|
||||
.\" expenses, settlement liabilities, cost and other liabilities of any
|
||||
.\" kind as a result of use and redistribution of this Software or any
|
||||
.\" claim, suite, action, litigation or proceeding by any third party
|
||||
.\" arising out of or relates to this License Terms and Conditions.
|
||||
.\"
|
||||
.\" 7. Governing Law, Jurisdiction and Venue
|
||||
.\" This License Terms and Conditions shall be governed by and and
|
||||
.\" construed in accordance with the law of Japan. Any person or entities
|
||||
.\" using and/or redistributing this Software under this License Terms and
|
||||
.\" Conditions hereby agrees and consent to the personal and exclusive
|
||||
.\" jurisdiction and venue of Tokyo District Court of Japan.
|
||||
.\"
|
||||
.TH mdnres.conf 5 "Sep 7, 2000"
|
||||
.\"
|
||||
.SH NAME
|
||||
mdnres.conf \- configuration file for the mDNkit client-side library
|
||||
.\"
|
||||
.SH SYNOPSIS
|
||||
@ETCDIR@/mdnres.conf
|
||||
.\"
|
||||
.SH DESCRIPTION
|
||||
.B mdnres.conf
|
||||
is read by the client-side resolver which is multilingualized
|
||||
(internationalized) using mDNkit.
|
||||
This file specifies various properties regarding multilingual domain names
|
||||
such as:
|
||||
.RS 4
|
||||
\- the encoding of domain names in DNS protocol.
|
||||
.br
|
||||
\- normalization schemes.
|
||||
.br
|
||||
\- the alternative encoding which is used in case the domain name in
|
||||
the DNS reply message cannot be convertible to the local encoding.
|
||||
.br
|
||||
\- encoding name aliases.
|
||||
.RE
|
||||
.PP
|
||||
This file is a simple text file, and each line in the file
|
||||
(other than comment lines that begin with # and empty lines) forms an entry
|
||||
of the following format:
|
||||
.PP
|
||||
.RS 8
|
||||
.nf
|
||||
\fIkeyword\fP\ \fIvalue..\fP
|
||||
.fi
|
||||
.RE
|
||||
\."
|
||||
.SH "SERVER ENCODING ENTRY"
|
||||
Server encoding entry specifies the encoding name (codeset name) which
|
||||
is used as the encoding of multilingualized domain names by the DNS protocol.
|
||||
.PP
|
||||
The syntax of this entry is:
|
||||
.PP
|
||||
.RS 8
|
||||
.nf
|
||||
\f(CWserver-encoding \fP\fIencoding\fP
|
||||
.fi
|
||||
.RE
|
||||
.PP
|
||||
\fIencoding\fP is the encoding name to be used, and any of the following
|
||||
names can be specified.
|
||||
.RS 4
|
||||
.IP "\(bu" 2
|
||||
``UTF-8''
|
||||
.IP "\(bu" 2
|
||||
``RACE''
|
||||
.IP "\(bu" 2
|
||||
``BRACE''
|
||||
.IP "\(bu" 2
|
||||
``LACE''
|
||||
.IP "\(bu" 2
|
||||
``UTF-5''
|
||||
.IP "\(bu" 2
|
||||
Codeset names which iconv_open() library function accepts. Please
|
||||
consult iconv() documentation for the available codesets.
|
||||
.IP "\(bu" 2
|
||||
Any alias names for the above, defined by the alias file.
|
||||
(See section ``ENCODING ALIAS ENTRY'')
|
||||
.RE
|
||||
.SH "SERVER ZLD ENTRY"
|
||||
Some of the encodings used by internationalized name servers (the one
|
||||
specified by `server-encoding' entry) requires ZLD (zero-level domain),
|
||||
additional toplevel domain that is hidden from users/applications.
|
||||
This entry specifies the ZLD.
|
||||
.PP
|
||||
The syntax of this entry is:
|
||||
.PP
|
||||
.RS 8
|
||||
.nf
|
||||
\f(CWserver-zld \fP\fIZLD\fP
|
||||
.fi
|
||||
.RE
|
||||
.PP
|
||||
Note that this entry is ignored unless mDNkit is configured with
|
||||
\f(CW--enable-zld\fR so that its ZLD support is enabled.
|
||||
.SH "NORMALIZATION ENTRY"
|
||||
Normalization entry specifies the normalization schemes which should be
|
||||
applied to the domain names before sending them to name servers.
|
||||
.\"
|
||||
The syntax of this entry is:
|
||||
.PP
|
||||
.RS 8
|
||||
.nf
|
||||
\f(CWnormalize \fP\fIscheme\fP [\fIscheme\fP..]
|
||||
.fi
|
||||
.RE
|
||||
.PP
|
||||
.I scheme
|
||||
is the normalization scheme, and following shows the currently available
|
||||
schemes:
|
||||
.RS 4
|
||||
.TP 4
|
||||
\f(CWascii-lowercase\fP
|
||||
Convert ASCII uppercase letters to lowercase.
|
||||
.TP 4
|
||||
\f(CWascii-uppercase\fP
|
||||
Convert ASCII lowercase letters to uppercase.
|
||||
.TP 4
|
||||
\f(CWunicode-lowercase\fP
|
||||
Convert Unicode uppercase letters to lowercase, based on ``Unicode
|
||||
Technical Report #21: Case Mappings''.
|
||||
Note that only locale-independent conversion is supported.
|
||||
.TP 4
|
||||
\f(CWunicode-uppercase\fP
|
||||
Convert Unicode lowercase letters to uppercase, based on ``Unicode
|
||||
Technical Report #21: Case Mappings''.
|
||||
Note that only locale-independent conversion is supported.
|
||||
.TP 4
|
||||
\f(CWunicode-form-c\fP
|
||||
Perform Unicode normalization called ``Unicode Normalization Form C''.
|
||||
.TP 4
|
||||
\f(CWunicode-form-kc\fP
|
||||
Perform Unicode normalization called ``Unicode Normalization Form KC''.
|
||||
.TP 4
|
||||
\f(CWja-compose-voiced-sound\fP
|
||||
Compose Japanese full-width hiragana/katakana character and the following
|
||||
(semi) voiced sound mark (dakuten or han-dakuten in Japanese) into a
|
||||
single combined letter if such letter exists.
|
||||
.TP 4
|
||||
\f(CWja-kana-fullwidth\fP
|
||||
Convert Japanese half-width kana characters to full-width.
|
||||
.TP 4
|
||||
\f(CWja-alnum-halfwidth\fP
|
||||
Convert full-width alphabets, digits and minus sign to half-width.
|
||||
.TP 4
|
||||
\f(CWja-minus-hack\fP
|
||||
Convert Japanese full-width minus sign
|
||||
(Unicode ``MINUS SIGN'') to ``\-'' (Unicode ``HYPHEN-MINUS'').
|
||||
.RE
|
||||
.PP
|
||||
More than one
|
||||
.I schemes
|
||||
can be specified.
|
||||
If multiple schemes are specified, they are applied in turn.
|
||||
.SH "ALTERNATIVE ENCODING ENTRY"
|
||||
The resolver library multilingualized by mDNkit automatically
|
||||
determines the local codeset the application uses, and tries to
|
||||
convert domain names in a DNS reply message to the codeset.
|
||||
However, it is possible that the conversion fails because some
|
||||
characters in the domain names have no mapping to the local codeset.
|
||||
This occurs, for example, when a Japanese application using Japanese
|
||||
codeset receives a DNS reply containing Chinese characters which
|
||||
are not included in the Japanese character set.
|
||||
.PP
|
||||
Alternative encoding entry specifies the codeset name to be used
|
||||
instead of the local codeset in case the above problem happens.
|
||||
.PP
|
||||
The syntax of this entry is:
|
||||
.PP
|
||||
.RS 8
|
||||
.nf
|
||||
\f(CWalternate-encoding \fP\fIencoding\fP
|
||||
.fi
|
||||
.RE
|
||||
.PP
|
||||
.I encoding
|
||||
is the name of the codeset. It must be an ASCII-compatible
|
||||
encoding such as RACE.
|
||||
.\"
|
||||
.SH "ENCODING ALIAS ENTRY"
|
||||
Encoding alias entry specifies the file containing codeset name aliases.
|
||||
The aliases can be used just as the real names.
|
||||
.PP
|
||||
The syntax of this entry is:
|
||||
.PP
|
||||
.RS 8
|
||||
.nf
|
||||
\f(CWalias-file \fP\fIpathname\fP
|
||||
.fi
|
||||
.RE
|
||||
.PP
|
||||
.I pathname
|
||||
specifies the path name of the alias file.
|
||||
The alias file is a simple text file, consisting of lines of the form:
|
||||
.PP
|
||||
.RS 8
|
||||
.nf
|
||||
\fIalias-name\fP\ \fIname\fP
|
||||
.fi
|
||||
.RE
|
||||
.PP
|
||||
.I alias-name
|
||||
is the alias name to be defined, and
|
||||
.I name
|
||||
is the real name or another alias name.
|
||||
.\"
|
||||
.SH "LOCAL CODESET"
|
||||
.B mdnres.conf
|
||||
does not have an entry to specify the local codeset, since
|
||||
it is determined from the application's current locale information.
|
||||
So each application can use different local codeset.
|
||||
.PP
|
||||
Although mDNkit tries hard to find out the local codeset, sometimes it
|
||||
fails. For example, there are applications which use non-ASCII codeset
|
||||
but work in C locale. In this case, you can specify the application's
|
||||
local codeset by an environment variable ``MDN_LOCAL_CODESET''.
|
||||
Just set the codeset name (or its alias name) to the variable, and
|
||||
mDNkit will use the codeset as the local one, regardless of the locale
|
||||
setting.
|
||||
.SH "SAMPLE CONFIGURATION"
|
||||
The following shows a sample configuration file.
|
||||
.RS 4
|
||||
.ft CW
|
||||
.nf
|
||||
|
||||
#
|
||||
# a sample configuration.
|
||||
#
|
||||
|
||||
# Use RACE as the DNS protocol encoding.
|
||||
server-encoding RACE
|
||||
|
||||
# Use lowercase conversion and Normalization Form KC for normalization.
|
||||
normalize unicode-lowercase unicode-form-kc
|
||||
|
||||
# Use RACE as the alternative encoding.
|
||||
alternate-encoding RACE
|
||||
|
||||
.fi
|
||||
.ft R
|
||||
.RE
|
||||
.\"
|
||||
.SH FILES
|
||||
.I @ETCDIR@/mdnres.conf
|
||||
.br
|
||||
.I @ETCDIR@/mdnres.conf.sample
|
||||
\- sample configuration with comments
|
||||
.\"
|
||||
.SH "SEE ALSO"
|
||||
iconv(3)
|
||||
2173
contrib/idn/mdnkit/patch/bind9/patch.most
Normal file
2173
contrib/idn/mdnkit/patch/bind9/patch.most
Normal file
File diff suppressed because it is too large
Load diff
73
contrib/idn/mdnkit/tools/Makefile.in
Normal file
73
contrib/idn/mdnkit/tools/Makefile.in
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
# $Id: Makefile.in,v 1.6 2000/07/19 05:00:16 ishisone 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
# Tokyo, Japan.
|
||||
#
|
||||
# 1. Use, Modification and Redistribution (including distribution of any
|
||||
# modified or derived work) in source and/or binary forms is permitted
|
||||
# under this License Terms and Conditions.
|
||||
#
|
||||
# 2. Redistribution of source code must retain the copyright notices as they
|
||||
# appear in each source code file, this License Terms and Conditions.
|
||||
#
|
||||
# 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
# this License Terms and Conditions, in the documentation and/or other
|
||||
# materials provided with the distribution. For the purposes of binary
|
||||
# distribution the "Copyright Notice" refers to the following language:
|
||||
# "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
#
|
||||
# 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
# derived from this Software without specific prior written approval of
|
||||
# JPNIC.
|
||||
#
|
||||
# 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
#
|
||||
# 6. Indemnification by Licensee
|
||||
# Any person or entities using and/or redistributing this Software under
|
||||
# this License Terms and Conditions shall defend indemnify and hold
|
||||
# harmless JPNIC from and against any and all judgements damages,
|
||||
# expenses, settlement liabilities, cost and other liabilities of any
|
||||
# kind as a result of use and redistribution of this Software or any
|
||||
# claim, suite, action, litigation or proceeding by any third party
|
||||
# arising out of or relates to this License Terms and Conditions.
|
||||
#
|
||||
# 7. Governing Law, Jurisdiction and Venue
|
||||
# This License Terms and Conditions shall be governed by and and
|
||||
# construed in accordance with the law of Japan. Any person or entities
|
||||
# using and/or redistributing this Software under this License Terms and
|
||||
# Conditions hereby agrees and consent to the personal and exclusive
|
||||
# jurisdiction and venue of Tokyo District Court of Japan.
|
||||
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
prefix = @prefix@
|
||||
exec_prefix = @exec_prefix@
|
||||
|
||||
SUBDIRS = mdnconv runmdn
|
||||
|
||||
all:
|
||||
for d in $(SUBDIRS); do (cd $$d; $(MAKE) all); done
|
||||
|
||||
install:
|
||||
for d in $(SUBDIRS); do (cd $$d; $(MAKE) install); done
|
||||
|
||||
clean:
|
||||
for d in $(SUBDIRS); do (cd $$d; $(MAKE) clean); done
|
||||
109
contrib/idn/mdnkit/tools/mdnconv/Makefile.in
Normal file
109
contrib/idn/mdnkit/tools/mdnconv/Makefile.in
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
# $Id: Makefile.in,v 1.11 2000/11/17 06:53:23 ishisone 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, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
|
||||
# Tokyo, Japan.
|
||||
#
|
||||
# 1. Use, Modification and Redistribution (including distribution of any
|
||||
# modified or derived work) in source and/or binary forms is permitted
|
||||
# under this License Terms and Conditions.
|
||||
#
|
||||
# 2. Redistribution of source code must retain the copyright notices as they
|
||||
# appear in each source code file, this License Terms and Conditions.
|
||||
#
|
||||
# 3. Redistribution in binary form must reproduce the Copyright Notice,
|
||||
# this License Terms and Conditions, in the documentation and/or other
|
||||
# materials provided with the distribution. For the purposes of binary
|
||||
# distribution the "Copyright Notice" refers to the following language:
|
||||
# "Copyright (c) Japan Network Information Center. All rights reserved."
|
||||
#
|
||||
# 4. Neither the name of JPNIC may be used to endorse or promote products
|
||||
# derived from this Software without specific prior written approval of
|
||||
# JPNIC.
|
||||
#
|
||||
# 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
|
||||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
#
|
||||
# 6. Indemnification by Licensee
|
||||
# Any person or entities using and/or redistributing this Software under
|
||||
# this License Terms and Conditions shall defend indemnify and hold
|
||||
# harmless JPNIC from and against any and all judgements damages,
|
||||
# expenses, settlement liabilities, cost and other liabilities of any
|
||||
# kind as a result of use and redistribution of this Software or any
|
||||
# claim, suite, action, litigation or proceeding by any third party
|
||||
# arising out of or relates to this License Terms and Conditions.
|
||||
#
|
||||
# 7. Governing Law, Jurisdiction and Venue
|
||||
# This License Terms and Conditions shall be governed by and and
|
||||
# construed in accordance with the law of Japan. Any person or entities
|
||||
# using and/or redistributing this Software under this License Terms and
|
||||
# Conditions hereby agrees and consent to the personal and exclusive
|
||||
# jurisdiction and venue of Tokyo District Court of Japan.
|
||||
|
||||
top_builddir = ../..
|
||||
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
prefix = @prefix@
|
||||
exec_prefix = @exec_prefix@
|
||||
|
||||
BINDIR = @bindir@
|
||||
LIBDIR = @libdir@
|
||||
MANDIR = @mandir@
|
||||
|
||||
CC = @CC@
|
||||
RANLIB = @RANLIB@
|
||||
INSTALL = @INSTALL@
|
||||
INSTALL_PROGRAM = @INSTALL_PROGRAM@
|
||||
INSTALL_DATA = @INSTALL_DATA@
|
||||
SHELL = @SHELL@
|
||||
LIBTOOL = @LIBTOOL@
|
||||
|
||||
OPTS =
|
||||
INCS = -I$(srcdir)/../../include -I../../include
|
||||
DEFS =
|
||||
|
||||
CFLAGS = $(OPTS) $(INCS) $(DEFS) @CFLAGS@
|
||||
|
||||
SRCS = mdnconv.c util.c
|
||||
OBJS = mdnconv.o util.o
|
||||
|
||||
ICONVLIB = @ICONVLIB@
|
||||
MDNLIB = ../../lib/libmdn.la
|
||||
|
||||
LIBS = $(MDNLIB) $(ICONVLIB)
|
||||
|
||||
all: mdnconv
|
||||
|
||||
mdnconv: $(OBJS) $(MDNLIB)
|
||||
$(LIBTOOL) --mode=link $(CC) -o $@ $(OBJS) $(LIBS)
|
||||
|
||||
install: install-prog install-man
|
||||
|
||||
install-prog: mdnconv
|
||||
[ -d $(BINDIR) ] || mkdir $(BINDIR)
|
||||
$(LIBTOOL) --mode=install $(INSTALL_PROGRAM) mdnconv $(BINDIR)
|
||||
|
||||
install-man:
|
||||
[ -d $(MANDIR) ] || mkdir $(MANDIR)
|
||||
[ -d $(MANDIR)/man1 ] || mkdir $(MANDIR)/man1
|
||||
$(INSTALL_DATA) $(srcdir)/mdnconv.1 $(MANDIR)/man1
|
||||
|
||||
clean:
|
||||
rm -f *.o mdnconv *.core core *~
|
||||
117
contrib/idn/mdnkit/tools/mdnconv/README.ja
Normal file
117
contrib/idn/mdnkit/tools/mdnconv/README.ja
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
|
||||
mdnconv -- named.conf/ゾーンファイル用コードセットコンバータ
|
||||
|
||||
* 使用法
|
||||
mdnconv [オプション..] [ファイル]
|
||||
|
||||
* 概要
|
||||
|
||||
mdnconv はコマンド行引数で指定されたオプションにしたがってテキストのコー
|
||||
ドセットを変換し、標準出力に書き出します。引数としてファイル名が指定さ
|
||||
れればその内容を変換し、指定されなければ標準入力の内容を変換します。
|
||||
|
||||
* オプション
|
||||
|
||||
mdnconv は次のようなオプションを受け付けます。
|
||||
|
||||
-in 入力コード
|
||||
入力コードセットの指定です。指定できる値は、
|
||||
iconv() が受け付けるコードセット名、"UTF-5"、
|
||||
および後述する -alias オプションで定義したそれらの別名です。
|
||||
現在のバージョンではこのオプションの指定は必須です。
|
||||
|
||||
-out 出力コード
|
||||
出力コードセットの指定です。指定できる値は、
|
||||
iconv() が受け付けるコードセット名、"UTF-5"、
|
||||
および後述する -alias オプションで定義したそれらの別名です。
|
||||
デフォルトは UTF-8 です。
|
||||
|
||||
-normalize 正規化
|
||||
実行する正規化の種類を指定します。このオプションは複数
|
||||
指定することができ、その場合には指定された順序で
|
||||
正規化が行われます。現在、使用できる正規化の名称は
|
||||
以下の通りです。
|
||||
|
||||
ascii-lowercase
|
||||
ASCII の大文字を小文字に変換します。
|
||||
ascii-uppercase
|
||||
ASCII の小文字を大文字に変換します。
|
||||
unicode-lowercase
|
||||
UnicodeData.txt に定義されている Lowercase Mapping
|
||||
にしたがって大文字を小文字に変換します。
|
||||
unicode-uppercase
|
||||
UnicodeData.txt に定義されている Uppercase Mapping
|
||||
にしたがって小文字を大文字に変換します。
|
||||
unicode-form-c
|
||||
Unicode Normalization Form C にしたがって
|
||||
正規化を行います。
|
||||
unicode-form-kc
|
||||
Unicode Normalization Form KC にしたがって
|
||||
正規化を行います。
|
||||
ja-delimiter-hack
|
||||
全角の句点『。』およびピリオド『.』を
|
||||
半角のピリオド『.』に変換します。
|
||||
ja-fullwidth
|
||||
半角カタカナを全角カタカナに変換します。
|
||||
|
||||
-zld ZLD
|
||||
ZLD を指定します。UTF-5 への変換の際、ドメイン名の
|
||||
最後が指定された ZLD に一致する場合、ZLD 部分は
|
||||
UTF-5 に変換されません。
|
||||
あるいは次の -auto と組み合わせた場合には、
|
||||
ドメイン名の最後がピリオドであり、かつ非ASCII
|
||||
文字を含んでいた場合、指定したZLD が自動的に付加されます。
|
||||
|
||||
-auto
|
||||
ドメイン名の最後がピリオドであり、かつ非ASCII
|
||||
文字を含んでいる場合に、-zld オプションで指定したZLD を
|
||||
自動的に付加します。
|
||||
|
||||
-whole
|
||||
正規化および出力コードセットへの変換を入力テキスト
|
||||
全体にわたって行います。デフォルトでは、入力テキストの
|
||||
非ASCII文字およびその周辺のみを対象とします。
|
||||
|
||||
-alias 別名ファイル
|
||||
コードセット名の別名を定義したファイルを指定します。
|
||||
|
||||
-flush
|
||||
行単位で出力をフラッシュします。
|
||||
|
||||
|
||||
* 変換の仕組み
|
||||
|
||||
mdnconv は、入力されたデータをまず UTF-8 へと変換します。UTF-8 の状態
|
||||
で正規化を実行し、最後に UTF-8 から出力コードセットへと変換して出力し
|
||||
ます。入力されたデータのUTF-8への変換、はすべてのデータに対して行われ
|
||||
ますが、正規化および UTF-8 から出力コードセットへの変換は、非ASCII文字
|
||||
とその周辺に対してのみ行われます。具体的には、
|
||||
|
||||
非ASCII文字、およびその前後のドメイン名を構成するASCII文字
|
||||
とピリオド ([-0-9A-Za-z.]) の部分
|
||||
|
||||
が変換対象になります。mdnconv は入力データを構文解析するような処理はし
|
||||
ていませんので、実際にはドメイン名ではなくても、上記の条件に一致する個
|
||||
所はすべて変換対象になります。
|
||||
|
||||
-whole オプションを指定して mdnconv を起動することにより、すべてのデータに
|
||||
対して正規化と出力コードセットへの変換を行うことが可能です。
|
||||
|
||||
|
||||
* named.conf/ゾーンファイルの管理方法
|
||||
|
||||
named.conf やゾーンファイルはローカルエンコーディングで書かれたものを
|
||||
マスターとし、これを mdnconv で UTF-8 や UTF-5 に変換して named に食わ
|
||||
せるのがよいでしょう。例えばローカルエンコーディングのファイルにサフィッ
|
||||
クス .lc を、UTF-5/UTF-8 のファイルにそれぞれサフィックス.utf5 .utf8
|
||||
をつけることにすれば、つぎのような Makefile のルールを指定することで変
|
||||
換ができます。
|
||||
|
||||
.SUFFIXES: .lc .utf5 .utf8
|
||||
.lc.utf5:
|
||||
mdnconv -in $(LOCALCODE) -out UTF-5 $< > $@
|
||||
.lc.utf8:
|
||||
mdnconv -in $(LOCALCODE) -out UTF-8 $< > $@
|
||||
|
||||
|
||||
; $Id: README.ja,v 1.2 2000/06/12 04:23:57 ishisone Exp $
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue