libidn.html   [plain text]


<html lang="en">
<head>
<title>GNU Libidn</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="GNU Libidn">
<meta name="generator" content="makeinfo 4.8">
<link title="Top" rel="top" href="#Top">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<!--
This manual is last updated 31 May 2007 for version
0.6.14 of GNU Libidn.

Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 Simon Josefsson.

     Permission is granted to copy, distribute and/or modify this
     document under the terms of the GNU Free Documentation License,
     Version 1.2 or any later version published by the Free Software
     Foundation; with the Invariant Sections being "Commercial
     Support", no Front-Cover Texts, and no Back-Cover Texts.  A copy
     of the license is included in the section entitled "GNU Free
     Documentation License".
   -->
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
  pre.display { font-family:inherit }
  pre.format  { font-family:inherit }
  pre.smalldisplay { font-family:inherit; font-size:smaller }
  pre.smallformat  { font-family:inherit; font-size:smaller }
  pre.smallexample { font-size:smaller }
  pre.smalllisp    { font-size:smaller }
  span.sc    { font-variant:small-caps }
  span.roman { font-family:serif; font-weight:normal; } 
  span.sansserif { font-family:sans-serif; font-weight:normal; } 
body { 
	margin: 2%;
	padding: 0 5%;
	background: #f2f2f9;
}
h1,h2,h3,h4,h5 {
    padding: 0.5em 0 0 5%;
    font-family: Tahoma, Verdana, sans-serif;
    font-weight: bold;
}
h1 {
    padding: 0.5em 0 0.5em 5%;
    color: white;
    background: #3366cc;
    border-bottom: solid 1px black;
}
h2 { text-decoration: underline; }
h4 { font-style: italic; }
pre {
  margin: 0 5%;
  padding: 0.5em;
}
pre.example {
  border: solid 1px #aaaaff;
  background: #eeeeff;
  padding-bottom: 1em;
}
pre.verbatim {
  border: solid 1px gray;
  background: white;
  padding-bottom: 1em;
}
div.node {
  background: #ffeeee;
  margin: 0 -5% 0 -2%;
  padding: 0.5em 0.5em;
  border: solid 1px #ffaaaa;
  margin-top: 0.5em;
  margin-bottom: 0.5em;
  font-weight: bold;
  color: #770000;
}
.node a {
  color: #770000;
}
.node a:visited {
  color: #550000;
}
dd, li {
  padding-top: 0.1em;
  padding-bottom: 0.1em;
}
--></style>
</head>
<body>
<h1 class="settitle">GNU Libidn</h1>
<div class="contents">
<h2>Table of Contents</h2>
<ul>
<li><a name="toc_Top" href="#Top">GNU Libidn</a>
<li><a name="toc_Introduction" href="#Introduction">1 Introduction</a>
<ul>
<li><a href="#Getting-Started">1.1 Getting Started</a>
<li><a href="#Features">1.2 Features</a>
<li><a href="#Library-Overview">1.3 Library Overview</a>
<li><a href="#Supported-Platforms">1.4 Supported Platforms</a>
<li><a href="#Getting-help">1.5 Getting help</a>
<li><a href="#Commercial-Support">1.6 Commercial Support</a>
<li><a href="#Downloading-and-Installing">1.7 Downloading and Installing</a>
<li><a href="#Bug-Reports">1.8 Bug Reports</a>
<li><a href="#Contributing">1.9 Contributing</a>
</li></ul>
<li><a name="toc_Preparation" href="#Preparation">2 Preparation</a>
<ul>
<li><a href="#Header">2.1 Header</a>
<li><a href="#Initialization">2.2 Initialization</a>
<li><a href="#Version-Check">2.3 Version Check</a>
<li><a href="#Building-the-source">2.4 Building the source</a>
<li><a href="#Autoconf-tests">2.5 Autoconf tests</a>
</li></ul>
<li><a name="toc_Utility-Functions" href="#Utility-Functions">3 Utility Functions</a>
<ul>
<li><a href="#Utility-Functions">3.1 Header file <code>stringprep.h</code></a>
<li><a href="#Utility-Functions">3.2 Unicode Encoding Transformation</a>
<li><a href="#Utility-Functions">3.3 Unicode Normalization</a>
<li><a href="#Utility-Functions">3.4 Character Set Conversion</a>
</li></ul>
<li><a name="toc_Stringprep-Functions" href="#Stringprep-Functions">4 Stringprep Functions</a>
<ul>
<li><a href="#Stringprep-Functions">4.1 Header file <code>stringprep.h</code></a>
<li><a href="#Stringprep-Functions">4.2 Defining A Stringprep Profile</a>
<li><a href="#Stringprep-Functions">4.3 Control Flags</a>
<li><a href="#Stringprep-Functions">4.4 Core Functions</a>
<li><a href="#Stringprep-Functions">4.5 Error Handling</a>
<li><a href="#Stringprep-Functions">4.6 Stringprep Profile Macros</a>
</li></ul>
<li><a name="toc_Punycode-Functions" href="#Punycode-Functions">5 Punycode Functions</a>
<ul>
<li><a href="#Punycode-Functions">5.1 Header file <code>punycode.h</code></a>
<li><a href="#Punycode-Functions">5.2 Unicode Code Point Data Type</a>
<li><a href="#Punycode-Functions">5.3 Core Functions</a>
<li><a href="#Punycode-Functions">5.4 Error Handling</a>
</li></ul>
<li><a name="toc_IDNA-Functions" href="#IDNA-Functions">6 IDNA Functions</a>
<ul>
<li><a href="#IDNA-Functions">6.1 Header file <code>idna.h</code></a>
<li><a href="#IDNA-Functions">6.2 Control Flags</a>
<li><a href="#IDNA-Functions">6.3 Prefix String</a>
<li><a href="#IDNA-Functions">6.4 Core Functions</a>
<li><a href="#IDNA-Functions">6.5 Simplified ToASCII Interface</a>
<li><a href="#IDNA-Functions">6.6 Simplified ToUnicode Interface</a>
<li><a href="#IDNA-Functions">6.7 Error Handling</a>
</li></ul>
<li><a name="toc_TLD-Functions" href="#TLD-Functions">7 TLD Functions</a>
<ul>
<li><a href="#TLD-Functions">7.1 Header file <code>tld.h</code></a>
<li><a href="#TLD-Functions">7.2 Core Functions</a>
<li><a href="#TLD-Functions">7.3 Utility Functions</a>
<li><a href="#TLD-Functions">7.4 High-Level Wrapper Functions</a>
<li><a href="#TLD-Functions">7.5 Error Handling</a>
</li></ul>
<li><a name="toc_PR29-Functions" href="#PR29-Functions">8 PR29 Functions</a>
<ul>
<li><a href="#PR29-Functions">8.1 Header file <code>pr29.h</code></a>
<li><a href="#PR29-Functions">8.2 Core Functions</a>
<li><a href="#PR29-Functions">8.3 Utility Functions</a>
<li><a href="#PR29-Functions">8.4 Error Handling</a>
</li></ul>
<li><a name="toc_Examples" href="#Examples">9 Examples</a>
<ul>
<li><a href="#Example-1">9.1 Example 1</a>
<li><a href="#Example-2">9.2 Example 2</a>
<li><a href="#Example-3">9.3 Example 3</a>
<li><a href="#Example-4">9.4 Example 4</a>
<li><a href="#Example-5">9.5 Example 5</a>
</li></ul>
<li><a name="toc_Invoking-idn" href="#Invoking-idn">10 Invoking idn</a>
<ul>
<li><a href="#Invoking-idn">10.1 Name</a>
<li><a href="#Invoking-idn">10.2 Description</a>
<li><a href="#Invoking-idn">10.3 Options</a>
<li><a href="#Invoking-idn">10.4 Environment Variables</a>
<li><a href="#Invoking-idn">10.5 Examples</a>
<li><a href="#Invoking-idn">10.6 Troubleshooting</a>
</li></ul>
<li><a name="toc_Emacs-API" href="#Emacs-API">11 Emacs API</a>
<ul>
<li><a href="#Emacs-API">11.1 Punycode Emacs API</a>
<li><a href="#Emacs-API">11.2 IDNA Emacs API</a>
</li></ul>
<li><a name="toc_Java-API" href="#Java-API">12 Java API</a>
<ul>
<li><a href="#Java-API">12.1 Overview</a>
<li><a href="#Java-API">12.2 Miscellaneous Programs</a>
<ul>
<li><a href="#Java-API">12.2.1 GenerateRFC3454</a>
<li><a href="#Java-API">12.2.2 GenerateNFKC</a>
<li><a href="#Java-API">12.2.3 TestIDNA</a>
<li><a href="#Java-API">12.2.4 TestNFKC</a>
</li></ul>
<li><a href="#Java-API">12.3 Possible Problems</a>
<li><a href="#Java-API">12.4 A Note on Java and Unicode</a>
</li></ul>
<li><a name="toc_C_0023-API" href="#C_0023-API">13 C# API</a>
<li><a name="toc_Acknowledgements" href="#Acknowledgements">14 Acknowledgements</a>
<li><a name="toc_History" href="#History">15 History</a>
<li><a name="toc_PR29-discussion" href="#PR29-discussion">Appendix A PR29 discussion</a>
<li><a name="toc_Copying-Information" href="#Copying-Information">Appendix B Copying Information</a>
<ul>
<li><a href="#GNU-Free-Documentation-License">B.1 GNU Free Documentation License</a>
<li><a href="#GNU-LGPL">B.2 GNU Lesser General Public License</a>
<li><a href="#GNU-GPL">B.3 GNU General Public License</a>
</li></ul>
<li><a name="toc_Function-and-Variable-Index" href="#Function-and-Variable-Index">Function and Variable Index</a>
<li><a name="toc_Concept-Index" href="#Concept-Index">Concept Index</a>
</li></ul>
</div>



<div class="node">
<p><hr>
<a name="Top"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Introduction">Introduction</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#dir">(dir)</a>

</div>

<h2 class="unnumbered">GNU Libidn</h2>

<p>This manual is last updated 31 May 2007 for version
0.6.14 of GNU Libidn.

   <p>Copyright &copy; 2002, 2003, 2004, 2005, 2006, 2007 Simon Josefsson.

   <blockquote>
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.2 or
any later version published by the Free Software Foundation; with the
Invariant Sections being &ldquo;Commercial Support&rdquo;, no Front-Cover Texts,
and no Back-Cover Texts.  A copy of the license is included in the
section entitled &ldquo;GNU Free Documentation License&rdquo;. 
</blockquote>

<ul class="menu">
<li><a accesskey="1" href="#Introduction">Introduction</a>: 		How to use this manual. 
<li><a accesskey="2" href="#Preparation">Preparation</a>: 			What you should do before using the library. 
<li><a accesskey="3" href="#Utility-Functions">Utility Functions</a>: 		Unicode transformation utility functions. 
<li><a accesskey="4" href="#Stringprep-Functions">Stringprep Functions</a>: 	Stringprep functions. 
<li><a accesskey="5" href="#Punycode-Functions">Punycode Functions</a>: 		Punycode functions. 
<li><a accesskey="6" href="#IDNA-Functions">IDNA Functions</a>: 		IDNA functions. 
<li><a accesskey="7" href="#TLD-Functions">TLD Functions</a>: 		TLD functions. 
<li><a accesskey="8" href="#PR29-Functions">PR29 Functions</a>: 		Detect strings non-idempotent under NFKC. 
<li><a accesskey="9" href="#Examples">Examples</a>:                     Demonstrate how to use the library. 
<li><a href="#Invoking-idn">Invoking idn</a>: 		Command line interface to the library. 
<li><a href="#Emacs-API">Emacs API</a>:                    Emacs Lisp API for Libidn. 
<li><a href="#Java-API">Java API</a>:                     Notes on the Java port of Libidn. 
<li><a href="#C_0023-API">C# API</a>:                       Notes on the C# port of Libidn. 
<li><a href="#Acknowledgements">Acknowledgements</a>:             Whom to blame. 
<li><a href="#History">History</a>:                      Rough outline of development history.

</li></ul>
<p>Appendices

</p>
<ul class="menu">
<li><a href="#PR29-discussion">PR29 discussion</a>:              Implementation aspects of the PR29 flaw. 
<li><a href="#Copying-Information">Copying Information</a>: 		License text covering the Libidn library.

</li></ul>
<p>Indices

</p>
<ul class="menu">
<li><a href="#Function-and-Variable-Index">Function and Variable Index</a>
<li><a href="#Concept-Index">Concept Index</a>

   </ul>

<div class="node">
<p><hr>
<a name="Introduction"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Preparation">Preparation</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Top">Top</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="chapter">1 Introduction</h2>

<p>GNU Libidn is an implementation of the Stringprep, Punycode and IDNA
specifications defined by the IETF Internationalized Domain Names
(IDN) working group, used for internationalized domain names.  The C
library is available under the GNU Lesser General Public License
(see <a href="#GNU-LGPL">GNU LGPL</a>).

   <p>The library contains a generic Stringprep implementation that does
Unicode 3.2 NFKC normalization, mapping and prohibitation of
characters, and bidirectional character handling.  Profiles for
Nameprep, iSCSI, SASL and XMPP are included.  Punycode and ASCII
Compatible Encoding (ACE) via IDNA are supported.  A mechanism to
define Top-Level Domain (TLD) specific validation tables, and to
compare strings against those tables, is included.  Default tables for
some TLDs are also included.

   <p>The Stringprep API consists of two main functions, one for converting
data from the system's native representation into UTF-8, and one
function to perform the Stringprep processing.  Adding a new
Stringprep profile for your application within the API is
straightforward.  The Punycode API consists of one encoding function
and one decoding function.  The IDNA API consists of the ToASCII and
ToUnicode functions, as well as an high-level interface for converting
entire domain names to and from the ACE encoded form.  The TLD API
consists of one set of functions to extract the TLD name from a domain
string, one set of functions to locate the proper TLD table to use
based on the TLD name, and core functions to validate a string against
a TLD table, and some utility wrappers to perform all the steps in one
call.

   <p>The library is used by, e.g., GNU SASL and Shishi to process user
names and passwords.  Libidn can be built into GNU Libc to enable a
new system-wide getaddrinfo flag for IDN processing.

   <p>Libidn is developed for the GNU/Linux system, but runs on over 20 Unix
platforms (including Solaris, IRIX, AIX, and Tru64) and Windows. 
Libidn is written in C and (parts of) the API is accessible from C,
C++, Emacs Lisp, Python and Java.  A native Java and C# port is also
provided, licensed under the GNU Lesser General Public License
(see <a href="#GNU-LGPL">GNU LGPL</a>).

<ul class="menu">
<li><a accesskey="1" href="#Getting-Started">Getting Started</a>
<li><a accesskey="2" href="#Features">Features</a>
<li><a accesskey="3" href="#Library-Overview">Library Overview</a>
<li><a accesskey="4" href="#Supported-Platforms">Supported Platforms</a>
<li><a accesskey="5" href="#Getting-help">Getting help</a>
<li><a accesskey="6" href="#Commercial-Support">Commercial Support</a>
<li><a accesskey="7" href="#Downloading-and-Installing">Downloading and Installing</a>
<li><a accesskey="8" href="#Bug-Reports">Bug Reports</a>
<li><a accesskey="9" href="#Contributing">Contributing</a>
</ul>

<div class="node">
<p><hr>
<a name="Getting-Started"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Features">Features</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Introduction">Introduction</a>

</div>

<h3 class="section">1.1 Getting Started</h3>

<p>This manual documents the library programming interface.  All
functions and data types provided by the library are explained. 
Included are also examples, and documentation for the command line
tool <samp><span class="file">idn</span></samp> that provide a quick interface to the library.  The
Emacs Lisp bindings for the library is also discussed.

   <p>The reader is assumed to possess basic familiarity with
internationalization concepts and network programming in C or C++.

   <p>This manual can be used in several ways.  If read from the beginning
to the end, it gives a good introduction into the library and how it
can be used in an application.  Forward references are included where
necessary.  Later on, the manual can be used as a reference manual to
get just the information needed about any particular interface of the
library.  Experienced programmers might want to start looking at the
examples at the end of the manual (see <a href="#Examples">Examples</a>), and then only
read up those parts of the interface which are unclear.

<div class="node">
<p><hr>
<a name="Features"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Library-Overview">Library Overview</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Getting-Started">Getting Started</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Introduction">Introduction</a>

</div>

<h3 class="section">1.2 Features</h3>

<p>This library might have a couple of advantages over other libraries
doing a similar job.

     <dl>
<dt>It's Free Software<dd>Anybody can use, modify, and redistribute it under the terms of the
GNU Lesser General Public License (see <a href="#GNU-LGPL">GNU LGPL</a>).

     <br><dt>It's thread-safe<dd>No global state is kept in the library.  All functions are reentrant.

     <br><dt>It's portable<dd>The code is intended to be written in pure ANSI C89.  It has been
tested on many Unix like operating systems, and Windows.

     <br><dt>It's modularized<dd>The library is composed of several modules, and the only interaction
between modules is through each modules' public API.  If you only need
one piece of functionality, it is possible to take the files you need
and incorporate them into your own project.

     <br><dt>It's not bloated<dd>The design of the library is based on the smallest API necessary to
implement the basic functionality.  It has been carefully extended
with a small number of high-level wrappers to make it comfortable to
use the library.  However, it does not implement additional
functionality just for the sake of completeness.

     <br><dt>It's documented<dd>Sadly, not all software comes with documentation these days.  This one
does.

   </dl>

<div class="node">
<p><hr>
<a name="Library-Overview"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Supported-Platforms">Supported Platforms</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Features">Features</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Introduction">Introduction</a>

</div>

<h3 class="section">1.3 Library Overview</h3>

<p>The following illustration show the components that make up Libidn,
and how your application relates to the library.  In the illustration,
various components are shown as boxes.  You see the generic StringPrep
component, the various StringPrep profiles including Nameprep, the
Punycode component, the IDNA component, and the TLD component.  The
arrows indicate aggregation, e.g., IDNA uses Punycode and Nameprep,
and in turn Nameprep uses the generic StringPrep interface.  The
interfaces to all components are available for applications, no
component within the library is hidden from the application.

   <div class="block-image"><img src="libidn-components.png" alt="libidn-components.png"></div>

<div class="node">
<p><hr>
<a name="Supported-Platforms"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Getting-help">Getting help</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Library-Overview">Library Overview</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Introduction">Introduction</a>

</div>

<h3 class="section">1.4 Supported Platforms</h3>

<p>Libidn has at some point in time been tested on the following
platforms.

     <ol type=1 start=1>

     <li>Debian GNU/Linux 3.0 (Woody)
<a name="index-Debian-1"></a>
GCC 2.95.4 and GNU Make. This is the main development platform. 
<code>alphaev67-unknown-linux-gnu</code>, <code>alphaev6-unknown-linux-gnu</code>,
<code>arm-unknown-linux-gnu</code>, <code>armv4l-unknown-linux-gnu</code>,
<code>hppa-unknown-linux-gnu</code>, <code>hppa64-unknown-linux-gnu</code>,
<code>i686-pc-linux-gnu</code>, <code>ia64-unknown-linux-gnu</code>,
<code>m68k-unknown-linux-gnu</code>, <code>mips-unknown-linux-gnu</code>,
<code>mipsel-unknown-linux-gnu</code>, <code>powerpc-unknown-linux-gnu</code>,
<code>s390-ibm-linux-gnu</code>, <code>sparc-unknown-linux-gnu</code>,
<code>sparc64-unknown-linux-gnu</code>.

     <li>Debian GNU/Linux 2.1
<a name="index-Debian-2"></a>
GCC 2.95.1 and GNU Make. <code>armv4l-unknown-linux-gnu</code>.

     <li>Tru64 UNIX
<a name="index-Tru64-3"></a>
Tru64 UNIX C compiler and Tru64 Make. <code>alphaev67-dec-osf5.1</code>,
<code>alphaev68-dec-osf5.1</code>.

     <li>SuSE Linux 7.1
<a name="index-SuSE-4"></a>
GCC 2.96 and GNU Make. <code>alphaev6-unknown-linux-gnu</code>,
<code>alphaev67-unknown-linux-gnu</code>.

     <li>SuSE Linux 7.2a
<a name="index-SuSE-Linux-5"></a>
GCC 3.0 and GNU Make. <code>ia64-unknown-linux-gnu</code>.

     <li>SuSE Linux
<a name="index-SuSE-Linux-6"></a>
GCC 3.2.2 and GNU Make.  <code>x86_64-unknown-linux-gnu</code> (AMD64
Opteron &ldquo;Melody&rdquo;).

     <li>SuSE Enterprise Server 9 on IBM OpenPower 720
<a name="index-SuSE-Linux-7"></a><a name="index-OpenPower-720-8"></a>
GCC 3.3.3 and GNU Make.  <code>powerpc64-unknown-linux-gnu</code>.

     <li>RedHat Linux 7.2
<a name="index-RedHat-9"></a>
GCC 2.96 and GNU Make. <code>alphaev6-unknown-linux-gnu</code>,
<code>alphaev67-unknown-linux-gnu</code>, <code>ia64-unknown-linux-gnu</code>.

     <li>RedHat Linux 8.0
<a name="index-RedHat-10"></a>
GCC 3.2 and GNU Make. <code>i686-pc-linux-gnu</code>.

     <li>RedHat Advanced Server 2.1
<a name="index-RedHat-Advanced-Server-11"></a>
GCC 2.96 and GNU Make. <code>i686-pc-linux-gnu</code>.

     <li>Slackware Linux 8.0.01
<a name="index-RedHat-12"></a>
GCC 2.95.3 and GNU Make. <code>i686-pc-linux-gnu</code>.

     <li>Mandrake Linux 9.0
<a name="index-Mandrake-13"></a>
GCC 3.2 and GNU Make. <code>i686-pc-linux-gnu</code>.

     <li>IRIX 6.5
<a name="index-IRIX-14"></a>
MIPS C compiler, IRIX Make. <code>mips-sgi-irix6.5</code>.

     <li>AIX 4.3.2
<a name="index-AIX-15"></a>
IBM C for AIX compiler, AIX Make.  <code>rs6000-ibm-aix4.3.2.0</code>.

     <li>Microsoft Windows 2000 (Cygwin)
<a name="index-Windows-16"></a>
GCC 3.2, GNU make. <code>i686-pc-cygwin</code>.

     <li>HP-UX 11
<a name="index-HP_002dUX-17"></a>
HP-UX C compiler and HP Make. <code>ia64-hp-hpux11.22</code>,
<code>hppa2.0w-hp-hpux11.11</code>.

     <li>SUN Solaris 2.7
<a name="index-Solaris-18"></a>
GCC 3.0.4 and GNU Make. <code>sparc-sun-solaris2.7</code>.

     <li>SUN Solaris 2.8
<a name="index-Solaris-19"></a>
Sun WorkShop Compiler C 6.0 and SUN Make. <code>sparc-sun-solaris2.8</code>.

     <li>SUN Solaris 2.9
<a name="index-Solaris-20"></a>
Sun Forte Developer 7 C compiler and GNU
Make. <code>sparc-sun-solaris2.9</code>.

     <li>NetBSD 1.6
<a name="index-NetBSD-21"></a>
GCC 2.95.3 and GNU Make. <code>alpha-unknown-netbsd1.6</code>,
<code>i386-unknown-netbsdelf1.6</code>.

     <li>OpenBSD 3.1 and 3.2
<a name="index-OpenBSD-22"></a>
GCC 2.95.3 and GNU Make. <code>alpha-unknown-openbsd3.1</code>,
<code>i386-unknown-openbsd3.1</code>.

     <li>FreeBSD 4.7 and 4.8
<a name="index-FreeBSD-23"></a>
GCC 2.95.4 and GNU Make. <code>alpha-unknown-freebsd4.7</code>,
<code>alpha-unknown-freebsd4.8</code>, <code>i386-unknown-freebsd4.7</code>,
<code>i386-unknown-freebsd4.8</code>.

     <li>MacOS X 10.2 Server Edition
<a name="index-MacOS-X-24"></a>
GCC 3.1 and GNU Make. <code>powerpc-apple-darwin6.5</code>.

     <li>MacOS X 10.4 &ldquo;Tiger&rdquo; with Xcode 2.0
<a name="index-MacOS-X-25"></a>
GCC 4.0 and GNU Make. <code>powerpc-apple-darwin8.0</code>.

     <li>Cross compiled to uClinux/uClibc on Motorola Coldfire
<a name="index-Motorola-Coldfire-26"></a><a name="index-uClinux-27"></a><a name="index-uClibc-28"></a>
GCC 3.4 and GNU Make <code>m68k-uclinux-elf</code>.

     <li>Cross compiled to ARM using Glibc
<a name="index-ARM-29"></a>
GCC 2.95 and GNU Make <code>arm-linux</code>.

     <li>Cross compiled to Mingw32. 
<a name="index-Windows-30"></a><a name="index-Microsoft-31"></a><a name="index-mingw32-32"></a>
GCC 3.4.4 and GNU Make <code>i586-mingw32msvc</code>.

        </ol>

   <p>If you use Libidn on, or port Libidn to, a new platform please report
it to the author.

<div class="node">
<p><hr>
<a name="Getting-help"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Commercial-Support">Commercial Support</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Supported-Platforms">Supported Platforms</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Introduction">Introduction</a>

</div>

<h3 class="section">1.5 Getting help</h3>

<p>A mailing list where users of Libidn may help each other exists, and
you can reach it by sending e-mail to <a href="mailto:help-libidn@gnu.org">help-libidn@gnu.org</a>. 
Archives of the mailing list discussions, and an interface to manage
subscriptions, is available through the World Wide Web at
<a href="http://lists.gnu.org/mailman/listinfo/help-libidn">http://lists.gnu.org/mailman/listinfo/help-libidn</a>.

<div class="node">
<p><hr>
<a name="Commercial-Support"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Downloading-and-Installing">Downloading and Installing</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Getting-help">Getting help</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Introduction">Introduction</a>

</div>

<h3 class="section">1.6 Commercial Support</h3>

<p>Commercial support is available for users of GNU Libidn.  The kind of
support that can be purchased may include:

     <ul>
<li>Implement new features. 
Such as country code specific profiling to support a restricted subset
of Unicode.

     <li>Port Libidn to new platforms. 
This could include porting Libidn to an embedded platforms that may
need memory or size optimization.

     <li>Integrating IDN support in your existing project.

     <li>System design of components related to IDN.

   </ul>

   <p>If you are interested, please write to:

<pre class="verbatim">
Simon Josefsson Datakonsult
Hagagatan 24
113 47 Stockholm
Sweden

E-mail: simon@josefsson.org
</pre>

   <p>If your company provide support related to GNU Libidn and would like
to be mentioned here, contact the author (see <a href="#Bug-Reports">Bug Reports</a>).

<div class="node">
<p><hr>
<a name="Downloading-and-Installing"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Bug-Reports">Bug Reports</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Commercial-Support">Commercial Support</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Introduction">Introduction</a>

</div>

<h3 class="section">1.7 Downloading and Installing</h3>

<p><a name="index-Installation-33"></a><a name="index-Download-34"></a>
The package can be downloaded from several places, including:

   <p><a href="http://josefsson.org/libidn/releases/">http://josefsson.org/libidn/releases/</a>

   <p>The latest version is stored in a file, e.g.,
`<samp><span class="samp">gsasl-0.6.14.tar.gz</span></samp>' where the `<samp><span class="samp">0.6.14</span></samp>'
value is the highest version number in the directory.

   <p>The package is then extracted, configured and built like many other
packages that use Autoconf.  For detailed information on configuring
and building it, refer to the <samp><span class="file">INSTALL</span></samp> file that is part of the
distribution archive.

   <p>Here is an example terminal session that download, configure, build
and install the package.  You will need a few basic tools, such as
`<samp><span class="samp">sh</span></samp>', `<samp><span class="samp">make</span></samp>' and `<samp><span class="samp">cc</span></samp>'.

<pre class="example">     $ wget -q http://josefsson.org/libidn/releases/libidn-0.6.14.tar.gz
     $ tar xfz libidn-0.6.14.tar.gz
     $ cd libidn-0.6.14/
     $ ./configure
     ...
     $ make
     ...
     $ make install
     ...
</pre>
   <p>After that Libidn should be properly installed and ready for use.

   <p>A few <code>configure</code> options may be relevant, summarized in the
table.

     <dl>
<dt><code>--enable-java</code><dd>Build the Java port into a *.JAR file.  See <a href="#Java-API">Java API</a>, for more
information.

     <br><dt><code>--disable-tld</code><dd>Disable the TLD module.  This would typically only be useful if you
are building on a memory restricted platforms.  See <a href="#TLD-Functions">TLD Functions</a>,
for more information.

     <br><dt><code>--enable-csharp[=IMPL]</code><dd>Build the C3 port into a *.DLL file.  See <a href="#C_0023-API">C# API</a>, for more
information.  Here, <code>IMPL</code> is <code>pnet</code> or <code>mono</code>,
indicating whether the PNET <samp><span class="command">cscc</span></samp> compiler or the Mono
<samp><span class="command">mcs</span></samp> compiler should be used, respectively.

   </dl>

   <p>For the complete list, refer to the output from <code>configure
--help</code>.

<div class="node">
<p><hr>
<a name="Bug-Reports"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Contributing">Contributing</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Downloading-and-Installing">Downloading and Installing</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Introduction">Introduction</a>

</div>

<h3 class="section">1.8 Bug Reports</h3>

<p><a name="index-Reporting-Bugs-35"></a>
If you think you have found a bug in Libidn, please investigate it and
report it.

     <ul>
<li>Please make sure that the bug is really in Libidn, and
preferably also check that it hasn't already been fixed in the latest
version.

     <li>You have to send us a test case that makes it possible for us to
reproduce the bug.

     <li>You also have to explain what is wrong; if you get a crash, or
if the results printed are not good and in that case, in what way. 
Make sure that the bug report includes all information you would need
to fix this kind of bug for someone else.

   </ul>

   <p>Please make an effort to produce a self-contained report, with
something definite that can be tested or debugged.  Vague queries or
piecemeal messages are difficult to act on and don't help the
development effort.

   <p>If your bug report is good, we will do our best to help you to get a
corrected version of the software; if the bug report is poor, we won't
do anything about it (apart from asking you to send better bug
reports).

   <p>If you think something in this manual is unclear, or downright
incorrect, or if the language needs to be improved, please also send a
note.

   <p>Send your bug report to:

<div align="center">`<samp><span class="samp">bug-libidn@gnu.org</span></samp>'</div>

<div class="node">
<p><hr>
<a name="Contributing"></a>
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Bug-Reports">Bug Reports</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Introduction">Introduction</a>

</div>

<h3 class="section">1.9 Contributing</h3>

<p><a name="index-Contributing-36"></a><a name="index-Hacking-37"></a>
If you want to submit a patch for inclusion &ndash; from solve a typo you
discovered, up to adding support for a new feature &ndash; you should
submit it as a bug report (see <a href="#Bug-Reports">Bug Reports</a>).  There are some
things that you can do to increase the chances for it to be included
in the official package.

   <p>Unless your patch is very small (say, under 10 lines) we require that
you assign the copyright of your work to the Free Software Foundation. 
This is to protect the freedom of the project.  If you have not
already signed papers, we will send you the necessary information when
you submit your contribution.

   <p>For contributions that doesn't consist of actual programming code, the
only guidelines are common sense.  Use it.

   <p>For code contributions, a number of style guides will help you:

     <ul>
<li>Coding Style. 
Follow the GNU Standards document (see <a href="standards.html#Top">GNU Coding Standards</a>).

     <p>If you normally code using another coding standard, there is no
problem, but you should use `<samp><span class="samp">indent</span></samp>' to reformat the code
(see <a href="indent.html#Top">GNU Indent</a>) before submitting your work.

     <li>Use the unified diff format `<samp><span class="samp">diff -u</span></samp>'.

     <li>Return errors. 
No reason whatsoever should abort the execution of the library.  Even
memory allocation errors, e.g. when malloc return NULL, should work
although result in an error code.

     <li>Design with thread safety in mind. 
Don't use global variables and the like.

     <li>Avoid using the C math library. 
It causes problems for embedded implementations, and in most
situations it is very easy to avoid using it.

     <li>Document your functions. 
Use comments before each function headers, that, if properly
formatted, are extracted into GTK-DOC web pages.  Don't forget to
update the Texinfo manual as well.

     <li>Supply a ChangeLog and NEWS entries, where appropriate.

   </ul>

<!-- ********************************************************** -->
<!-- *******************  Preparation  ************************ -->
<!-- ********************************************************** -->
<div class="node">
<p><hr>
<a name="Preparation"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Utility-Functions">Utility Functions</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Introduction">Introduction</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="chapter">2 Preparation</h2>

<p>To use `Libidn', you have to perform some changes to your sources and
the build system.  The necessary changes are small and explained in
the following sections.  At the end of this chapter, it is described
how the library is initialized, and how the requirements of the
library are verified.

   <p>A faster way to find out how to adapt your application for use with
`Libidn' may be to look at the examples at the end of this manual
(see <a href="#Examples">Examples</a>).

<ul class="menu">
<li><a accesskey="1" href="#Header">Header</a>
<li><a accesskey="2" href="#Initialization">Initialization</a>
<li><a accesskey="3" href="#Version-Check">Version Check</a>
<li><a accesskey="4" href="#Building-the-source">Building the source</a>
<li><a accesskey="5" href="#Autoconf-tests">Autoconf tests</a>
</ul>

<div class="node">
<p><hr>
<a name="Header"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Initialization">Initialization</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Preparation">Preparation</a>

</div>

<h3 class="section">2.1 Header</h3>

<p>The library contains a few independent parts, and each part export the
interfaces (data types and functions) in a header file.  You must
include the appropriate header files in all programs using the
library, either directly or through some other header file, like this:

<pre class="example">     #include &lt;stringprep.h&gt;
</pre>
   <p>The header files and the functions they define are categorized as
follows:

     <dl>
<dt>stringprep.h<dd>
The low-level stringprep API entry point.  For IDN applications, this
is usually invoked via IDNA. Some applications, specifically non-IDN
ones, may want to prepare strings directly though, and should include
this header file.

     <p>The name space of the stringprep part of Libidn is <code>stringprep*</code>
for function names, <code>Stringprep*</code> for data types and
<code>STRINGPREP_*</code> for other symbols.  In addition,
<code>_stringprep*</code> is reserved for internal use and should never be
used by applications.

     <br><dt>punycode.h<dd>
The entry point to Punycode encoding and decoding functions.  Normally
punycode is used via the idna.h interface, but some application may
want to perform raw punycode operations.

     <p>The name space of the punycode part of Libidn is <code>punycode_*</code> for
function names, <code>Punycode*</code> for data types and <code>PUNYCODE_*</code>
for other symbols.  In addition, <code>_punycode*</code> is reserved for
internal use and should never be used by applications. 
<br><dt>idna.h<dd>
The entry point to the IDNA functions.  This is the normal entry point
for applications that need IDN functionality.

     <p>The name space of the IDNA part of Libidn is <code>idna_*</code> for
function names, <code>Idna*</code> for data types and <code>IDNA_*</code> for
other symbols.  In addition, <code>_idna*</code> is reserved for internal
use and should never be used by applications.

     <br><dt>tld.h<dd>
The entry point to the TLD functions.  Normal applications are not
expected to need this functionality, but it is present for
applications that are used by TLDs to validate customer input.

     <p>The name space of the TLD part of Libidn is <code>tld_*</code> for function
names, <code>Tld_*</code> for data types and <code>TLD_*</code> for other symbols. 
In addition, <code>_tld*</code> is reserved for internal use and should
never be used by applications.

     <br><dt>pr29.h<dd>
The entry point to the PR29 functions.  These functions are used to
detect &ldquo;problem sequences&rdquo; (see <a href="#PR29-Functions">PR29 Functions</a>), mostly for use
in security critical applications.

     <p>The name space of the PR29 part of Libidn is <code>pr29_*</code> for
function names, <code>Pr29_*</code> for data types and <code>PR29_*</code> for
other symbols.  In addition, <code>_pr29*</code> is reserved for internal
use and should never be used by applications.

   </dl>

<div class="node">
<p><hr>
<a name="Initialization"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Version-Check">Version Check</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Header">Header</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Preparation">Preparation</a>

</div>

<h3 class="section">2.2 Initialization</h3>

<p>Libidn is stateless and does not need any initialization.

<div class="node">
<p><hr>
<a name="Version-Check"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Building-the-source">Building the source</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Initialization">Initialization</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Preparation">Preparation</a>

</div>

<h3 class="section">2.3 Version Check</h3>

<p>It is often desirable to check that the version of `Libidn' used is
indeed one which fits all requirements.  Even with binary
compatibility new features may have been introduced but due to problem
with the dynamic linker an old version is actually used.  So you may
want to check that the version is okay right after program startup.

<h4 class="subheading">stringprep_check_version</h4>

<p><a name="stringprep_005fcheck_005fversion"></a>

<div class="defun">
&mdash; Function: const char * <b>stringprep_check_version</b> (<var>const char * req_version</var>)<var><a name="index-stringprep_005fcheck_005fversion-38"></a></var><br>
<blockquote><p><var>req_version</var>: Required version number, or NULL.

        <p>Check that the the version of the library is at minimum the requested one
and return the version string; return NULL if the condition is not
satisfied.  If a NULL is passed to this function, no check is done,
but the version string is simply returned.

        <p>See <code>STRINGPREP_VERSION</code> for a suitable <code>req_version</code> string.

        <p><strong>Return value:</strong> Version string of run-time library, or NULL if the
run-time library does not meet the required version number. 
</p></blockquote></div>

   <p>The normal way to use the function is to put something similar to the
following first in your <code>main</code>:

<pre class="example">       if (!stringprep_check_version (STRINGPREP_VERSION))
         {
           printf ("stringprep_check_version() failed:\n"
                   "Header file incompatible with shared library.\n");
           exit(1);
         }
</pre>
   <div class="node">
<p><hr>
<a name="Building-the-source"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Autoconf-tests">Autoconf tests</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Version-Check">Version Check</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Preparation">Preparation</a>

</div>

<h3 class="section">2.4 Building the source</h3>

<p><a name="index-Compiling-your-application-39"></a>
If you want to compile a source file including e.g. the `idna.h' header
file, you must make sure that the compiler can find it in the
directory hierarchy.  This is accomplished by adding the path to the
directory in which the header file is located to the compilers include
file search path (via the <samp><span class="option">-I</span></samp> option).

   <p>However, the path to the include file is determined at the time the
source is configured.  To solve this problem, `Libidn' uses the
external package <samp><span class="command">pkg-config</span></samp> that knows the path to the
include file and other configuration options.  The options that need
to be added to the compiler invocation at compile time are output by
the <samp><span class="option">--cflags</span></samp> option to <samp><span class="command">pkg-config libidn</span></samp>.  The
following example shows how it can be used at the command line:

<pre class="example">     gcc -c foo.c `pkg-config libidn --cflags`
</pre>
   <p>Adding the output of `<samp><span class="samp">pkg-config libidn --cflags</span></samp>' to the
compilers command line will ensure that the compiler can find e.g. the
idna.h header file.

   <p>A similar problem occurs when linking the program with the library. 
Again, the compiler has to find the library files.  For this to work,
the path to the library files has to be added to the library search
path (via the <samp><span class="option">-L</span></samp> option).  For this, the option
<samp><span class="option">--libs</span></samp> to <samp><span class="command">pkg-config libidn</span></samp> can be used.  For
convenience, this option also outputs all other options that are
required to link the program with the `libidn' libarary.  The example
shows how to link <samp><span class="file">foo.o</span></samp> with the `libidn' library to a program
<samp><span class="command">foo</span></samp>.

<pre class="example">     gcc -o foo foo.o `pkg-config libidn --libs`
</pre>
   <p>Of course you can also combine both examples to a single command by
specifying both options to <samp><span class="command">pkg-config</span></samp>:

<pre class="example">     gcc -o foo foo.c `pkg-config libidn --cflags --libs`
</pre>
   <div class="node">
<p><hr>
<a name="Autoconf-tests"></a>
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Building-the-source">Building the source</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Preparation">Preparation</a>

</div>

<h3 class="section">2.5 Autoconf tests</h3>

<p><a name="index-Autoconf-tests-40"></a><a name="index-Configure-tests-41"></a>
If your project uses Autoconf (see <a href="autoconf.html#Top">GNU Autoconf</a>)
to check for installed libraries, you might find the following snippet
illustrative.  It add a new <samp><span class="file">configure</span></samp> parameter
<code>--with-libidn</code>, and check for <samp><span class="file">idna.h</span></samp> and `<samp><span class="samp">-lidn</span></samp>'
(possibly below the directory specified as the optional argument to
<code>--with-libidn</code>), and define the <acronym>CPP</acronym> symbol
<code>LIBIDN</code> if the library is found.  The default behaviour is to
search for the library and enable the functionality (that is, define
the symbol) when the library is found, but if you wish to make the
default behaviour of your package be that Libidn is not used (even if
it is installed on the system), change `<samp><span class="samp">libidn=yes</span></samp>' to
`<samp><span class="samp">libidn=no</span></samp>' on the third line.

<pre class="example">     AC_ARG_WITH(libidn, AC_HELP_STRING([--with-libidn=[DIR]],
                                     [Support IDN (needs GNU Libidn)]),
       libidn=$withval, libidn=yes)
     if test "$libidn" != "no"; then
       if test "$libidn" != "yes"; then
         LDFLAGS="${LDFLAGS} -L$libidn/lib"
         CPPFLAGS="${CPPFLAGS} -I$libidn/include"
       fi
       AC_CHECK_HEADER(idna.h,
         AC_CHECK_LIB(idn, stringprep_check_version,
           [libidn=yes LIBS="${LIBS} -lidn"], libidn=no),
         libidn=no)
     fi
     if test "$libidn" != "no" ; then
       AC_DEFINE(LIBIDN, 1, [Define to 1 if you want IDN support.])
     else
       AC_MSG_WARN([Libidn not found])
     fi
     AC_MSG_CHECKING([if Libidn should be used])
     AC_MSG_RESULT($libidn)
</pre>
   <p>If you require that your users have installed <code>pkg-config</code> (which
I cannot recommend generally), the above can be done more easily as
follows.

<pre class="example">     AC_ARG_WITH(libidn, AC_HELP_STRING([--with-libidn=[DIR]],
                                     [Support IDN (needs GNU Libidn)]),
       libidn=$withval, libidn=yes)
     if test "$libidn" != "no" ; then
       PKG_CHECK_MODULES(LIBIDN, libidn &gt;= 0.0.0, [libidn=yes], [libidn=no])
       if test "$libidn" != "yes" ; then
         libidn=no
         AC_MSG_WARN([Libidn not found])
       else
         libidn=yes
         AC_DEFINE(LIBIDN, 1, [Define to 1 if you want Libidn.])
       fi
     fi
     AC_MSG_CHECKING([if Libidn should be used])
     AC_MSG_RESULT($libidn)
</pre>
   <!-- ********************************************************** -->
<!-- ********************  Utility Functions ****************** -->
<!-- ********************************************************** -->
<div class="node">
<p><hr>
<a name="Utility-Functions"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Stringprep-Functions">Stringprep Functions</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Preparation">Preparation</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="chapter">3 Utility Functions</h2>

<p><a name="index-Utility-Functions-42"></a>
The rest of this library makes extensive use of Unicode characters. 
In order to interface this library with the outside world, your
application may need to make various Unicode transformations.

<h3 class="section">3.1 Header file <code>stringprep.h</code></h3>

<p>To use the functions explained in this chapter, you need to include
the file <samp><span class="file">stringprep.h</span></samp> using:

<pre class="example">     #include &lt;stringprep.h&gt;
</pre>
   <h3 class="section">3.2 Unicode Encoding Transformation</h3>

<h4 class="subheading">stringprep_unichar_to_utf8</h4>

<p><a name="stringprep_005funichar_005fto_005futf8"></a>

<div class="defun">
&mdash; Function: int <b>stringprep_unichar_to_utf8</b> (<var>uint32_t c, char * outbuf</var>)<var><a name="index-stringprep_005funichar_005fto_005futf8-43"></a></var><br>
<blockquote><p><var>c</var>: a ISO10646 character code

        <p><var>outbuf</var>: output buffer, must have at least 6 bytes of space. 
If <code>NULL</code>, the length will be computed and returned
and nothing will be written to <code>outbuf</code>.

        <p>Converts a single character to UTF-8.

        <p><strong>Return value:</strong> number of bytes written. 
</p></blockquote></div>

<h4 class="subheading">stringprep_utf8_to_unichar</h4>

<p><a name="stringprep_005futf8_005fto_005funichar"></a>

<div class="defun">
&mdash; Function: uint32_t <b>stringprep_utf8_to_unichar</b> (<var>const char * p</var>)<var><a name="index-stringprep_005futf8_005fto_005funichar-44"></a></var><br>
<blockquote><p><var>p</var>: a pointer to Unicode character encoded as UTF-8

        <p>Converts a sequence of bytes encoded as UTF-8 to a Unicode character. 
If <code>p</code> does not point to a valid UTF-8 encoded character, results are
undefined.

        <p><strong>Return value:</strong> the resulting character. 
</p></blockquote></div>

<h4 class="subheading">stringprep_ucs4_to_utf8</h4>

<p><a name="stringprep_005fucs4_005fto_005futf8"></a>

<div class="defun">
&mdash; Function: char * <b>stringprep_ucs4_to_utf8</b> (<var>const uint32_t * str, ssize_t len, size_t * items_read, size_t * items_written</var>)<var><a name="index-stringprep_005fucs4_005fto_005futf8-45"></a></var><br>
<blockquote><p><var>str</var>: a UCS-4 encoded string

        <p><var>len</var>: the maximum length of <code>str</code> to use. If <code>len</code> &lt; 0, then
the string is terminated with a 0 character.

        <p><var>items_read</var>: location to store number of characters read read, or <code>NULL</code>.

        <p><var>items_written</var>: location to store number of bytes written or <code>NULL</code>. 
The value here stored does not include the trailing 0
byte.

        <p>Convert a string from a 32-bit fixed width representation as UCS-4. 
to UTF-8. The result will be terminated with a 0 byte.

        <p><strong>Return value:</strong> a pointer to a newly allocated UTF-8 string. 
This value must be freed with <code>free()</code>. If an
error occurs, <code>NULL</code> will be returned and
<code>error</code> set. 
</p></blockquote></div>

<h4 class="subheading">stringprep_utf8_to_ucs4</h4>

<p><a name="stringprep_005futf8_005fto_005fucs4"></a>

<div class="defun">
&mdash; Function: uint32_t * <b>stringprep_utf8_to_ucs4</b> (<var>const char * str, ssize_t len, size_t * items_written</var>)<var><a name="index-stringprep_005futf8_005fto_005fucs4-46"></a></var><br>
<blockquote><p><var>str</var>: a UTF-8 encoded string

        <p><var>len</var>: the maximum length of <code>str</code> to use. If <code>len</code> &lt; 0, then
the string is nul-terminated.

        <p><var>items_written</var>: location to store the number of characters in the
result, or <code>NULL</code>.

        <p>Convert a string from UTF-8 to a 32-bit fixed width
representation as UCS-4, assuming valid UTF-8 input. 
This function does no error checking on the input.

        <p><strong>Return value:</strong> a pointer to a newly allocated UCS-4 string. 
This value must be freed with <code>free()</code>. 
</p></blockquote></div>

<h3 class="section">3.3 Unicode Normalization</h3>

<h4 class="subheading">stringprep_ucs4_nfkc_normalize</h4>

<p><a name="stringprep_005fucs4_005fnfkc_005fnormalize"></a>

<div class="defun">
&mdash; Function: uint32_t * <b>stringprep_ucs4_nfkc_normalize</b> (<var>uint32_t * str, ssize_t len</var>)<var><a name="index-stringprep_005fucs4_005fnfkc_005fnormalize-47"></a></var><br>
<blockquote><p><var>str</var>: a Unicode string.

        <p><var>len</var>: length of <code>str</code> array, or -1 if <code>str</code> is nul-terminated.

        <p>Converts UCS4 string into UTF-8 and runs
<code>stringprep_utf8_nfkc_normalize()</code>.

        <p><strong>Return value:</strong> a newly allocated Unicode string, that is the NFKC
normalized form of <code>str</code>. 
</p></blockquote></div>

<h4 class="subheading">stringprep_utf8_nfkc_normalize</h4>

<p><a name="stringprep_005futf8_005fnfkc_005fnormalize"></a>

<div class="defun">
&mdash; Function: char * <b>stringprep_utf8_nfkc_normalize</b> (<var>const char * str, ssize_t len</var>)<var><a name="index-stringprep_005futf8_005fnfkc_005fnormalize-48"></a></var><br>
<blockquote><p><var>str</var>: a UTF-8 encoded string.

        <p><var>len</var>: length of <code>str</code>, in bytes, or -1 if <code>str</code> is nul-terminated.

        <p>Converts a string into canonical form, standardizing
such issues as whether a character with an accent
is represented as a base character and combining
accent or as a single precomposed character.

        <p>The normalization mode is NFKC (ALL COMPOSE).  It standardizes
differences that do not affect the text content, such as the
above-mentioned accent representation. It standardizes the
"compatibility" characters in Unicode, such as SUPERSCRIPT THREE to
the standard forms (in this case DIGIT THREE). Formatting
information may be lost but for most text operations such
characters should be considered the same. It returns a result with
composed forms rather than a maximally decomposed form.

        <p><strong>Return value:</strong> a newly allocated string, that is the
NFKC normalized form of <code>str</code>. 
</p></blockquote></div>

<h3 class="section">3.4 Character Set Conversion</h3>

<h4 class="subheading">stringprep_locale_charset</h4>

<p><a name="stringprep_005flocale_005fcharset"></a>

<div class="defun">
&mdash; Function: const char * <b>stringprep_locale_charset</b> (<var> void</var>)<var><a name="index-stringprep_005flocale_005fcharset-49"></a></var><br>
<blockquote>
<p>Find out current locale charset.  The function respect the CHARSET
environment variable, but typically uses nl_langinfo(CODESET) when
it is supported.  It fall back on "ASCII" if CHARSET isn't set and
nl_langinfo isn't supported or return anything.

        <p>Note that this function return the application's locale's preferred
charset (or thread's locale's preffered charset, if your system
support thread-specific locales).  It does not return what the
system may be using.  Thus, if you receive data from external
sources you cannot in general use this function to guess what
charset it is encoded in.  Use stringprep_convert from the external
representation into the charset returned by this function, to have
data in the locale encoding.

        <p><strong>Return value:</strong> Return the character set used by the current locale. 
It will never return NULL, but use "ASCII" as a fallback. 
</p></blockquote></div>

<h4 class="subheading">stringprep_convert</h4>

<p><a name="stringprep_005fconvert"></a>

<div class="defun">
&mdash; Function: char * <b>stringprep_convert</b> (<var>const char * str, const char * to_codeset, const char * from_codeset</var>)<var><a name="index-stringprep_005fconvert-50"></a></var><br>
<blockquote><p><var>str</var>: input zero-terminated string.

        <p><var>to_codeset</var>: name of destination character set.

        <p><var>from_codeset</var>: name of origin character set, as used by <code>str</code>.

        <p>Convert the string from one character set to another using the
system's <code>iconv()</code> function.

        <p><strong>Return value:</strong> Returns newly allocated zero-terminated string which
is <code>str</code> transcoded into to_codeset. 
</p></blockquote></div>

<h4 class="subheading">stringprep_locale_to_utf8</h4>

<p><a name="stringprep_005flocale_005fto_005futf8"></a>

<div class="defun">
&mdash; Function: char * <b>stringprep_locale_to_utf8</b> (<var>const char * str</var>)<var><a name="index-stringprep_005flocale_005fto_005futf8-51"></a></var><br>
<blockquote><p><var>str</var>: input zero terminated string.

        <p>Convert string encoded in the locale's character set into UTF-8 by
using <code>stringprep_convert()</code>.

        <p><strong>Return value:</strong> Returns newly allocated zero-terminated string which
is <code>str</code> transcoded into UTF-8. 
</p></blockquote></div>

<h4 class="subheading">stringprep_utf8_to_locale</h4>

<p><a name="stringprep_005futf8_005fto_005flocale"></a>

<div class="defun">
&mdash; Function: char * <b>stringprep_utf8_to_locale</b> (<var>const char * str</var>)<var><a name="index-stringprep_005futf8_005fto_005flocale-52"></a></var><br>
<blockquote><p><var>str</var>: input zero terminated string.

        <p>Convert string encoded in UTF-8 into the locale's character set by
using <code>stringprep_convert()</code>.

        <p><strong>Return value:</strong> Returns newly allocated zero-terminated string which
is <code>str</code> transcoded into the locale's character set. 
</p></blockquote></div>

<!-- ********************************************************** -->
<!-- ******************  Stringprep Functions ***************** -->
<!-- ********************************************************** -->
<div class="node">
<p><hr>
<a name="Stringprep-Functions"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Punycode-Functions">Punycode Functions</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Utility-Functions">Utility Functions</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="chapter">4 Stringprep Functions</h2>

<p><a name="index-Stringprep-Functions-53"></a>
Stringprep describes a framework for preparing Unicode text strings in
order to increase the likelihood that string input and string
comparison work in ways that make sense for typical users throughout
the world. The stringprep protocol is useful for protocol identifier
values, company and personal names, internationalized domain names,
and other text strings.

<h3 class="section">4.1 Header file <code>stringprep.h</code></h3>

<p>To use the functions explained in this chapter, you need to include
the file <samp><span class="file">stringprep.h</span></samp> using:

<pre class="example">     #include &lt;stringprep.h&gt;
</pre>
   <h3 class="section">4.2 Defining A Stringprep Profile</h3>

<p>Further types and structures are defined for applications that want to
specify their own stringprep profile.  As these are fairly obscure,
and by necessity tied to the implementation, we do not document them
here.  Look into the <samp><span class="file">stringprep.h</span></samp> header file, and the
<samp><span class="file">profiles.c</span></samp> source code for the details.

<h3 class="section">4.3 Control Flags</h3>

<div class="defun">
&mdash; Stringprep flags: Stringprep_profile_flags <b>STRINGPREP_NO_NFKC</b><var><a name="index-STRINGPREP_005fNO_005fNFKC-54"></a></var><br>
<blockquote><p>Disable the NFKC normalization, as well as selecting the non-NFKC case
folding tables.  Usually the profile specifies BIDI and NFKC settings,
and applications should not override it unless in special situations. 
</p></blockquote></div>

<div class="defun">
&mdash; Stringprep flags: Stringprep_profile_flags <b>STRINGPREP_NO_BIDI</b><var><a name="index-STRINGPREP_005fNO_005fBIDI-55"></a></var><br>
<blockquote><p>Disable the BIDI step.  Usually the profile specifies BIDI and NFKC
settings, and applications should not override it unless in special
situations. 
</p></blockquote></div>

<div class="defun">
&mdash; Stringprep flags: Stringprep_profile_flags <b>STRINGPREP_NO_UNASSIGNED</b><var><a name="index-STRINGPREP_005fNO_005fUNASSIGNED-56"></a></var><br>
<blockquote><p>Make the library return with an error if string contains unassigned
characters according to profile. 
</p></blockquote></div>

<h3 class="section">4.4 Core Functions</h3>

<h4 class="subheading">stringprep_4i</h4>

<p><a name="stringprep_005f4i"></a>

<div class="defun">
&mdash; Function: int <b>stringprep_4i</b> (<var>uint32_t * ucs4, size_t * len, size_t maxucs4len, Stringprep_profile_flags flags, const Stringprep_profile * profile</var>)<var><a name="index-stringprep_005f4i-57"></a></var><br>
<blockquote><p><var>ucs4</var>: input/output array with string to prepare.

        <p><var>len</var>: on input, length of input array with Unicode code points,
on exit, length of output array with Unicode code points.

        <p><var>maxucs4len</var>: maximum length of input/output array.

        <p><var>flags</var>: a <code>Stringprep_profile_flags</code> value, or 0.

        <p><var>profile</var>: pointer to <code>Stringprep_profile</code> to use.

        <p>Prepare the input UCS-4 string according to the stringprep profile,
and write back the result to the input string.

        <p>The input is not required to be zero terminated (<code>ucs4</code>[<code>len</code>] = 0). 
The output will not be zero terminated unless <code>ucs4</code>[<code>len</code>] = 0. 
Instead, see <code>stringprep_4zi()</code> if your input is zero terminated or
if you want the output to be.

        <p>Since the stringprep operation can expand the string, <code>maxucs4len</code>
indicate how large the buffer holding the string is.  This function
will not read or write to code points outside that size.

        <p>The <code>flags</code> are one of <code>Stringprep_profile_flags</code> values, or 0.

        <p>The <code>profile</code> contain the <code>Stringprep_profile</code> instructions to
perform.  Your application can define new profiles, possibly
re-using the generic stringprep tables that always will be part of
the library, or use one of the currently supported profiles.

        <p><strong>Return value:</strong> Returns <code>STRINGPREP_OK</code> iff successful, or an
<code>Stringprep_rc</code> error code. 
</p></blockquote></div>

<h4 class="subheading">stringprep_4zi</h4>

<p><a name="stringprep_005f4zi"></a>

<div class="defun">
&mdash; Function: int <b>stringprep_4zi</b> (<var>uint32_t * ucs4, size_t maxucs4len, Stringprep_profile_flags flags, const Stringprep_profile * profile</var>)<var><a name="index-stringprep_005f4zi-58"></a></var><br>
<blockquote><p><var>ucs4</var>: input/output array with zero terminated string to prepare.

        <p><var>maxucs4len</var>: maximum length of input/output array.

        <p><var>flags</var>: a <code>Stringprep_profile_flags</code> value, or 0.

        <p><var>profile</var>: pointer to <code>Stringprep_profile</code> to use.

        <p>Prepare the input zero terminated UCS-4 string according to the
stringprep profile, and write back the result to the input string.

        <p>Since the stringprep operation can expand the string, <code>maxucs4len</code>
indicate how large the buffer holding the string is.  This function
will not read or write to code points outside that size.

        <p>The <code>flags</code> are one of <code>Stringprep_profile_flags</code> values, or 0.

        <p>The <code>profile</code> contain the <code>Stringprep_profile</code> instructions to
perform.  Your application can define new profiles, possibly
re-using the generic stringprep tables that always will be part of
the library, or use one of the currently supported profiles.

        <p><strong>Return value:</strong> Returns <code>STRINGPREP_OK</code> iff successful, or an
<code>Stringprep_rc</code> error code. 
</p></blockquote></div>

<h4 class="subheading">stringprep</h4>

<p><a name="stringprep"></a>

<div class="defun">
&mdash; Function: int <b>stringprep</b> (<var>char * in, size_t maxlen, Stringprep_profile_flags flags, const Stringprep_profile * profile</var>)<var><a name="index-stringprep-59"></a></var><br>
<blockquote><p><var>in</var>: input/ouput array with string to prepare.

        <p><var>maxlen</var>: maximum length of input/output array.

        <p><var>flags</var>: a <code>Stringprep_profile_flags</code> value, or 0.

        <p><var>profile</var>: pointer to <code>Stringprep_profile</code> to use.

        <p>Prepare the input zero terminated UTF-8 string according to the
stringprep profile, and write back the result to the input string.

        <p>Note that you must convert strings entered in the systems locale
into UTF-8 before using this function, see
<code>stringprep_locale_to_utf8()</code>.

        <p>Since the stringprep operation can expand the string, <code>maxlen</code>
indicate how large the buffer holding the string is.  This function
will not read or write to characters outside that size.

        <p>The <code>flags</code> are one of <code>Stringprep_profile_flags</code> values, or 0.

        <p>The <code>profile</code> contain the <code>Stringprep_profile</code> instructions to
perform.  Your application can define new profiles, possibly
re-using the generic stringprep tables that always will be part of
the library, or use one of the currently supported profiles.

        <p><strong>Return value:</strong> Returns <code>STRINGPREP_OK</code> iff successful, or an error code. 
</p></blockquote></div>

<h4 class="subheading">stringprep_profile</h4>

<p><a name="stringprep_005fprofile"></a>

<div class="defun">
&mdash; Function: int <b>stringprep_profile</b> (<var>const char * in, char ** out, const char * profile, Stringprep_profile_flags flags</var>)<var><a name="index-stringprep_005fprofile-60"></a></var><br>
<blockquote><p><var>in</var>: input array with UTF-8 string to prepare.

        <p><var>out</var>: output variable with pointer to newly allocate string.

        <p><var>profile</var>: name of stringprep profile to use.

        <p><var>flags</var>: a <code>Stringprep_profile_flags</code> value, or 0.

        <p>Prepare the input zero terminated UTF-8 string according to the
stringprep profile, and return the result in a newly allocated
variable.

        <p>Note that you must convert strings entered in the systems locale
into UTF-8 before using this function, see
<code>stringprep_locale_to_utf8()</code>.

        <p>The output <code>out</code> variable must be deallocated by the caller.

        <p>The <code>flags</code> are one of <code>Stringprep_profile_flags</code> values, or 0.

        <p>The <code>profile</code> specifies the name of the stringprep profile to use. 
It must be one of the internally supported stringprep profiles.

        <p><strong>Return value:</strong> Returns <code>STRINGPREP_OK</code> iff successful, or an error code. 
</p></blockquote></div>

<h3 class="section">4.5 Error Handling</h3>

<h4 class="subheading">stringprep_strerror</h4>

<p><a name="stringprep_005fstrerror"></a>

<div class="defun">
&mdash; Function: const char * <b>stringprep_strerror</b> (<var>Stringprep_rc rc</var>)<var><a name="index-stringprep_005fstrerror-61"></a></var><br>
<blockquote><p><var>rc</var>: a <code>Stringprep_rc</code> return code.

        <p>Convert a return code integer to a text string.  This string can be
used to output a diagnostic message to the user.

        <p><strong>STRINGPREP_OK:</strong> Successful operation.  This value is guaranteed to
always be zero, the remaining ones are only guaranteed to hold
non-zero values, for logical comparison purposes.

        <p><strong>STRINGPREP_CONTAINS_UNASSIGNED:</strong> String contain unassigned Unicode
code points, which is forbidden by the profile.

        <p><strong>STRINGPREP_CONTAINS_PROHIBITED:</strong> String contain code points
prohibited by the profile.

        <p><strong>STRINGPREP_BIDI_BOTH_L_AND_RAL:</strong> String contain code points with
conflicting bidirection category.

        <p><strong>STRINGPREP_BIDI_LEADTRAIL_NOT_RAL:</strong> Leading and trailing character
in string not of proper bidirectional category.

        <p><strong>STRINGPREP_BIDI_CONTAINS_PROHIBITED:</strong> Contains prohibited code
points detected by bidirectional code.

        <p><strong>STRINGPREP_TOO_SMALL_BUFFER:</strong> Buffer handed to function was too
small.  This usually indicate a problem in the calling
application.

        <p><strong>STRINGPREP_PROFILE_ERROR:</strong> The stringprep profile was inconsistent. 
This usually indicate an internal error in the library.

        <p><strong>STRINGPREP_FLAG_ERROR:</strong> The supplied flag conflicted with profile. 
This usually indicate a problem in the calling application.

        <p><strong>STRINGPREP_UNKNOWN_PROFILE:</strong> The supplied profile name was not
known to the library.

        <p><strong>STRINGPREP_NFKC_FAILED:</strong> The Unicode NFKC operation failed.  This
usually indicate an internal error in the library.

        <p><strong>STRINGPREP_MALLOC_ERROR:</strong> The <code>malloc()</code> was out of memory.  This is
usually a fatal error.

        <p><strong>Return value:</strong> Returns a pointer to a statically allocated string
containing a description of the error with the return code <code>rc</code>. 
</p></blockquote></div>

<h3 class="section">4.6 Stringprep Profile Macros</h3>

<div class="defun">
&mdash; Function: int <b>stringprep_nameprep_no_unassigned</b> (<var>char * in, int maxlen</var>)<var><a name="index-stringprep_005fnameprep_005fno_005funassigned-62"></a></var><br>
<blockquote>
<p><var>in</var>: input/ouput array with string to prepare.

        <p><var>maxlen</var>: maximum length of input/output array.

        <p>Prepare the input UTF-8 string according to the nameprep profile.  The
AllowUnassigned flag is false, use <code>stringprep_nameprep</code> for
true AllowUnassigned.  Returns 0 iff successful, or an error code. 
</p></blockquote></div>

<div class="defun">
&mdash; Function: int <b>stringprep_iscsi</b> (<var>char * in, int maxlen</var>)<var><a name="index-stringprep_005fiscsi-63"></a></var><br>
<blockquote>
<p><var>in</var>: input/ouput array with string to prepare.

        <p><var>maxlen</var>: maximum length of input/output array.

        <p>Prepare the input UTF-8 string according to the draft iSCSI stringprep
profile.  Returns 0 iff successful, or an error code. 
</p></blockquote></div>

<div class="defun">
&mdash; Function: int <b>stringprep_plain</b> (<var>char * in, int maxlen</var>)<var><a name="index-stringprep_005fplain-64"></a></var><br>
<blockquote>
<p><var>in</var>: input/ouput array with string to prepare.

        <p><var>maxlen</var>: maximum length of input/output array.

        <p>Prepare the input UTF-8 string according to the draft SASL ANONYMOUS
profile.  Returns 0 iff successful, or an error code. 
</p></blockquote></div>

<div class="defun">
&mdash; Function: int <b>stringprep_xmpp_nodeprep</b> (<var>char * in, int maxlen</var>)<var><a name="index-stringprep_005fxmpp_005fnodeprep-65"></a></var><br>
<blockquote>
<p><var>in</var>: input/ouput array with string to prepare.

        <p><var>maxlen</var>: maximum length of input/output array.

        <p>Prepare the input UTF-8 string according to the draft XMPP node
identifier profile.  Returns 0 iff successful, or an error code. 
</p></blockquote></div>

<div class="defun">
&mdash; Function: int <b>stringprep_xmpp_resourceprep</b> (<var>char * in, int maxlen</var>)<var><a name="index-stringprep_005fxmpp_005fresourceprep-66"></a></var><br>
<blockquote>
<p><var>in</var>: input/ouput array with string to prepare.

        <p><var>maxlen</var>: maximum length of input/output array.

        <p>Prepare the input UTF-8 string according to the draft XMPP resource
identifier profile.  Returns 0 iff successful, or an error code. 
</p></blockquote></div>

<!-- ********************************************************** -->
<!-- *******************  Punycode Functions ****************** -->
<!-- ********************************************************** -->
<div class="node">
<p><hr>
<a name="Punycode-Functions"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#IDNA-Functions">IDNA Functions</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Stringprep-Functions">Stringprep Functions</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="chapter">5 Punycode Functions</h2>

<p><a name="index-Punycode-Functions-67"></a>
Punycode is a simple and efficient transfer encoding syntax designed
for use with Internationalized Domain Names in Applications. It
uniquely and reversibly transforms a Unicode string into an ASCII
string. ASCII characters in the Unicode string are represented
literally, and non-ASCII characters are represented by ASCII
characters that are allowed in host name labels (letters, digits, and
hyphens). A general algorithm called Bootstring allows a string of
basic code points to uniquely represent any string of code points
drawn from a larger set. Punycode is an instance of Bootstring that
uses particular parameter values, appropriate for IDNA.

<h3 class="section">5.1 Header file <code>punycode.h</code></h3>

<p>To use the functions explained in this chapter, you need to include
the file <samp><span class="file">punycode.h</span></samp> using:

<pre class="example">     #include &lt;punycode.h&gt;
</pre>
   <h3 class="section">5.2 Unicode Code Point Data Type</h3>

<p>The punycode function uses a special type to denote Unicode code
points.  It is guaranteed to always be a 32 bit unsigned integer.

<div class="defun">
&mdash; Punycode Unicode code point: uint32_t <b>punycode_uint</b><var><a name="index-punycode_005fuint-68"></a></var><br>
<blockquote><p>A unsigned integer that hold Unicode code points. 
</p></blockquote></div>

<h3 class="section">5.3 Core Functions</h3>

<p>Note that the current implementation will fail if the
<code>input_length</code> exceed 4294967295 (the size of
<code>punycode_uint</code>).  This restriction may be removed in the future. 
Meanwhile applications are encouraged to not depend on this problem,
and use <code>sizeof</code> to initialize <code>input_length</code> and
<code>output_length</code>.

   <p>The functions provided are the following two entry points:

<h4 class="subheading">punycode_encode</h4>

<p><a name="punycode_005fencode"></a>

<div class="defun">
&mdash; Function: int <b>punycode_encode</b> (<var>size_t input_length, const punycode_uint </var>[]<var> input, const unsigned char </var>[]<var> case_flags, size_t * output_length, char </var>[]<var> output</var>)<var><a name="index-punycode_005fencode-69"></a></var><br>
<blockquote><p><var>input_length</var>: The number of code points in the <code>input</code> array and
the number of flags in the <code>case_flags</code> array.

        <p><var>input</var>: An array of code points.  They are presumed to be Unicode
code points, but that is not strictly REQUIRED.  The array
contains code points, not code units.  UTF-16 uses code units
D800 through DFFF to refer to code points 10000..10FFFF.  The
code points D800..DFFF do not occur in any valid Unicode string. 
The code points that can occur in Unicode strings (0..D7FF and
E000..10FFFF) are also called Unicode scalar values.

        <p><var>case_flags</var>: A <code>NULL</code> pointer or an array of boolean values parallel
to the <code>input</code> array.  Nonzero (true, flagged) suggests that the
corresponding Unicode character be forced to uppercase after
being decoded (if possible), and zero (false, unflagged) suggests
that it be forced to lowercase (if possible).  ASCII code points
(0..7F) are encoded literally, except that ASCII letters are
forced to uppercase or lowercase according to the corresponding
case flags.  If <code>case_flags</code> is a <code>NULL</code> pointer then ASCII letters
are left as they are, and other code points are treated as
unflagged.

        <p><var>output_length</var>: The caller passes in the maximum number of ASCII
code points that it can receive.  On successful return it will
contain the number of ASCII code points actually output.

        <p><var>output</var>: An array of ASCII code points.  It is *not*
null-terminated; it will contain zeros if and only if the <code>input</code>
contains zeros.  (Of course the caller can leave room for a
terminator and add one if needed.)

        <p>Converts a sequence of code points (presumed to be Unicode code
points) to Punycode.

        <p><strong>Return value:</strong> The return value can be any of the <code>Punycode_status</code>
values defined above except <code>PUNYCODE_BAD_INPUT</code>.  If not
<code>PUNYCODE_SUCCESS</code>, then <code>output_size</code> and <code>output</code> might contain
garbage. 
</p></blockquote></div>

<h4 class="subheading">punycode_decode</h4>

<p><a name="punycode_005fdecode"></a>

<div class="defun">
&mdash; Function: int <b>punycode_decode</b> (<var>size_t input_length, const char </var>[]<var> input, size_t * output_length, punycode_uint </var>[]<var> output, unsigned char </var>[]<var> case_flags</var>)<var><a name="index-punycode_005fdecode-70"></a></var><br>
<blockquote><p><var>input_length</var>: The number of ASCII code points in the <code>input</code> array.

        <p><var>input</var>: An array of ASCII code points (0..7F).

        <p><var>output_length</var>: The caller passes in the maximum number of code
points that it can receive into the <code>output</code> array (which is also
the maximum number of flags that it can receive into the
<code>case_flags</code> array, if <code>case_flags</code> is not a <code>NULL</code> pointer).  On
successful return it will contain the number of code points
actually output (which is also the number of flags actually
output, if case_flags is not a null pointer).  The decoder will
never need to output more code points than the number of ASCII
code points in the input, because of the way the encoding is
defined.  The number of code points output cannot exceed the
maximum possible value of a punycode_uint, even if the supplied
<code>output_length</code> is greater than that.

        <p><var>output</var>: An array of code points like the input argument of
<code>punycode_encode()</code> (see above).

        <p><var>case_flags</var>: A <code>NULL</code> pointer (if the flags are not needed by the
caller) or an array of boolean values parallel to the <code>output</code>
array.  Nonzero (true, flagged) suggests that the corresponding
Unicode character be forced to uppercase by the caller (if
possible), and zero (false, unflagged) suggests that it be forced
to lowercase (if possible).  ASCII code points (0..7F) are output
already in the proper case, but their flags will be set
appropriately so that applying the flags would be harmless.

        <p>Converts Punycode to a sequence of code points (presumed to be
Unicode code points).

        <p><strong>Return value:</strong> The return value can be any of the <code>Punycode_status</code>
values defined above.  If not <code>PUNYCODE_SUCCESS</code>, then
<code>output_length</code>, <code>output</code>, and <code>case_flags</code> might contain garbage. 
</p></blockquote></div>

<h3 class="section">5.4 Error Handling</h3>

<h4 class="subheading">punycode_strerror</h4>

<p><a name="punycode_005fstrerror"></a>

<div class="defun">
&mdash; Function: const char * <b>punycode_strerror</b> (<var>Punycode_status rc</var>)<var><a name="index-punycode_005fstrerror-71"></a></var><br>
<blockquote><p><var>rc</var>: an <code>Punycode_status</code> return code.

        <p>Convert a return code integer to a text string.  This string can be
used to output a diagnostic message to the user.

        <p><strong>PUNYCODE_SUCCESS:</strong> Successful operation.  This value is guaranteed
to always be zero, the remaining ones are only guaranteed to hold
non-zero values, for logical comparison purposes.

        <p><strong>PUNYCODE_BAD_INPUT:</strong> Input is invalid.

        <p><strong>PUNYCODE_BIG_OUTPUT:</strong> Output would exceed the space provided.

        <p><strong>PUNYCODE_OVERFLOW:</strong> Input needs wider integers to process.

        <p><strong>Return value:</strong> Returns a pointer to a statically allocated string
containing a description of the error with the return code <code>rc</code>. 
</p></blockquote></div>

<!-- ********************************************************** -->
<!-- ********************* IDNA Functions ********************* -->
<!-- ********************************************************** -->
<div class="node">
<p><hr>
<a name="IDNA-Functions"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#TLD-Functions">TLD Functions</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Punycode-Functions">Punycode Functions</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="chapter">6 IDNA Functions</h2>

<p><a name="index-IDNA-Functions-72"></a>
Until now, there has been no standard method for domain names to use
characters outside the ASCII repertoire. The IDNA document defines
internationalized domain names (IDNs) and a mechanism called IDNA for
handling them in a standard fashion. IDNs use characters drawn from a
large repertoire (Unicode), but IDNA allows the non-ASCII characters
to be represented using only the ASCII characters already allowed in
so-called host names today. This backward-compatible representation is
required in existing protocols like DNS, so that IDNs can be
introduced with no changes to the existing infrastructure. IDNA is
only meant for processing domain names, not free text.

<h3 class="section">6.1 Header file <code>idna.h</code></h3>

<p>To use the functions explained in this chapter, you need to include
the file <samp><span class="file">idna.h</span></samp> using:

<pre class="example">     #include &lt;idna.h&gt;
</pre>
   <h3 class="section">6.2 Control Flags</h3>

<p>The IDNA <code>flags</code> parameter can take on the following values, or a
bit-wise inclusive or of any subset of the parameters:

<div class="defun">
&mdash; Return code: Idna_flags <b>IDNA_ALLOW_UNASSIGNED</b><var><a name="index-IDNA_005fALLOW_005fUNASSIGNED-73"></a></var><br>
<blockquote><p>Allow unassigned Unicode code points. 
</p></blockquote></div>

<div class="defun">
&mdash; Return code: Idna_flags <b>IDNA_USE_STD3_ASCII_RULES</b><var><a name="index-IDNA_005fUSE_005fSTD3_005fASCII_005fRULES-74"></a></var><br>
<blockquote><p>Check output to make sure it is a STD3 conforming host name. 
</p></blockquote></div>

<h3 class="section">6.3 Prefix String</h3>

<div class="defun">
&mdash; Macro: #define <b>IDNA_ACE_PREFIX</b><var><a name="index-IDNA_005fACE_005fPREFIX-75"></a></var><br>
<blockquote><p>String with the official IDNA prefix, <code>xn--</code>. 
</p></blockquote></div>

<h3 class="section">6.4 Core Functions</h3>

<p>The idea behind the IDNA function names are as follows: the
<code>idna_to_ascii_4i</code> and <code>idna_to_unicode_44i</code> functions are
the core IDNA primitives.  The <code>4</code> indicate that the function
takes UCS-4 strings (i.e., Unicode code points encoded in a 32-bit
unsigned integer type) of the specified length.  The <code>i</code> indicate
that the data is written &ldquo;inline&rdquo; into the buffer.  This means the
caller is responsible for allocating (and deallocating) the string,
and providing the library with the allocated length of the string. 
The output length is written in the output length variable.  The
remaining functions all contain the <code>z</code> indicator, which means
the strings are zero terminated.  All output strings are allocated by
the library, and must be deallocated by the caller.  The <code>4</code>
indicator again means that the string is UCS-4, the <code>8</code> means the
strings are UTF-8 and the <code>l</code> indicator means the strings are
encoded in the encoding used by the current locale.

   <p>The functions provided are the following entry points:

<h4 class="subheading">idna_to_ascii_4i</h4>

<p><a name="idna_005fto_005fascii_005f4i"></a>

<div class="defun">
&mdash; Function: int <b>idna_to_ascii_4i</b> (<var>const uint32_t * in, size_t inlen, char * out, int flags</var>)<var><a name="index-idna_005fto_005fascii_005f4i-76"></a></var><br>
<blockquote><p><var>in</var>: input array with unicode code points.

        <p><var>inlen</var>: length of input array with unicode code points.

        <p><var>out</var>: output zero terminated string that must have room for at
least 63 characters plus the terminating zero.

        <p><var>flags</var>: an <code>Idna_flags</code> value, e.g., <code>IDNA_ALLOW_UNASSIGNED</code> or
<code>IDNA_USE_STD3_ASCII_RULES</code>.

        <p>The ToASCII operation takes a sequence of Unicode code points that make
up one label and transforms it into a sequence of code points in the
ASCII range (0..7F). If ToASCII succeeds, the original sequence and the
resulting sequence are equivalent labels.

        <p>It is important to note that the ToASCII operation can fail. ToASCII
fails if any step of it fails. If any step of the ToASCII operation
fails on any label in a domain name, that domain name MUST NOT be used
as an internationalized domain name. The method for deadling with this
failure is application-specific.

        <p>The inputs to ToASCII are a sequence of code points, the AllowUnassigned
flag, and the UseSTD3ASCIIRules flag. The output of ToASCII is either a
sequence of ASCII code points or a failure condition.

        <p>ToASCII never alters a sequence of code points that are all in the ASCII
range to begin with (although it could fail). Applying the ToASCII
operation multiple times has exactly the same effect as applying it just
once.

        <p><strong>Return value:</strong> Returns 0 on success, or an <code>Idna_rc</code> error code. 
</p></blockquote></div>

<h4 class="subheading">idna_to_unicode_44i</h4>

<p><a name="idna_005fto_005funicode_005f44i"></a>

<div class="defun">
&mdash; Function: int <b>idna_to_unicode_44i</b> (<var>const uint32_t * in, size_t inlen, uint32_t * out, size_t * outlen, int flags</var>)<var><a name="index-idna_005fto_005funicode_005f44i-77"></a></var><br>
<blockquote><p><var>in</var>: input array with unicode code points.

        <p><var>inlen</var>: length of input array with unicode code points.

        <p><var>out</var>: output array with unicode code points.

        <p><var>outlen</var>: on input, maximum size of output array with unicode code points,
on exit, actual size of output array with unicode code points.

        <p><var>flags</var>: an <code>Idna_flags</code> value, e.g., <code>IDNA_ALLOW_UNASSIGNED</code> or
<code>IDNA_USE_STD3_ASCII_RULES</code>.

        <p>The ToUnicode operation takes a sequence of Unicode code points
that make up one label and returns a sequence of Unicode code
points. If the input sequence is a label in ACE form, then the
result is an equivalent internationalized label that is not in ACE
form, otherwise the original sequence is returned unaltered.

        <p>ToUnicode never fails. If any step fails, then the original input
sequence is returned immediately in that step.

        <p>The Punycode decoder can never output more code points than it
inputs, but Nameprep can, and therefore ToUnicode can.  Note that
the number of octets needed to represent a sequence of code points
depends on the particular character encoding used.

        <p>The inputs to ToUnicode are a sequence of code points, the
AllowUnassigned flag, and the UseSTD3ASCIIRules flag. The output of
ToUnicode is always a sequence of Unicode code points.

        <p><strong>Return value:</strong> Returns <code>Idna_rc</code> error condition, but it must only be
used for debugging purposes.  The output buffer is always
guaranteed to contain the correct data according to the
specification (sans malloc induced errors).  NB!  This means that
you normally ignore the return code from this function, as
checking it means breaking the standard. 
</p></blockquote></div>

<h3 class="section">6.5 Simplified ToASCII Interface</h3>

<h4 class="subheading">idna_to_ascii_4z</h4>

<p><a name="idna_005fto_005fascii_005f4z"></a>

<div class="defun">
&mdash; Function: int <b>idna_to_ascii_4z</b> (<var>const uint32_t * input, char ** output, int flags</var>)<var><a name="index-idna_005fto_005fascii_005f4z-78"></a></var><br>
<blockquote><p><var>input</var>: zero terminated input Unicode string.

        <p><var>output</var>: pointer to newly allocated output string.

        <p><var>flags</var>: an <code>Idna_flags</code> value, e.g., <code>IDNA_ALLOW_UNASSIGNED</code> or
<code>IDNA_USE_STD3_ASCII_RULES</code>.

        <p>Convert UCS-4 domain name to ASCII string.  The domain name may
contain several labels, separated by dots.  The output buffer must
be deallocated by the caller.

        <p><strong>Return value:</strong> Returns <code>IDNA_SUCCESS</code> on success, or error code. 
</p></blockquote></div>

<h4 class="subheading">idna_to_ascii_8z</h4>

<p><a name="idna_005fto_005fascii_005f8z"></a>

<div class="defun">
&mdash; Function: int <b>idna_to_ascii_8z</b> (<var>const char * input, char ** output, int flags</var>)<var><a name="index-idna_005fto_005fascii_005f8z-79"></a></var><br>
<blockquote><p><var>input</var>: zero terminated input UTF-8 string.

        <p><var>output</var>: pointer to newly allocated output string.

        <p><var>flags</var>: an <code>Idna_flags</code> value, e.g., <code>IDNA_ALLOW_UNASSIGNED</code> or
<code>IDNA_USE_STD3_ASCII_RULES</code>.

        <p>Convert UTF-8 domain name to ASCII string.  The domain name may
contain several labels, separated by dots.  The output buffer must
be deallocated by the caller.

        <p><strong>Return value:</strong> Returns <code>IDNA_SUCCESS</code> on success, or error code. 
</p></blockquote></div>

<h4 class="subheading">idna_to_ascii_lz</h4>

<p><a name="idna_005fto_005fascii_005flz"></a>

<div class="defun">
&mdash; Function: int <b>idna_to_ascii_lz</b> (<var>const char * input, char ** output, int flags</var>)<var><a name="index-idna_005fto_005fascii_005flz-80"></a></var><br>
<blockquote><p><var>input</var>: zero terminated input string encoded in the current locale's
character set.

        <p><var>output</var>: pointer to newly allocated output string.

        <p><var>flags</var>: an <code>Idna_flags</code> value, e.g., <code>IDNA_ALLOW_UNASSIGNED</code> or
<code>IDNA_USE_STD3_ASCII_RULES</code>.

        <p>Convert domain name in the locale's encoding to ASCII string.  The
domain name may contain several labels, separated by dots.  The
output buffer must be deallocated by the caller.

        <p><strong>Return value:</strong> Returns <code>IDNA_SUCCESS</code> on success, or error code. 
</p></blockquote></div>

<h3 class="section">6.6 Simplified ToUnicode Interface</h3>

<h4 class="subheading">idna_to_unicode_4z4z</h4>

<p><a name="idna_005fto_005funicode_005f4z4z"></a>

<div class="defun">
&mdash; Function: int <b>idna_to_unicode_4z4z</b> (<var>const uint32_t * input, uint32_t ** output, int flags</var>)<var><a name="index-idna_005fto_005funicode_005f4z4z-81"></a></var><br>
<blockquote><p><var>input</var>: zero-terminated Unicode string.

        <p><var>output</var>: pointer to newly allocated output Unicode string.

        <p><var>flags</var>: an <code>Idna_flags</code> value, e.g., <code>IDNA_ALLOW_UNASSIGNED</code> or
<code>IDNA_USE_STD3_ASCII_RULES</code>.

        <p>Convert possibly ACE encoded domain name in UCS-4 format into a
UCS-4 string.  The domain name may contain several labels,
separated by dots.  The output buffer must be deallocated by the
caller.

        <p><strong>Return value:</strong> Returns <code>IDNA_SUCCESS</code> on success, or error code. 
</p></blockquote></div>

<h4 class="subheading">idna_to_unicode_8z4z</h4>

<p><a name="idna_005fto_005funicode_005f8z4z"></a>

<div class="defun">
&mdash; Function: int <b>idna_to_unicode_8z4z</b> (<var>const char * input, uint32_t ** output, int flags</var>)<var><a name="index-idna_005fto_005funicode_005f8z4z-82"></a></var><br>
<blockquote><p><var>input</var>: zero-terminated UTF-8 string.

        <p><var>output</var>: pointer to newly allocated output Unicode string.

        <p><var>flags</var>: an <code>Idna_flags</code> value, e.g., <code>IDNA_ALLOW_UNASSIGNED</code> or
<code>IDNA_USE_STD3_ASCII_RULES</code>.

        <p>Convert possibly ACE encoded domain name in UTF-8 format into a
UCS-4 string.  The domain name may contain several labels,
separated by dots.  The output buffer must be deallocated by the
caller.

        <p><strong>Return value:</strong> Returns <code>IDNA_SUCCESS</code> on success, or error code. 
</p></blockquote></div>

<h4 class="subheading">idna_to_unicode_8z8z</h4>

<p><a name="idna_005fto_005funicode_005f8z8z"></a>

<div class="defun">
&mdash; Function: int <b>idna_to_unicode_8z8z</b> (<var>const char * input, char ** output, int flags</var>)<var><a name="index-idna_005fto_005funicode_005f8z8z-83"></a></var><br>
<blockquote><p><var>input</var>: zero-terminated UTF-8 string.

        <p><var>output</var>: pointer to newly allocated output UTF-8 string.

        <p><var>flags</var>: an <code>Idna_flags</code> value, e.g., <code>IDNA_ALLOW_UNASSIGNED</code> or
<code>IDNA_USE_STD3_ASCII_RULES</code>.

        <p>Convert possibly ACE encoded domain name in UTF-8 format into a
UTF-8 string.  The domain name may contain several labels,
separated by dots.  The output buffer must be deallocated by the
caller.

        <p><strong>Return value:</strong> Returns <code>IDNA_SUCCESS</code> on success, or error code. 
</p></blockquote></div>

<h4 class="subheading">idna_to_unicode_8zlz</h4>

<p><a name="idna_005fto_005funicode_005f8zlz"></a>

<div class="defun">
&mdash; Function: int <b>idna_to_unicode_8zlz</b> (<var>const char * input, char ** output, int flags</var>)<var><a name="index-idna_005fto_005funicode_005f8zlz-84"></a></var><br>
<blockquote><p><var>input</var>: zero-terminated UTF-8 string.

        <p><var>output</var>: pointer to newly allocated output string encoded in the
current locale's character set.

        <p><var>flags</var>: an <code>Idna_flags</code> value, e.g., <code>IDNA_ALLOW_UNASSIGNED</code> or
<code>IDNA_USE_STD3_ASCII_RULES</code>.

        <p>Convert possibly ACE encoded domain name in UTF-8 format into a
string encoded in the current locale's character set.  The domain
name may contain several labels, separated by dots.  The output
buffer must be deallocated by the caller.

        <p><strong>Return value:</strong> Returns <code>IDNA_SUCCESS</code> on success, or error code. 
</p></blockquote></div>

<h4 class="subheading">idna_to_unicode_lzlz</h4>

<p><a name="idna_005fto_005funicode_005flzlz"></a>

<div class="defun">
&mdash; Function: int <b>idna_to_unicode_lzlz</b> (<var>const char * input, char ** output, int flags</var>)<var><a name="index-idna_005fto_005funicode_005flzlz-85"></a></var><br>
<blockquote><p><var>input</var>: zero-terminated string encoded in the current locale's
character set.

        <p><var>output</var>: pointer to newly allocated output string encoded in the
current locale's character set.

        <p><var>flags</var>: an <code>Idna_flags</code> value, e.g., <code>IDNA_ALLOW_UNASSIGNED</code> or
<code>IDNA_USE_STD3_ASCII_RULES</code>.

        <p>Convert possibly ACE encoded domain name in the locale's character
set into a string encoded in the current locale's character set. 
The domain name may contain several labels, separated by dots.  The
output buffer must be deallocated by the caller.

        <p><strong>Return value:</strong> Returns <code>IDNA_SUCCESS</code> on success, or error code. 
</p></blockquote></div>

<h3 class="section">6.7 Error Handling</h3>

<h4 class="subheading">idna_strerror</h4>

<p><a name="idna_005fstrerror"></a>

<div class="defun">
&mdash; Function: const char * <b>idna_strerror</b> (<var>Idna_rc rc</var>)<var><a name="index-idna_005fstrerror-86"></a></var><br>
<blockquote><p><var>rc</var>: an <code>Idna_rc</code> return code.

        <p>Convert a return code integer to a text string.  This string can be
used to output a diagnostic message to the user.

        <p><strong>IDNA_SUCCESS:</strong> Successful operation.  This value is guaranteed to
always be zero, the remaining ones are only guaranteed to hold
non-zero values, for logical comparison purposes.

        <p><strong>IDNA_STRINGPREP_ERROR:</strong> Error during string preparation.

        <p><strong>IDNA_PUNYCODE_ERROR:</strong> Error during punycode operation.

        <p><strong>IDNA_CONTAINS_NON_LDH:</strong> For IDNA_USE_STD3_ASCII_RULES, indicate that
the string contains non-LDH ASCII characters.

        <p><strong>IDNA_CONTAINS_MINUS:</strong> For IDNA_USE_STD3_ASCII_RULES, indicate that
the string contains a leading or trailing hyphen-minus (U+002D).

        <p><strong>IDNA_INVALID_LENGTH:</strong> The final output string is not within the
(inclusive) range 1 to 63 characters.

        <p><strong>IDNA_NO_ACE_PREFIX:</strong> The string does not contain the ACE prefix
(for ToUnicode).

        <p><strong>IDNA_ROUNDTRIP_VERIFY_ERROR:</strong> The ToASCII operation on output
string does not equal the input.

        <p><strong>IDNA_CONTAINS_ACE_PREFIX:</strong> The input contains the ACE prefix (for
ToASCII).

        <p><strong>IDNA_ICONV_ERROR:</strong> Could not convert string in locale encoding.

        <p><strong>IDNA_MALLOC_ERROR:</strong> Could not allocate buffer (this is typically a
fatal error).

        <p><strong>IDNA_DLOPEN_ERROR:</strong> Could not dlopen the libcidn DSO (only used
internally in libc).

        <p><strong>Return value:</strong> Returns a pointer to a statically allocated string
containing a description of the error with the return code <code>rc</code>. 
</p></blockquote></div>

<!-- ********************************************************** -->
<!-- ********************** TLD Functions ********************* -->
<!-- ********************************************************** -->
<div class="node">
<p><hr>
<a name="TLD-Functions"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#PR29-Functions">PR29 Functions</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#IDNA-Functions">IDNA Functions</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="chapter">7 TLD Functions</h2>

<p><a name="index-TLD-Functions-87"></a>
Organizations that manage some Top Level Domains (<acronym>TLD</acronym>s) have
published tables with characters they accept within the domain.  The
reason may be to reduce complexity that come from using the full
Unicode range, and to protect themselves from future (backwards
incompatible) changes in the IDN or Unicode specifications.  Libidn
implement an infrastructure for defining and checking strings against
such tables.  Libidn also ship some tables from <acronym>TLD</acronym>s that we
have managed to get permission to use them from.  Because these tables
are even less static than Unicode or StringPrep tables, it is likely
that they will be updated from time to time (even in backwards
incompatibe ways).  The Libidn interface provide a &ldquo;version&rdquo; field
for each <acronym>TLD</acronym> table, which can be compared for equality to
guarantee the same operation over time.

   <p>From a design point of view, you can regard the <acronym>TLD</acronym> tables
for IDN as the &ldquo;localization&rdquo; step that come after the
&ldquo;internationalization&rdquo; step provided by the IETF standards.

   <p>The TLD functionality rely on up-to-date tables.  The latest version
of Libidn aim to provide these, but tables with unclear copying
conditions, or generally experimental tables, are not included.  Some
such tables can be found at <a href="http://tldchk.berlios.de">http://tldchk.berlios.de</a>.

<h3 class="section">7.1 Header file <code>tld.h</code></h3>

<p>To use the functions explained in this chapter, you need to include
the file <samp><span class="file">tld.h</span></samp> using:

<pre class="example">     #include &lt;tld.h&gt;
</pre>
   <!-- @section Data Types -->
<!-- @deftp {Data type} {Tld_table_element} @var{start} @var{end} -->
<!-- @example -->
<!-- /* Interval of valid code points in the TLD. */ -->
<!-- struct Tld_table_element -->
<!-- @{ -->
<!-- uint32_t start;		/* Start of range. */ -->
<!-- uint32_t end;		/* End of range, end == start if single. */ -->
<!-- @}; -->
<!-- typedef struct Tld_table_element Tld_table_element; -->
<!-- @end example -->
<!-- This @code{struct} contain the @var{start} and @var{end} positions -->
<!-- (inclusive) of a range.  If the range is a single (i.e., starts and -->
<!-- ends in the same character), then set @var{end} to the same as -->
<!-- @var{start}.  This structure is normally used as an array. -->
<!-- @end deftp -->
<!-- @deftp {Data type} {Tld_table} @var{name} @var{version} @var{nvalid} @var{valid} -->
<!-- @example -->
<!-- /* List valid code points in a TLD. */ -->
<!-- struct Tld_table -->
<!-- @{ -->
<!-- char *name;			/* TLD name, e.g., "no". */ -->
<!-- char *version;		/* Version string from TLD file. */ -->
<!-- size_t nvalid;		/* Number of entries in data. */ -->
<!-- Tld_table_element *valid[];	/* Sorted array of valid code points. */ -->
<!-- @}; -->
<!-- typedef struct Tld_table Tld_table; -->
<!-- @end example -->
<!-- In this @code{struct}, the @var{name} field is a string (@samp{char*}) -->
<!-- indicating the TLD name (e.g., ``no'').  The @var{version} field is a -->
<!-- string (@samp{char*}) containing a free form humanly readable string -->
<!-- that can be used for equality comparison to compare different versions -->
<!-- of the table.  The @var{nvalid} field indicate how many entries there -->
<!-- are in @var{valid}, which brings us finally to @var{valid} that -->
<!-- contain the actual code points that are valid for this TLD (see -->
<!-- @code{Tld_table_element} above). -->
<!-- @end deftp -->
<h3 class="section">7.2 Core Functions</h3>

<h4 class="subheading">tld_check_4t</h4>

<p><a name="tld_005fcheck_005f4t"></a>

<div class="defun">
&mdash; Function: int <b>tld_check_4t</b> (<var>const uint32_t * in, size_t inlen, size_t * errpos, const Tld_table * tld</var>)<var><a name="index-tld_005fcheck_005f4t-88"></a></var><br>
<blockquote><p><var>in</var>: Array of unicode code points to process. Does not need to be
zero terminated.

        <p><var>inlen</var>: Number of unicode code points.

        <p><var>errpos</var>: Position of offending character is returned here.

        <p><var>tld</var>: A <code>Tld_table</code> data structure representing the restrictions for
which the input should be tested.

        <p>Test each of the code points in <code>in</code> for whether or not
they are allowed by the data structure in <code>tld</code>, return
the position of the first character for which this is not
the case in <code>errpos</code>.

        <p><strong>Return value:</strong> Returns the <code>Tld_rc</code> value <code>TLD_SUCCESS</code> if all code
points are valid or when <code>tld</code> is null, <code>TLD_INVALID</code> if a
character is not allowed, or additional error codes on general
failure conditions. 
</p></blockquote></div>

<h4 class="subheading">tld_check_4tz</h4>

<p><a name="tld_005fcheck_005f4tz"></a>

<div class="defun">
&mdash; Function: int <b>tld_check_4tz</b> (<var>const uint32_t * in, size_t * errpos, const Tld_table * tld</var>)<var><a name="index-tld_005fcheck_005f4tz-89"></a></var><br>
<blockquote><p><var>in</var>: Zero terminated array of unicode code points to process.

        <p><var>errpos</var>: Position of offending character is returned here.

        <p><var>tld</var>: A <code>Tld_table</code> data structure representing the restrictions for
which the input should be tested.

        <p>Test each of the code points in <code>in</code> for whether or not
they are allowed by the data structure in <code>tld</code>, return
the position of the first character for which this is not
the case in <code>errpos</code>.

        <p><strong>Return value:</strong> Returns the <code>Tld_rc</code> value <code>TLD_SUCCESS</code> if all code
points are valid or when <code>tld</code> is null, <code>TLD_INVALID</code> if a
character is not allowed, or additional error codes on general
failure conditions. 
</p></blockquote></div>

<h3 class="section">7.3 Utility Functions</h3>

<h4 class="subheading">tld_get_4</h4>

<p><a name="tld_005fget_005f4"></a>

<div class="defun">
&mdash; Function: int <b>tld_get_4</b> (<var>const uint32_t * in, size_t inlen, char ** out</var>)<var><a name="index-tld_005fget_005f4-90"></a></var><br>
<blockquote><p><var>in</var>: Array of unicode code points to process. Does not need to be
zero terminated.

        <p><var>inlen</var>: Number of unicode code points.

        <p><var>out</var>: Zero terminated ascii result string pointer.

        <p>Isolate the top-level domain of <code>in</code> and return it as an ASCII
string in <code>out</code>.

        <p><strong>Return value:</strong> Return <code>TLD_SUCCESS</code> on success, or the corresponding
<code>Tld_rc</code> error code otherwise. 
</p></blockquote></div>

<h4 class="subheading">tld_get_4z</h4>

<p><a name="tld_005fget_005f4z"></a>

<div class="defun">
&mdash; Function: int <b>tld_get_4z</b> (<var>const uint32_t * in, char ** out</var>)<var><a name="index-tld_005fget_005f4z-91"></a></var><br>
<blockquote><p><var>in</var>: Zero terminated array of unicode code points to process.

        <p><var>out</var>: Zero terminated ascii result string pointer.

        <p>Isolate the top-level domain of <code>in</code> and return it as an ASCII
string in <code>out</code>.

        <p><strong>Return value:</strong> Return <code>TLD_SUCCESS</code> on success, or the corresponding
<code>Tld_rc</code> error code otherwise. 
</p></blockquote></div>

<h4 class="subheading">tld_get_z</h4>

<p><a name="tld_005fget_005fz"></a>

<div class="defun">
&mdash; Function: int <b>tld_get_z</b> (<var>const char * in, char ** out</var>)<var><a name="index-tld_005fget_005fz-92"></a></var><br>
<blockquote><p><var>in</var>: Zero terminated character array to process.

        <p><var>out</var>: Zero terminated ascii result string pointer.

        <p>Isolate the top-level domain of <code>in</code> and return it as an ASCII
string in <code>out</code>.  The input string <code>in</code> may be UTF-8, ISO-8859-1 or
any ASCII compatible character encoding.

        <p><strong>Return value:</strong> Return <code>TLD_SUCCESS</code> on success, or the corresponding
<code>Tld_rc</code> error code otherwise. 
</p></blockquote></div>

<h4 class="subheading">tld_get_table</h4>

<p><a name="tld_005fget_005ftable"></a>

<div class="defun">
&mdash; Function: const Tld_table * <b>tld_get_table</b> (<var>const char * tld, const Tld_table ** tables</var>)<var><a name="index-tld_005fget_005ftable-93"></a></var><br>
<blockquote><p><var>tld</var>: TLD name (e.g. "com") as zero terminated ASCII byte string.

        <p><var>tables</var>: Zero terminated array of <code>Tld_table</code> info-structures for
TLDs.

        <p>Get the TLD table for a named TLD by searching through the given
TLD table array.

        <p><strong>Return value:</strong> Return structure corresponding to TLD <code>tld</code> by going
thru <code>tables</code>, or return <code>NULL</code> if no such structure is found. 
</p></blockquote></div>

<h4 class="subheading">tld_default_table</h4>

<p><a name="tld_005fdefault_005ftable"></a>

<div class="defun">
&mdash; Function: const Tld_table * <b>tld_default_table</b> (<var>const char * tld, const Tld_table ** overrides</var>)<var><a name="index-tld_005fdefault_005ftable-94"></a></var><br>
<blockquote><p><var>tld</var>: TLD name (e.g. "com") as zero terminated ASCII byte string.

        <p><var>overrides</var>: Additional zero terminated array of <code>Tld_table</code>
info-structures for TLDs, or <code>NULL</code> to only use library deault
tables.

        <p>Get the TLD table for a named TLD, using the internal defaults,
possibly overrided by the (optional) supplied tables.

        <p><strong>Return value:</strong> Return structure corresponding to TLD <code>tld_str</code>, first
looking through <code>overrides</code> then thru built-in list, or <code>NULL</code> if
no such structure found. 
</p></blockquote></div>

<h3 class="section">7.4 High-Level Wrapper Functions</h3>

<h4 class="subheading">tld_check_4</h4>

<p><a name="tld_005fcheck_005f4"></a>

<div class="defun">
&mdash; Function: int <b>tld_check_4</b> (<var>const uint32_t * in, size_t inlen, size_t * errpos, const Tld_table ** overrides</var>)<var><a name="index-tld_005fcheck_005f4-95"></a></var><br>
<blockquote><p><var>in</var>: Array of unicode code points to process. Does not need to be
zero terminated.

        <p><var>inlen</var>: Number of unicode code points.

        <p><var>errpos</var>: Position of offending character is returned here.

        <p><var>overrides</var>: A <code>Tld_table</code> array of additional domain restriction
structures that complement and supersede the built-in information.

        <p>Test each of the code points in <code>in</code> for whether or not they are
allowed by the information in <code>overrides</code> or by the built-in TLD
restriction data. When data for the same TLD is available both
internally and in <code>overrides</code>, the information in <code>overrides</code> takes
precedence. If several entries for a specific TLD are found, the
first one is used.  If <code>overrides</code> is <code>NULL</code>, only the built-in
information is used.  The position of the first offending character
is returned in <code>errpos</code>.

        <p><strong>Return value:</strong> Returns the <code>Tld_rc</code> value <code>TLD_SUCCESS</code> if all code
points are valid or when <code>tld</code> is null, <code>TLD_INVALID</code> if a
character is not allowed, or additional error codes on general
failure conditions. 
</p></blockquote></div>

<h4 class="subheading">tld_check_4z</h4>

<p><a name="tld_005fcheck_005f4z"></a>

<div class="defun">
&mdash; Function: int <b>tld_check_4z</b> (<var>const uint32_t * in, size_t * errpos, const Tld_table ** overrides</var>)<var><a name="index-tld_005fcheck_005f4z-96"></a></var><br>
<blockquote><p><var>in</var>: Zero-terminated array of unicode code points to process.

        <p><var>errpos</var>: Position of offending character is returned here.

        <p><var>overrides</var>: A <code>Tld_table</code> array of additional domain restriction
structures that complement and supersede the built-in information.

        <p>Test each of the code points in <code>in</code> for whether or not they are
allowed by the information in <code>overrides</code> or by the built-in TLD
restriction data. When data for the same TLD is available both
internally and in <code>overrides</code>, the information in <code>overrides</code> takes
precedence. If several entries for a specific TLD are found, the
first one is used.  If <code>overrides</code> is <code>NULL</code>, only the built-in
information is used.  The position of the first offending character
is returned in <code>errpos</code>.

        <p><strong>Return value:</strong> Returns the <code>Tld_rc</code> value <code>TLD_SUCCESS</code> if all code
points are valid or when <code>tld</code> is null, <code>TLD_INVALID</code> if a
character is not allowed, or additional error codes on general
failure conditions. 
</p></blockquote></div>

<h4 class="subheading">tld_check_8z</h4>

<p><a name="tld_005fcheck_005f8z"></a>

<div class="defun">
&mdash; Function: int <b>tld_check_8z</b> (<var>const char * in, size_t * errpos, const Tld_table ** overrides</var>)<var><a name="index-tld_005fcheck_005f8z-97"></a></var><br>
<blockquote><p><var>in</var>: Zero-terminated UTF8 string to process.

        <p><var>errpos</var>: Position of offending character is returned here.

        <p><var>overrides</var>: A <code>Tld_table</code> array of additional domain restriction
structures that complement and supersede the built-in information.

        <p>Test each of the characters in <code>in</code> for whether or not they are
allowed by the information in <code>overrides</code> or by the built-in TLD
restriction data. When data for the same TLD is available both
internally and in <code>overrides</code>, the information in <code>overrides</code> takes
precedence. If several entries for a specific TLD are found, the
first one is used.  If <code>overrides</code> is <code>NULL</code>, only the built-in
information is used.  The position of the first offending character
is returned in <code>errpos</code>.  Note that the error position refers to the
decoded character offset rather than the byte position in the
string.

        <p><strong>Return value:</strong> Returns the <code>Tld_rc</code> value <code>TLD_SUCCESS</code> if all
characters are valid or when <code>tld</code> is null, <code>TLD_INVALID</code> if a
character is not allowed, or additional error codes on general
failure conditions. 
</p></blockquote></div>

<h4 class="subheading">tld_check_lz</h4>

<p><a name="tld_005fcheck_005flz"></a>

<div class="defun">
&mdash; Function: int <b>tld_check_lz</b> (<var>const char * in, size_t * errpos, const Tld_table ** overrides</var>)<var><a name="index-tld_005fcheck_005flz-98"></a></var><br>
<blockquote><p><var>in</var>: Zero-terminated string in the current locales encoding to process.

        <p><var>errpos</var>: Position of offending character is returned here.

        <p><var>overrides</var>: A <code>Tld_table</code> array of additional domain restriction
structures that complement and supersede the built-in information.

        <p>Test each of the characters in <code>in</code> for whether or not they are
allowed by the information in <code>overrides</code> or by the built-in TLD
restriction data. When data for the same TLD is available both
internally and in <code>overrides</code>, the information in <code>overrides</code> takes
precedence. If several entries for a specific TLD are found, the
first one is used.  If <code>overrides</code> is <code>NULL</code>, only the built-in
information is used.  The position of the first offending character
is returned in <code>errpos</code>.  Note that the error position refers to the
decoded character offset rather than the byte position in the
string.

        <p><strong>Return value:</strong> Returns the <code>Tld_rc</code> value <code>TLD_SUCCESS</code> if all
characters are valid or when <code>tld</code> is null, <code>TLD_INVALID</code> if a
character is not allowed, or additional error codes on general
failure conditions. 
</p></blockquote></div>

<h3 class="section">7.5 Error Handling</h3>

<h4 class="subheading">tld_strerror</h4>

<p><a name="tld_005fstrerror"></a>

<div class="defun">
&mdash; Function: const char * <b>tld_strerror</b> (<var>Tld_rc rc</var>)<var><a name="index-tld_005fstrerror-99"></a></var><br>
<blockquote><p><var>rc</var>: tld return code

        <p>Convert a return code integer to a text string.  This string can be
used to output a diagnostic message to the user.

        <p><strong>TLD_SUCCESS:</strong> Successful operation.  This value is guaranteed to
always be zero, the remaining ones are only guaranteed to hold
non-zero values, for logical comparison purposes.

        <p><strong>TLD_INVALID:</strong> Invalid character found.

        <p><strong>TLD_NODATA:</strong> No input data was provided.

        <p><strong>TLD_MALLOC_ERROR:</strong> Error during memory allocation.

        <p><strong>TLD_ICONV_ERROR:</strong> Error during iconv string conversion.

        <p><strong>TLD_NO_TLD:</strong> No top-level domain found in domain string.

        <p><strong>Return value:</strong> Returns a pointer to a statically allocated string
containing a description of the error with the return code <code>rc</code>. 
</p></blockquote></div>

<!-- ********************************************************** -->
<!-- ********************** PR29 Functions ******************** -->
<!-- ********************************************************** -->
<div class="node">
<p><hr>
<a name="PR29-Functions"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Examples">Examples</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#TLD-Functions">TLD Functions</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="chapter">8 PR29 Functions</h2>

<p><a name="index-PR29-Functions-100"></a>
A deficiency in the specification of Unicode Normalization Forms has
been found.  The consequence is that some strings can be normalized
into different strings by different implementations.  In other words,
two different implementations may return different output for the same
input (because the interpretation of the specification is
ambiguous). Further, an implementation invoked again on the one of the
output strings may return a different string (because one of the
interpretation of the ambiguous specification make normalization
non-idempotent).  Fortunately, only a select few character sequence
exhibit this problem, and none of them are expected to occur in
natural languages (due to different linguistic uses of the involved
characters).

   <p>A full discussion of the problem may be found at:

   <p><a href="http://www.unicode.org/review/pr-29.html">http://www.unicode.org/review/pr-29.html</a>

   <p>The PR29 functions below allow you to detect the problem sequence.  So
when would you want to use these functions?  For most applications,
such as those using Nameprep for IDN, this is likely only to be an
interoperability problem.  Thus, you may not want to care about it, as
the character sequences will rarely occur naturally.  However, if you
are using a profile, such as SASLPrep, to process authentication
tokens; authorization tokens; or passwords, there is a real danger
that attackers may try to use the peculiarities in these strings to
attack parts of your system.  As only a small number of strings, and
no naturally occurring strings, exhibit this problem, the conservative
approach of rejecting the strings is recommended.  If this approach is
not used, you should instead verify that all parts of your system,
that process the tokens and passwords, use a NFKC implementation that
produce the same output for the same input.

   <p>Technically inclined readers may be interested in knowing more about
the implementation aspects of the PR29 flaw. See <a href="#PR29-discussion">PR29 discussion</a>.

<h3 class="section">8.1 Header file <code>pr29.h</code></h3>

<p>To use the functions explained in this chapter, you need to include
the file <samp><span class="file">pr29.h</span></samp> using:

<pre class="example">     #include &lt;pr29.h&gt;
</pre>
   <h3 class="section">8.2 Core Functions</h3>

<h4 class="subheading">pr29_4</h4>

<p><a name="pr29_005f4"></a>

<div class="defun">
&mdash; Function: int <b>pr29_4</b> (<var>const uint32_t * in, size_t len</var>)<var><a name="index-pr29_005f4-101"></a></var><br>
<blockquote><p><var>in</var>: input array with unicode code points.

        <p><var>len</var>: length of input array with unicode code points.

        <p>Check the input to see if it may be normalized into different
strings by different NFKC implementations, due to an anomaly in the
NFKC specifications.

        <p><strong>Return value:</strong> Returns the <code>Pr29_rc</code> value <code>PR29_SUCCESS</code> on success,
and <code>PR29_PROBLEM</code> if the input sequence is a "problem sequence"
(i.e., may be normalized into different strings by different
implementations). 
</p></blockquote></div>

<h3 class="section">8.3 Utility Functions</h3>

<h4 class="subheading">pr29_4z</h4>

<p><a name="pr29_005f4z"></a>

<div class="defun">
&mdash; Function: int <b>pr29_4z</b> (<var>const uint32_t * in</var>)<var><a name="index-pr29_005f4z-102"></a></var><br>
<blockquote><p><var>in</var>: zero terminated array of Unicode code points.

        <p>Check the input to see if it may be normalized into different
strings by different NFKC implementations, due to an anomaly in the
NFKC specifications.

        <p><strong>Return value:</strong> Returns the <code>Pr29_rc</code> value <code>PR29_SUCCESS</code> on success,
and <code>PR29_PROBLEM</code> if the input sequence is a "problem sequence"
(i.e., may be normalized into different strings by different
implementations). 
</p></blockquote></div>

<h4 class="subheading">pr29_8z</h4>

<p><a name="pr29_005f8z"></a>

<div class="defun">
&mdash; Function: int <b>pr29_8z</b> (<var>const char * in</var>)<var><a name="index-pr29_005f8z-103"></a></var><br>
<blockquote><p><var>in</var>: zero terminated input UTF-8 string.

        <p>Check the input to see if it may be normalized into different
strings by different NFKC implementations, due to an anomaly in the
NFKC specifications.

        <p><strong>Return value:</strong> Returns the <code>Pr29_rc</code> value <code>PR29_SUCCESS</code> on success,
and <code>PR29_PROBLEM</code> if the input sequence is a "problem sequence"
(i.e., may be normalized into different strings by different
implementations), or <code>PR29_STRINGPREP_ERROR</code> if there was a
problem converting the string from UTF-8 to UCS-4. 
</p></blockquote></div>

<h3 class="section">8.4 Error Handling</h3>

<h4 class="subheading">pr29_strerror</h4>

<p><a name="pr29_005fstrerror"></a>

<div class="defun">
&mdash; Function: const char * <b>pr29_strerror</b> (<var>Pr29_rc rc</var>)<var><a name="index-pr29_005fstrerror-104"></a></var><br>
<blockquote><p><var>rc</var>: an <code>Pr29_rc</code> return code.

        <p>Convert a return code integer to a text string.  This string can be
used to output a diagnostic message to the user.

        <p><strong>PR29_SUCCESS:</strong> Successful operation.  This value is guaranteed to
always be zero, the remaining ones are only guaranteed to hold
non-zero values, for logical comparison purposes.

        <p><strong>PR29_PROBLEM:</strong> A problem sequence was encountered.

        <p><strong>PR29_STRINGPREP_ERROR:</strong> The character set conversion failed (only
for <code>pr29_8()</code> and <code>pr29_8z()</code>).

        <p><strong>Return value:</strong> Returns a pointer to a statically allocated string
containing a description of the error with the return code <code>rc</code>. 
</p></blockquote></div>

<!-- ********************************************************** -->
<!-- ***********************  Examples  *********************** -->
<!-- ********************************************************** -->
<div class="node">
<p><hr>
<a name="Examples"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Invoking-idn">Invoking idn</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#PR29-Functions">PR29 Functions</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="chapter">9 Examples</h2>

<p><a name="index-Examples-105"></a>
This chapter contains example code which illustrate how `Libidn' can
be used when writing your own application.

<ul class="menu">
<li><a accesskey="1" href="#Example-1">Example 1</a>: 		Example using stringprep. 
<li><a accesskey="2" href="#Example-2">Example 2</a>: 		Example using punycode. 
<li><a accesskey="3" href="#Example-3">Example 3</a>: 		Example using IDNA ToASCII. 
<li><a accesskey="4" href="#Example-4">Example 4</a>: 		Example using IDNA ToUnicode. 
<li><a accesskey="5" href="#Example-5">Example 5</a>: 		Example using TLD checking. 
</ul>

<div class="node">
<p><hr>
<a name="Example-1"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Example-2">Example 2</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Examples">Examples</a>

</div>

<h3 class="section">9.1 Example 1</h3>

<p>This example demonstrates how the stringprep functions are used.

<pre class="verbatim">/* example.c --- Example code showing how to use stringprep().
 * Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007  Simon Josefsson
 *
 * This file is part of GNU Libidn.
 *
 * GNU Libidn is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * GNU Libidn 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with GNU Libidn; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
 *
 */

#include &lt;stdio.h>
#include &lt;stdlib.h>
#include &lt;string.h>
#include &lt;locale.h>		/* setlocale() */
#include &lt;stringprep.h>

/*
 * Compiling using libtool and pkg-config is recommended:
 *
 * $ libtool cc -o example example.c `pkg-config --cflags --libs libidn`
 * $ ./example
 * Input string encoded as `ISO-8859-1': ª
 * Before locale2utf8 (length 2): aa 0a
 * Before stringprep (length 3): c2 aa 0a
 * After stringprep (length 2): 61 0a
 * $
 *
 */

int
main (int argc, char *argv[])
{
  char buf[BUFSIZ];
  char *p;
  int rc;
  size_t i;

  setlocale (LC_ALL, "");

  printf ("Input string encoded as `%s': ", stringprep_locale_charset ());
  fflush (stdout);
  fgets (buf, BUFSIZ, stdin);

  printf ("Before locale2utf8 (length %d): ", strlen (buf));
  for (i = 0; i &lt; strlen (buf); i++)
    printf ("%02x ", buf[i] &amp; 0xFF);
  printf ("\n");

  p = stringprep_locale_to_utf8 (buf);
  if (p)
    {
      strcpy (buf, p);
      free (p);
    }
  else
    printf ("Could not convert string to UTF-8, continuing anyway...\n");

  printf ("Before stringprep (length %d): ", strlen (buf));
  for (i = 0; i &lt; strlen (buf); i++)
    printf ("%02x ", buf[i] &amp; 0xFF);
  printf ("\n");

  rc = stringprep (buf, BUFSIZ, 0, stringprep_nameprep);
  if (rc != STRINGPREP_OK)
    printf ("Stringprep failed (%d): %s\n", rc, stringprep_strerror (rc));
  else
    {
      printf ("After stringprep (length %d): ", strlen (buf));
      for (i = 0; i &lt; strlen (buf); i++)
	printf ("%02x ", buf[i] &amp; 0xFF);
      printf ("\n");
    }

  return 0;
}
</pre>
<div class="node">
<p><hr>
<a name="Example-2"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Example-3">Example 3</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Example-1">Example 1</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Examples">Examples</a>

</div>

<h3 class="section">9.2 Example 2</h3>

<p>This example demonstrates how the punycode functions are used.

<pre class="verbatim">/* example2.c --- Example code showing how to use punycode.
 * Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007  Simon Josefsson
 * Copyright (C) 2002  Adam M. Costello
 *
 * This file is part of GNU Libidn.
 *
 * GNU Libidn is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * GNU Libidn 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with GNU Libidn; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
 *
 */

#include &lt;locale.h>		/* setlocale() */

/*
 * This file is derived from RFC 3492 written by Adam M. Costello.
 *
 * Disclaimer and license: Regarding this entire document or any
 * portion of it (including the pseudocode and C code), the author
 * makes no guarantees and is not responsible for any damage resulting
 * from its use.  The author grants irrevocable permission to anyone
 * to use, modify, and distribute it in any way that does not diminish
 * the rights of anyone else to use, modify, and distribute it,
 * provided that redistributed derivative works do not contain
 * misleading author or version information.  Derivative works need
 * not be licensed under similar terms.
 *
 */

#include &lt;assert.h>
#include &lt;stdio.h>
#include &lt;stdlib.h>
#include &lt;string.h>

#include &lt;punycode.h>

/* For testing, we'll just set some compile-time limits rather than */
/* use malloc(), and set a compile-time option rather than using a  */
/* command-line option.                                             */

enum
{
  unicode_max_length = 256,
  ace_max_length = 256
};

static void
usage (char **argv)
{
  fprintf (stderr,
	   "\n"
	   "%s -e reads code points and writes a Punycode string.\n"
	   "%s -d reads a Punycode string and writes code points.\n"
	   "\n"
	   "Input and output are plain text in the native character set.\n"
	   "Code points are in the form u+hex separated by whitespace.\n"
	   "Although the specification allows Punycode strings to contain\n"
	   "any characters from the ASCII repertoire, this test code\n"
	   "supports only the printable characters, and needs the Punycode\n"
	   "string to be followed by a newline.\n"
	   "The case of the u in u+hex is the force-to-uppercase flag.\n",
	   argv[0], argv[0]);
  exit (EXIT_FAILURE);
}

static void
fail (const char *msg)
{
  fputs (msg, stderr);
  exit (EXIT_FAILURE);
}

static const char too_big[] =
  "input or output is too large, recompile with larger limits\n";
static const char invalid_input[] = "invalid input\n";
static const char overflow[] = "arithmetic overflow\n";
static const char io_error[] = "I/O error\n";

/* The following string is used to convert printable */
/* characters between ASCII and the native charset:  */

static const char print_ascii[] = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" " !\"#$%&amp;'()*+,-./" "0123456789:;&lt;=>?" "\0x40"	/* at sign */
  "ABCDEFGHIJKLMNO"
  "PQRSTUVWXYZ[\\]^_" "`abcdefghijklmno" "pqrstuvwxyz{|}~\n";

int
main (int argc, char **argv)
{
  enum punycode_status status;
  int r;
  size_t input_length, output_length, j;
  unsigned char case_flags[unicode_max_length];

  setlocale (LC_ALL, "");

  if (argc != 2)
    usage (argv);
  if (argv[1][0] != '-')
    usage (argv);
  if (argv[1][2] != 0)
    usage (argv);

  if (argv[1][1] == 'e')
    {
      uint32_t input[unicode_max_length];
      unsigned long codept;
      char output[ace_max_length + 1], uplus[3];
      int c;

      /* Read the input code points: */

      input_length = 0;

      for (;;)
	{
	  r = scanf ("%2s%lx", uplus, &amp;codept);
	  if (ferror (stdin))
	    fail (io_error);
	  if (r == EOF || r == 0)
	    break;

	  if (r != 2 || uplus[1] != '+' || codept > (uint32_t) - 1)
	    {
	      fail (invalid_input);
	    }

	  if (input_length == unicode_max_length)
	    fail (too_big);

	  if (uplus[0] == 'u')
	    case_flags[input_length] = 0;
	  else if (uplus[0] == 'U')
	    case_flags[input_length] = 1;
	  else
	    fail (invalid_input);

	  input[input_length++] = codept;
	}

      /* Encode: */

      output_length = ace_max_length;
      status = punycode_encode (input_length, input, case_flags,
				&amp;output_length, output);
      if (status == punycode_bad_input)
	fail (invalid_input);
      if (status == punycode_big_output)
	fail (too_big);
      if (status == punycode_overflow)
	fail (overflow);
      assert (status == punycode_success);

      /* Convert to native charset and output: */

      for (j = 0; j &lt; output_length; ++j)
	{
	  c = output[j];
	  assert (c >= 0 &amp;&amp; c &lt;= 127);
	  if (print_ascii[c] == 0)
	    fail (invalid_input);
	  output[j] = print_ascii[c];
	}

      output[j] = 0;
      r = puts (output);
      if (r == EOF)
	fail (io_error);
      return EXIT_SUCCESS;
    }

  if (argv[1][1] == 'd')
    {
      char input[ace_max_length + 2], *p, *pp;
      uint32_t output[unicode_max_length];

      /* Read the Punycode input string and convert to ASCII: */

      fgets (input, ace_max_length + 2, stdin);
      if (ferror (stdin))
	fail (io_error);
      if (feof (stdin))
	fail (invalid_input);
      input_length = strlen (input) - 1;
      if (input[input_length] != '\n')
	fail (too_big);
      input[input_length] = 0;

      for (p = input; *p != 0; ++p)
	{
	  pp = strchr (print_ascii, *p);
	  if (pp == 0)
	    fail (invalid_input);
	  *p = pp - print_ascii;
	}

      /* Decode: */

      output_length = unicode_max_length;
      status = punycode_decode (input_length, input, &amp;output_length,
				output, case_flags);
      if (status == punycode_bad_input)
	fail (invalid_input);
      if (status == punycode_big_output)
	fail (too_big);
      if (status == punycode_overflow)
	fail (overflow);
      assert (status == punycode_success);

      /* Output the result: */

      for (j = 0; j &lt; output_length; ++j)
	{
	  r = printf ("%s+%04lX\n",
		      case_flags[j] ? "U" : "u", (unsigned long) output[j]);
	  if (r &lt; 0)
	    fail (io_error);
	}

      return EXIT_SUCCESS;
    }

  usage (argv);
  return EXIT_SUCCESS;		/* not reached, but quiets compiler warning */
}
</pre>
<div class="node">
<p><hr>
<a name="Example-3"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Example-4">Example 4</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Example-2">Example 2</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Examples">Examples</a>

</div>

<h3 class="section">9.3 Example 3</h3>

<p>This example demonstrates how the library is used to convert
internationalized domain names into ASCII compatible names.

<pre class="verbatim">/* example3.c --- Example ToASCII() code showing how to use Libidn.
 * Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007  Simon Josefsson
 *
 * This file is part of GNU Libidn.
 *
 * GNU Libidn is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * GNU Libidn 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with GNU Libidn; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
 *
 */

#include &lt;stdio.h>
#include &lt;stdlib.h>
#include &lt;string.h>
#include &lt;locale.h>		/* setlocale() */
#include &lt;stringprep.h>		/* stringprep_locale_charset() */
#include &lt;idna.h>		/* idna_to_ascii_lz() */

/*
 * Compiling using libtool and pkg-config is recommended:
 *
 * $ libtool cc -o example3 example3.c `pkg-config --cflags --libs libidn`
 * $ ./example3
 * Input domain encoded as `ISO-8859-1': www.räksmörgåsª.example
 * Read string (length 23): 77 77 77 2e 72 e4 6b 73 6d f6 72 67 e5 73 aa 2e 65 78 61 6d 70 6c 65
 * ACE label (length 33): 'www.xn--rksmrgsa-0zap8p.example'
 * 77 77 77 2e 78 6e 2d 2d 72 6b 73 6d 72 67 73 61 2d 30 7a 61 70 38 70 2e 65 78 61 6d 70 6c 65
 * $
 *
 */

int
main (int argc, char *argv[])
{
  char buf[BUFSIZ];
  char *p;
  int rc;
  size_t i;

  setlocale (LC_ALL, "");

  printf ("Input domain encoded as `%s': ", stringprep_locale_charset ());
  fflush (stdout);
  fgets (buf, BUFSIZ, stdin);
  buf[strlen (buf) - 1] = '\0';

  printf ("Read string (length %d): ", strlen (buf));
  for (i = 0; i &lt; strlen (buf); i++)
    printf ("%02x ", buf[i] &amp; 0xFF);
  printf ("\n");

  rc = idna_to_ascii_lz (buf, &amp;p, 0);
  if (rc != IDNA_SUCCESS)
    {
      printf ("ToASCII() failed (%d): %s\n", rc, idna_strerror (rc));
      exit (1);
    }

  printf ("ACE label (length %d): '%s'\n", strlen (p), p);
  for (i = 0; i &lt; strlen (p); i++)
    printf ("%02x ", p[i] &amp; 0xFF);
  printf ("\n");

  free (p);

  return 0;
}
</pre>
<div class="node">
<p><hr>
<a name="Example-4"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Example-5">Example 5</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Example-3">Example 3</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Examples">Examples</a>

</div>

<h3 class="section">9.4 Example 4</h3>

<p>This example demonstrates how the library is used to convert ASCII
compatible names to internationalized domain names.

<pre class="verbatim">/* example4.c --- Example ToUnicode() code showing how to use Libidn.
 * Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007  Simon Josefsson
 *
 * This file is part of GNU Libidn.
 *
 * GNU Libidn is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * GNU Libidn 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with GNU Libidn; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
 *
 */

#include &lt;stdio.h>
#include &lt;stdlib.h>
#include &lt;string.h>
#include &lt;locale.h>		/* setlocale() */
#include &lt;stringprep.h>		/* stringprep_locale_charset() */
#include &lt;idna.h>		/* idna_to_unicode_lzlz() */

/*
 * Compiling using libtool and pkg-config is recommended:
 *
 * $ libtool cc -o example4 example4.c `pkg-config --cflags --libs libidn`
 * $ ./example4
 * Input domain encoded as `ISO-8859-1': www.xn--rksmrgsa-0zap8p.example
 * Read string (length 33): 77 77 77 2e 78 6e 2d 2d 72 6b 73 6d 72 67 73 61 2d 30 7a 61 70 38 70 2e 65 78 61 6d 70 6c 65
 * ACE label (length 23): 'www.räksmörgåsa.example'
 * 77 77 77 2e 72 e4 6b 73 6d f6 72 67 e5 73 61 2e 65 78 61 6d 70 6c 65
 * $
 *
 */

int
main (int argc, char *argv[])
{
  char buf[BUFSIZ];
  char *p;
  int rc;
  size_t i;

  setlocale (LC_ALL, "");

  printf ("Input domain encoded as `%s': ", stringprep_locale_charset ());
  fflush (stdout);
  fgets (buf, BUFSIZ, stdin);
  buf[strlen (buf) - 1] = '\0';

  printf ("Read string (length %d): ", strlen (buf));
  for (i = 0; i &lt; strlen (buf); i++)
    printf ("%02x ", buf[i] &amp; 0xFF);
  printf ("\n");

  rc = idna_to_unicode_lzlz (buf, &amp;p, 0);
  if (rc != IDNA_SUCCESS)
    {
      printf ("ToUnicode() failed (%d): %s\n", rc, idna_strerror (rc));
      exit (1);
    }

  printf ("ACE label (length %d): '%s'\n", strlen (p), p);
  for (i = 0; i &lt; strlen (p); i++)
    printf ("%02x ", p[i] &amp; 0xFF);
  printf ("\n");

  free (p);

  return 0;
}
</pre>
<div class="node">
<p><hr>
<a name="Example-5"></a>
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Example-4">Example 4</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Examples">Examples</a>

</div>

<h3 class="section">9.5 Example 5</h3>

<p>This example demonstrates how the library is used to check a string
for invalid characters within a specific TLD.

<pre class="verbatim">/* example5.c --- Example TLD checking.
 * Copyright (C) 2004, 2005, 2006, 2007  Simon Josefsson
 *
 * This file is part of GNU Libidn.
 *
 * GNU Libidn is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * GNU Libidn 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with GNU Libidn; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
 *
 */

#include &lt;stdio.h>
#include &lt;stdlib.h>
#include &lt;string.h>

/* Get stringprep_locale_charset, etc. */
#include &lt;stringprep.h>

/* Get idna_to_ascii_8z, etc. */
#include &lt;idna.h>

/* Get tld_check_4z. */
#include &lt;tld.h>

/*
 * Compiling using libtool and pkg-config is recommended:
 *
 * $ libtool cc -o example5 example5.c `pkg-config --cflags --libs libidn`
 * $ ./example5
 * Input domain encoded as `UTF-8': fooß.no
 * Read string (length 8): 66 6f 6f c3 9f 2e 6e 6f
 * ToASCII string (length 8): fooss.no
 * ToUnicode string: U+0066 U+006f U+006f U+0073 U+0073 U+002e U+006e U+006f
 * Domain accepted by TLD check
 *
 * $ ./example5
 * Input domain encoded as `UTF-8': gr€€n.no
 * Read string (length 12): 67 72 e2 82 ac e2 82 ac 6e 2e 6e 6f
 * ToASCII string (length 16): xn--grn-l50aa.no
 * ToUnicode string: U+0067 U+0072 U+20ac U+20ac U+006e U+002e U+006e U+006f
 * Domain rejected by TLD check, Unicode position 2
 *
 */

int
main (int argc, char *argv[])
{
  char buf[BUFSIZ];
  char *p;
  uint32_t *r;
  int rc;
  size_t errpos, i;

  printf ("Input domain encoded as `%s': ", stringprep_locale_charset ());
  fflush (stdout);
  fgets (buf, BUFSIZ, stdin);
  buf[strlen (buf) - 1] = '\0';

  printf ("Read string (length %d): ", strlen (buf));
  for (i = 0; i &lt; strlen (buf); i++)
    printf ("%02x ", buf[i] &amp; 0xFF);
  printf ("\n");

  p = stringprep_locale_to_utf8 (buf);
  if (p)
    {
      strcpy (buf, p);
      free (p);
    }
  else
    printf ("Could not convert string to UTF-8, continuing anyway...\n");

  rc = idna_to_ascii_8z (buf, &amp;p, 0);
  if (rc != IDNA_SUCCESS)
    {
      printf ("idna_to_ascii_8z failed (%d): %s\n", rc, idna_strerror (rc));
      return 2;
    }

  printf ("ToASCII string (length %d): %s\n", strlen (p), p);

  rc = idna_to_unicode_8z4z (p, &amp;r, 0);
  free (p);
  if (rc != IDNA_SUCCESS)
    {
      printf ("idna_to_unicode_8z4z failed (%d): %s\n",
	      rc, idna_strerror (rc));
      return 2;
    }

  printf ("ToUnicode string: ");
  for (i = 0; r[i]; i++)
    printf ("U+%04x ", r[i]);
  printf ("\n");

  rc = tld_check_4z (r, &amp;errpos, NULL);
  free (r);
  if (rc == TLD_INVALID)
    {
      printf ("Domain rejected by TLD check, Unicode position %d\n", errpos);
      return 1;
    }
  else if (rc != TLD_SUCCESS)
    {
      printf ("tld_check_4z() failed (%d): %s\n", rc, tld_strerror (rc));
      return 2;
    }

  printf ("Domain accepted by TLD check\n");

  return 0;
}
</pre>
<!-- ********************************************************** -->
<!-- *********************  Invoking idn  ********************* -->
<!-- ********************************************************** -->
<div class="node">
<p><hr>
<a name="Invoking-idn"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Emacs-API">Emacs API</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Examples">Examples</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="chapter">10 Invoking idn</h2>

<p><a name="index-idn-106"></a><a name="index-invoking-_0040command_007bidn_007d-107"></a><a name="index-command-line-108"></a>

<h3 class="section">10.1 Name</h3>

<p>GNU Libidn (idn) &ndash; Internationalized Domain Names command line tool

<h3 class="section">10.2 Description</h3>

<p><code>idn</code> allows internationalized string preparation
(`<samp><span class="samp">stringprep</span></samp>'), encoding and decoding of punycode data, and IDNA
ToASCII/ToUnicode operations to be performed on the command line.

   <p>If strings are specified on the command line, they are used as input
and the computed output is printed to standard output <code>stdout</code>. 
If no strings are specified on the command line, the program read
data, line by line, from the standard input <code>stdin</code>, and print
the computed output to standard output.  What processing is performed
(e.g., ToASCII, or Punycode encode) is indicated by options.  If any
errors are encountered, the execution of the applications is aborted.

   <p>All strings are expected to be encoded in the preferred charset used
by your locale.  Use <code>--debug</code> to find out what this charset is. 
You can override the charset used by setting environment variable
<code>CHARSET</code>.

   <p>To process a string that starts with <code>-</code>, for example
<code>-foo</code>, use <code>--</code> to signal the end of parameters, as in
<code>idn --quiet -a -- -foo</code>.

<h3 class="section">10.3 Options</h3>

<p><code>idn</code> recognizes these commands:

<pre class="verbatim">
  -h, --help               Print help and exit

  -V, --version            Print version and exit

  -s, --stringprep         Prepare string according to nameprep profile

  -d, --punycode-decode    Decode Punycode

  -e, --punycode-encode    Encode Punycode

  -a, --idna-to-ascii      Convert to ACE according to IDNA (default)

  -u, --idna-to-unicode    Convert from ACE according to IDNA

      --allow-unassigned   Toggle IDNA AllowUnassigned flag  (default=off)

      --usestd3asciirules  Toggle IDNA UseSTD3ASCIIRules flag  (default=off)

  -t, --tld                Check string for TLD specific rules
                             Only for --idna-to-ascii and --idna-to-unicode
                             (default=on)

  -p, --profile=STRING     Use specified stringprep profile instead
                             Valid stringprep profiles are `Nameprep',
                             `iSCSI', `Nodeprep', `Resourceprep', `trace', and
                             `SASLprep'.

      --debug              Print debugging information  (default=off)

      --quiet              Silent operation  (default=off)
</pre>

<h3 class="section">10.4 Environment Variables</h3>

<p>The <var>CHARSET</var> environment variable can be used to override what
character set to be used for decoding incoming data (i.e., on the
command line or on the standard input stream), and to encode data to
the standard output.  If your system is set up correctly, however, the
application will guess which character set is used automatically. 
Example usage:

<pre class="example">     $ CHARSET=ISO-8859-1 idn --punycode-encode
     ...
</pre>
   <h3 class="section">10.5 Examples</h3>

<p>Standard usage, reading input from standard input:

<pre class="example">     jas@latte:~$ idn
     libidn 0.3.5
     Copyright 2002, 2003 Simon Josefsson.
     GNU Libidn comes with NO WARRANTY, to the extent permitted by law.
     You may redistribute copies of GNU Libidn under the terms of
     the GNU Lesser General Public License.  For more information
     about these matters, see the file named COPYING.LIB.
     Type each input string on a line by itself, terminated by a newline character.
     r&auml;ksm&ouml;rg&aring;s.se
     xn--rksmrgs-5wao1o.se
     jas@latte:~$
</pre>
   <p>Reading input from command line, and disabling copyright and license
information:

<pre class="example">     jas@latte:~$ idn --quiet r&auml;ksm&ouml;rg&aring;s.se bl&aring;b&aelig;rgr&oslash;d.no
     xn--rksmrgs-5wao1o.se
     xn--blbrgrd-fxak7p.no
     jas@latte:~$
</pre>
   <p>Accessing a specific StringPrep profile directly:

<pre class="example">     jas@latte:~$ idn --quiet --profile=SASLprep --stringprep te&szlig;t&ordf;
     te&szlig;ta
     jas@latte:~$
</pre>
   <h3 class="section">10.6 Troubleshooting</h3>

<p>Getting character data encoded right, and making sure Libidn use the
same encoding, can be difficult.  The reason for this is that most
systems encode character data in more than one character encoding,
i.e., using <code>UTF-8</code> together with <code>ISO-8859-1</code> or
<code>ISO-2022-JP</code>.  This problem is likely to continue to exist until
only one character encoding come out as the evolutionary winner, or
(more likely, at least to some extents) forever.

   <p>The first step to troubleshooting character encoding problems with
Libidn is to use the `<samp><span class="samp">--debug</span></samp>' parameter to find out which
character set encoding `<samp><span class="samp">idn</span></samp>' believe your locale uses.

<pre class="example">     jas@latte:~$ idn --debug --quiet ""
     system locale uses charset `UTF-8'.
     
     jas@latte:~$
</pre>
   <p>If it prints <code>ANSI_X3.4-1968</code> (i.e., <code>US-ASCII</code>), this
indicate you have not configured your locale properly.  To configure
the locale, you can, for example, use `<samp><span class="samp">LANG=sv_SE.UTF-8; export
LANG</span></samp>' at a <code>/bin/sh</code> prompt, to set up your locale for a Swedish
environment using <code>UTF-8</code> as the encoding.

   <p>Sometimes `<samp><span class="samp">idn</span></samp>' appear to be unable to translate from your system
locale into <code>UTF-8</code> (which is used internally), and you get an
error like the following:

<pre class="example">     jas@latte:~$ idn --quiet foo
     idn: could not convert from ISO-8859-1 to UTF-8.
     jas@latte:~$
</pre>
   <p>The simplest explanation is that you haven't installed the
`<samp><span class="samp">iconv</span></samp>' conversion tools.  You can find it as a standalone
library in <acronym>GNU</acronym> Libiconv
(<a href="http://www.gnu.org/software/libiconv/">http://www.gnu.org/software/libiconv/</a>).  On many
<acronym>GNU</acronym>/Linux systems, this library is part of the system, but
you may have to install additional packages (e.g., `<samp><span class="samp">glibc-locale</span></samp>'
for Debian) to be able to use it.

   <p>Another explanation is that the error is correct and you are feeding
`<samp><span class="samp">idn</span></samp>' invalid data.  This can happen inadvertently if you are not
careful with the character set encodings you use.  For example, if
your shell run in a <code>ISO-8859-1</code> environment, and you invoke
`<samp><span class="samp">idn</span></samp>' with the `<samp><span class="samp">CHARSET</span></samp>' environment variable as follows,
you will feed it <code>ISO-8859-1</code> characters but force it to believe
they are <code>UTF-8</code>.  Naturally this will lead to an error, unless
the byte sequences happen to be parsable as <code>UTF-8</code>.  Note that
even if you don't get an error, the output may be incorrect in this
situation, because <code>ISO-8859-1</code> and <code>UTF-8</code> does not in
general encode the same characters as the same byte sequences.

<pre class="example">     jas@latte:~$ idn --quiet --debug ""
     system locale uses charset `ISO-8859-1'.
     
     jas@latte:~$ CHARSET=UTF-8 idn --quiet --debug r&auml;ksm&ouml;rg&aring;s
     system locale uses charset `UTF-8'.
     input[0] = U+0072
     input[1] = U+4af3
     input[2] = U+006d
     input[3] = U+1b29e5
     input[4] = U+0073
     output[0] = U+0078
     output[1] = U+006e
     output[2] = U+002d
     output[3] = U+002d
     output[4] = U+0072
     output[5] = U+006d
     output[6] = U+0073
     output[7] = U+002d
     output[8] = U+0068
     output[9] = U+0069
     output[10] = U+0036
     output[11] = U+0064
     output[12] = U+0035
     output[13] = U+0039
     output[14] = U+0037
     output[15] = U+0035
     output[16] = U+0035
     output[17] = U+0032
     output[18] = U+0061
     xn--rms-hi6d597552a
     jas@latte:~$
</pre>
   <p>The sense moral here is to forget about `<samp><span class="samp">CHARSET</span></samp>' (configure your
locales properly instead) unless you know what you are doing, and if
you want to use it, do it carefully, after verifying with
`<samp><span class="samp">--debug</span></samp>' that you get the desired results.

<div class="node">
<p><hr>
<a name="Emacs-API"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Java-API">Java API</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Invoking-idn">Invoking idn</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="chapter">11 Emacs API</h2>

<p>Included in Libidn are <samp><span class="file">punycode.el</span></samp> and <samp><span class="file">idna.el</span></samp> that
provides an Emacs Lisp API to (a limited set of) the Libidn API.  This
section describes the API.  Currently the IDNA API always set the
<code>UseSTD3ASCIIRules</code> flag and clear the <code>AllowUnassigned</code>
flag, in the future there may be functionality to specify these flags
via the API.

<h3 class="section">11.1 Punycode Emacs API</h3>

<div class="defun">
&mdash; Variable: <b>punycode-program</b><var><a name="index-punycode_002dprogram-109"></a></var><br>
<blockquote><p>Name of the GNU Libidn <samp><span class="file">idn</span></samp> application.  The default is
`<samp><span class="samp">idn</span></samp>'.  This variable can be customized. 
</p></blockquote></div>

<div class="defun">
&mdash; Variable: <b>punycode-environment</b><var><a name="index-punycode_002denvironment-110"></a></var><br>
<blockquote><p>List of environment variable definitions prepended to
`<samp><span class="samp">process-environment</span></samp>'.  The default is `<samp><span class="samp">("CHARSET=UTF-8")</span></samp>'. 
This variable can be customized. 
</p></blockquote></div>

<div class="defun">
&mdash; Variable: <b>punycode-encode-parameters</b><var><a name="index-punycode_002dencode_002dparameters-111"></a></var><br>
<blockquote><p>List of parameters passed to <var>punycode-program</var> to invoke punycode
encoding mode.  The default is `<samp><span class="samp">("--quiet" "--punycode-encode")</span></samp>'. 
This variable can be customized. 
</p></blockquote></div>

<div class="defun">
&mdash; Variable: <b>punycode-decode-parameters</b><var><a name="index-punycode_002ddecode_002dparameters-112"></a></var><br>
<blockquote><p>Parameters passed to <var>punycode-program</var> to invoke punycode
decoding mode.  The default is `<samp><span class="samp">("--quiet" "--punycode-decode")</span></samp>'. 
This variable can be customized. 
</p></blockquote></div>

<div class="defun">
&mdash; Function: <b>punycode-encode</b><var> string<a name="index-punycode_002dencode-113"></a></var><br>
<blockquote><p>Returns a Punycode encoding of the <var>string</var>, after converting the
input into UTF-8. 
</p></blockquote></div>

<div class="defun">
&mdash; Function: <b>punycode-decode</b><var> string<a name="index-punycode_002ddecode-114"></a></var><br>
<blockquote><p>Returns a possibly multibyte string which is the decoding of the
<var>string</var> which is a punycode encoded string. 
</p></blockquote></div>

<h3 class="section">11.2 IDNA Emacs API</h3>

<div class="defun">
&mdash; Variable: <b>idna-program</b><var><a name="index-idna_002dprogram-115"></a></var><br>
<blockquote><p>Name of the GNU Libidn <samp><span class="file">idn</span></samp> application.  The default is
`<samp><span class="samp">idn</span></samp>'.  This variable can be customized. 
</p></blockquote></div>

<div class="defun">
&mdash; Variable: <b>idna-environment</b><var><a name="index-idna_002denvironment-116"></a></var><br>
<blockquote><p>List of environment variable definitions prepended to
`<samp><span class="samp">process-environment</span></samp>'.  The default is `<samp><span class="samp">("CHARSET=UTF-8")</span></samp>'. 
This variable can be customized. 
</p></blockquote></div>

<div class="defun">
&mdash; Variable: <b>idna-to-ascii-parameters</b><var><a name="index-idna_002dto_002dascii_002dparameters-117"></a></var><br>
<blockquote><p>List of parameters passed to <var>idna-program</var> to invoke IDNA ToASCII
mode.  The default is `<samp><span class="samp">("--quiet" "--idna-to-ascii"
"--usestd3asciirules")</span></samp>'.  This variable can be customized. 
</p></blockquote></div>

<div class="defun">
&mdash; Variable: <b>idna-to-unicode-parameters</b><var><a name="index-idna_002dto_002dunicode_002dparameters-118"></a></var><br>
<blockquote><p>Parameters passed <var>idna-program</var> to invoke IDNA ToUnicode mode. 
The default is `<samp><span class="samp">("--quiet" "--idna-to-unicode"
"--usestd3asciirules")</span></samp>'.  This variable can be customized. 
</p></blockquote></div>

<div class="defun">
&mdash; Function: <b>idna-to-ascii</b><var> string<a name="index-idna_002dto_002dascii-119"></a></var><br>
<blockquote><p>Returns an ASCII Compatible Encoding (ACE) of the string computed by
the IDNA ToASCII operation on the input <var>string</var>, after converting
the input to UTF-8. 
</p></blockquote></div>

<div class="defun">
&mdash; Function: <b>idna-to-unicode</b><var> string<a name="index-idna_002dto_002dunicode-120"></a></var><br>
<blockquote><p>Returns a possibly multibyte string which is the output of the IDNA
ToUnicode operation computed on the input <var>string</var>. 
</p></blockquote></div>

<div class="node">
<p><hr>
<a name="Java-API"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#C_0023-API">C# API</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Emacs-API">Emacs API</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="chapter">12 Java API</h2>

<p>Libidn has been ported to the Java programming language, and as a
consequence most of the API is available to native Java applications. 
This section contain notes on this support, complete documentation is
pending.

   <p>The Java library, if Libidn has been built with Java support
(see <a href="#Downloading-and-Installing">Downloading and Installing</a>), will be placed in
<samp><span class="file">java/libidn.jar</span></samp>.  The source code is located in
<samp><span class="file">java/gnu/inet/encoding/</span></samp>.

<h3 class="section">12.1 Overview</h3>

<p>This package provides a Java implementation of the Internationalized
Domain Names in Applications (IDNA) standard. It is written entirely
in Java and does not require any additional libraries to be set up.

   <p>The gnu.inet.encoding.IDNA class offers two public functions, toASCII
and toUnicode which can be used as follows:

<pre class="example">     gnu.inet.encoding.IDNA.toASCII("bl&ouml;ds.z&uuml;g");
     gnu.inet.encoding.IDNA.toUnicode("xn--blds-6qa.xn--zg-xka");
</pre>
   <h3 class="section">12.2 Miscellaneous Programs</h3>

<p>The <samp><span class="file">misc/</span></samp> directory contains several programs that are related
to the Java part of GNU Libidn, but that don't need to be included in
the main source tree.

<h4 class="subsection">12.2.1 GenerateRFC3454</h4>

<p>This program parses RFC3454 and creates the RFC3454.java program that
is required during the StringPrep phase.

   <p>The RFC can be found at various locations, for example at
<a href="http://www.ietf.org/rfc/rfc3454.txt">http://www.ietf.org/rfc/rfc3454.txt</a>.

   <p>Invoke the program as follows:

<pre class="example">     $ java GenerateRFC3454
     Creating RFC3454.java... Ok.
</pre>
   <h4 class="subsection">12.2.2 GenerateNFKC</h4>

<p>The GenerateNFKC program parses the Unicode character database file
and generates all the tables required for NFKC. This program requires
the two files UnicodeData.txt and CompositionExclusions.txt of version
3.2 of the Unicode files. Note that RFC3454 (Stringprep) defines that
Unicode version 3.2 is to be used, not the latest version.

   <p>The Unicode data files can be found at
<a href="http://www.unicode.org/Public/">http://www.unicode.org/Public/</a>.

   <p>Invoke the program as follows:

<pre class="example">     $ java GenerateNFKC
     Creating CombiningClass.java... Ok.
     Creating DecompositionKeys.java... Ok.
     Creating DecompositionMappings.java... Ok.
     Creating Composition.java... Ok.
</pre>
   <h4 class="subsection">12.2.3 TestIDNA</h4>

<p>The TestIDNA program allows to test the IDNA implementation manually
or against Simon Josefsson's test vectors.

   <p>The test vectors can be found at the Libidn homepage,
<a href="http://www.gnu.org/software/libidn/">http://www.gnu.org/software/libidn/</a>.

   <p>To test the tranformation manually, use:

<pre class="example">     $ java -cp .:../libidn.jar TestIDNA -a &lt;string to test&gt;
     Input: &lt;string to test&gt;
     Output: &lt;toASCII(string to test)&gt;
     $ java -cp .:../libidn.jar TestIDNA -u &lt;string to test&gt;
     Input: &lt;string to test&gt;
     Output: &lt;toUnicode(string to test)&gt;
</pre>
   <p>To test against draft-josefsson-idn-test-vectors.html, use:

<pre class="example">     $ java -cp .:../libidn.jar TestIDNA -t
     No errors detected!
</pre>
   <h4 class="subsection">12.2.4 TestNFKC</h4>

<p>The TestNFKC program allows to test the NFKC implementation manually
or against the NormalizationTest.txt file from the Unicode data files.

   <p>To test the normalization manually, use:

<pre class="example">     $ java -cp .:../libidn.jar TestNFKC &lt;string to test&gt;
     Input: &lt;string to test&gt;
     Output: &lt;nfkc version of the string to test&gt;
</pre>
   <p>To test against NormalizationTest.txt:

<pre class="example">     $ java -cp .:../libidn.jar TestNFKC
     No errors detected!
</pre>
   <h3 class="section">12.3 Possible Problems</h3>

<p>Beware of Bugs: This Java API needs a lot more testing, especially
with "exotic" character sets. While it works for me, it may not work
for you.

   <p>Encoding of your Java sources: If you are using non-ASCII characters
in your Java source code, make sure javac compiles your programs with
the correct encoding. If necessary specify the encoding using the
-encoding parameter.

   <p>Java Unicode handling: Java 1.4 only handles 16-bit Unicode code
points (i.e. characters in the Basic Multilingual Plane), this
implementation therefore ignores all references to so-called
Supplementary Characters (U+10000 to U+10FFFF). Starting from Java
1.5, these characters will also be supported by Java, but this will
require changes to this library.  See also the next section.

<h3 class="section">12.4 A Note on Java and Unicode</h3>

<p>This library uses Java's builtin 'char' datatype. Up to Java 1.4, this
datatype only supports 16-bit Unicode code points, also called the
Basic Multilingual Plane. For this reason, this library doesn't work
for Supplementary Characters (i.e. characters from U+10000 to
U+10FFFF). All references to such characters are silently ignored.

   <p>Starting from Java 1.5, also Supplementary Characters will be
supported. However, this will require changes in the present version
of the library. Java 1.5 is currently in beta status.

   <p>For more information refer to the documentation of java.lang.Character
in the JDK API.

<div class="node">
<p><hr>
<a name="C%23-API"></a>
<a name="C_0023-API"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Acknowledgements">Acknowledgements</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Java-API">Java API</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="chapter">13 C# API</h2>

<p>The Libidn library has been ported to the C# language.  The port
reside in the top-level <samp><span class="file">csharp/</span></samp> directory.  Currently, no
further documentation about the implementation or the API is
available.  However, the C# port was based on the Java port, and the
API is exactly the same as in the Java version.  The help files for
the Java API may thus be useful.

<!-- ********************************************************** -->
<!-- *******************  Acknowledgements  ******************* -->
<!-- ********************************************************** -->
<div class="node">
<p><hr>
<a name="Acknowledgements"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#History">History</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#C_0023-API">C# API</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="chapter">14 Acknowledgements</h2>

<p>The punycode implementation was taken from the IETF IDN Punycode
specification, by Adam M. Costello.  The TLD code was contributed by
Thomas Jacob.  The Java implementation was contributed by Oliver Hitz. 
The C# implementation was contributed by Alexander Gnauck.  The
Unicode tables were provided by Unicode, Inc.  Some functions for
dealing with Unicode (see nfkc.c and toutf8.c) were borrowed from
GLib, downloaded from <a href="http://www.gtk.org/">http://www.gtk.org/</a>.  The manual borrowed
text from Libgcrypt by Werner Koch.

   <p>Inspiration for many things that, consciously or not, have gone into
this package is due to a number of free software package that the
author has been exposed to.  The author wishes to acknowledge the free
software community in general, for giving an example on what role
software development can play in the modern society.

   <p>Several people reported bugs, sent patches or suggested improvements,
see the file THANKS in the top-level directory of the source code.

<!-- ********************************************************** -->
<!-- ************************  History  *********************** -->
<!-- ********************************************************** -->
<div class="node">
<p><hr>
<a name="History"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#PR29-discussion">PR29 discussion</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Acknowledgements">Acknowledgements</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="chapter">15 History</h2>

<p>The complete history of user visible changes is stored in the file
<samp><span class="file">NEWS</span></samp> in the top-level directory of the source code tree.  The
complete history of modifications to each file is stored in the file
<samp><span class="file">ChangeLog</span></samp> in the same directory.  This section contain a
condensed version of that information, in the form of &ldquo;milestones&rdquo;
for the project.

     <dl>
<dt>Stringprep implementation.<dd>Version 0.0.0 released on 2002-11-05.

     <br><dt>IDNA and Punycode implementations, part of the GNU project.<dd>Version 0.1.0 released on 2003-01-05.

     <br><dt>Uses official IDNA ACE prefix 'xn&ndash;'.<dd>Version 0.1.7 released on 2003-02-12.

     <br><dt>Command line interface.<dd>Version 0.1.11 released on 2003-02-26.

     <br><dt>GNU Libc add-on proposed.<dd>Version 0.1.12 released on 2003-03-06.

     <br><dt>Interoperability testing during IDNConnect.<dd>Version 0.3.1 released on 2003-10-02.

     <br><dt>TLD restriction testing.<dd>Version 0.4.0 released on 2004-02-28.

     <br><dt>GNU Libc add-on integrated.<dd>Version 0.4.1 released on 2004-03-08.

     <br><dt>Native Java implementation.<dd>Version 0.4.2-0.4.9 released between 2004-03-20 and 2004-06-11.

     <br><dt>PR-29 functions for &ldquo;problem sequences&rdquo;.<dd>Version 0.5.0 released on 2004-06-26.

     <br><dt>Many small portability fixes and wider use.<dd>Version 0.5.1 through 0.5.20, released between 2004-07-09 and
2005-10-23.

     <br><dt>Native C# implementation.<dd>Version 0.6.0 released on 2005-12-03.

     <br><dt>Windows support through cross-compilation.<dd>Version 0.6.1 released on 2006-01-20.

   </dl>

<div class="node">
<p><hr>
<a name="PR29-discussion"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Copying-Information">Copying Information</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#History">History</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="appendix">Appendix A PR29 discussion</h2>

<p>If you wish to experiment with a modified Unicode NFKC implementation
according to the PR29 proposal, you may find the following bug report
useful.  However, I have not verified that the suggested modifications
are correct.  For reference, I'm including my response to the report
as well.

<pre class="verbatim">
From: Rick McGowan &lt;rick@unicode.org>
Subject: Possible bug and status of PR 29 change(s)
To: bug-libidn@gnu.org
Date: Wed, 27 Oct 2004 14:49:17 -0700

Hello. On behalf of the Unicode Consortium editorial committee, I would  
like to find out more information about the PR 29 fixes, if any, and  
functions in Libidn. Your implementation was listed in the text of PR29 as  
needing investigation, so I am following up on several implementations.

The UTC has accepted the proposed fix to D2 as outlined in PR29, and a new  
draft of UAX #15 has been issued.

I have looked at Libidn 0.5.8 (today), and there may still be a possible  
bug in NFKC.java and nfkc.c.

------------------------------------------------------

1. In NFKC.java, this line in canonicalOrdering():

      if (i > 0 &amp;&amp; (last_cc == 0 || last_cc != cc)) {

should perhaps be changed to:

      if (i > 0 &amp;&amp; (last_cc == 0 || last_cc &lt; cc)) {

but I'm not sure of the sense of this comparison.

------------------------------------------------------

2. In nfkc.c, function _g_utf8_normalize_wc() has this code:

	  if (i > 0 &amp;&amp;
	      (last_cc == 0 || last_cc != cc) &amp;&amp;
	      combine (wc_buffer[last_start], wc_buffer[i],
		       &amp;wc_buffer[last_start]))
	    {

This appears to have the same bug as the current Python implementation (in  
Python 2.3.4). The code should be checking, as per new rule D2 UAX #15  
update, that the next combining character is the same or HIGHER than the  
current one. It now checks to see if it's non-zero and not equal.

The above line(s) should perhaps be changed to:

	  if (i > 0 &amp;&amp;
	      (last_cc == 0 || last_cc &lt; cc) &amp;&amp;
	      combine (wc_buffer[last_start], wc_buffer[i],
		       &amp;wc_buffer[last_start]))
	    {

but I'm not sure of the sense of the comparison (&lt; or > or &lt;=?) here.

In the text of PR29, I will be marking Libidn as "needs change" and adding  
the version number that I checked. If any further change is made, please  
let me know the release version, and I'll update again.

Regards,
	Rick McGowan
</pre>

<pre class="verbatim">
From: Simon Josefsson &lt;jas@extundo.com>
Subject: Re: Possible bug and status of PR 29 change(s)
To: Rick McGowan &lt;rick@unicode.org>
Cc: bug-libidn@gnu.org
Date: Thu, 28 Oct 2004 09:47:47 +0200

Rick McGowan &lt;rick@unicode.org> writes:

> Hello. On behalf of the Unicode Consortium editorial committee, I would  
> like to find out more information about the PR 29 fixes, if any, and  
> functions in Libidn. Your implementation was listed in the text of PR29 as  
> needing investigation, so I am following up on several implementations.
>
> The UTC has accepted the proposed fix to D2 as outlined in PR29, and a new  
> draft of UAX #15 has been issued.
>
> I have looked at Libidn 0.5.8 (today), and there may still be a possible  
> bug in NFKC.java and nfkc.c.

Hello Rick.

I believe the current behavior is intentional.  Libidn do not aim to
implement latest-and-greatest NFKC, it aim to implement the NFKC
functionality required for StringPrep and IDN.  As you may know,
StringPrep/IDN reference Unicode 3.2.0, and explicitly says any later
changes (which I consider PR29 as) do not apply.

In fact, I believe that would I incorporate the changes suggested in
PR29, I would in fact be violating the IDN specifications.

Thanks for looking into the code and finding the place where the
change could be made.  I'll see if I can mention this in the manual
somewhere, for technically interested readers.

Regards,
Simon
</pre>

<div class="node">
<p><hr>
<a name="Copying-Information"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Function-and-Variable-Index">Function and Variable Index</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#PR29-discussion">PR29 discussion</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="appendix">Appendix B Copying Information</h2>

<ul class="menu">
<li><a accesskey="1" href="#GNU-Free-Documentation-License">GNU Free Documentation License</a>:    License for copying this manual. 
<li><a accesskey="2" href="#GNU-LGPL">GNU LGPL</a>:                          License for copying the library. 
<li><a accesskey="3" href="#GNU-GPL">GNU GPL</a>:                           License for copying the programs. 
</ul>

<div class="node">
<p><hr>
<a name="GNU-Free-Documentation-License"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#GNU-LGPL">GNU LGPL</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Copying-Information">Copying Information</a>

</div>

<h3 class="appendixsec">B.1 GNU Free Documentation License</h3>

<p><a name="index-FDL_002c-GNU-Free-Documentation-License-121"></a><div align="center">Version 1.2, November 2002</div>

<pre class="display">     Copyright &copy; 2000,2001,2002 Free Software Foundation, Inc.
     51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA
     
     Everyone is permitted to copy and distribute verbatim copies
     of this license document, but changing it is not allowed.
</pre>
     <ol type=1 start=0>
<li>PREAMBLE

     <p>The purpose of this License is to make a manual, textbook, or other
functional and useful document <dfn>free</dfn> in the sense of freedom: to
assure everyone the effective freedom to copy and redistribute it,
with or without modifying it, either commercially or noncommercially. 
Secondarily, this License preserves for the author and publisher a way
to get credit for their work, while not being considered responsible
for modifications made by others.

     <p>This License is a kind of &ldquo;copyleft&rdquo;, which means that derivative
works of the document must themselves be free in the same sense.  It
complements the GNU General Public License, which is a copyleft
license designed for free software.

     <p>We have designed this License in order to use it for manuals for free
software, because free software needs free documentation: a free
program should come with manuals providing the same freedoms that the
software does.  But this License is not limited to software manuals;
it can be used for any textual work, regardless of subject matter or
whether it is published as a printed book.  We recommend this License
principally for works whose purpose is instruction or reference.

     <li>APPLICABILITY AND DEFINITIONS

     <p>This License applies to any manual or other work, in any medium, that
contains a notice placed by the copyright holder saying it can be
distributed under the terms of this License.  Such a notice grants a
world-wide, royalty-free license, unlimited in duration, to use that
work under the conditions stated herein.  The &ldquo;Document&rdquo;, below,
refers to any such manual or work.  Any member of the public is a
licensee, and is addressed as &ldquo;you&rdquo;.  You accept the license if you
copy, modify or distribute the work in a way requiring permission
under copyright law.

     <p>A &ldquo;Modified Version&rdquo; of the Document means any work containing the
Document or a portion of it, either copied verbatim, or with
modifications and/or translated into another language.

     <p>A &ldquo;Secondary Section&rdquo; is a named appendix or a front-matter section
of the Document that deals exclusively with the relationship of the
publishers or authors of the Document to the Document's overall
subject (or to related matters) and contains nothing that could fall
directly within that overall subject.  (Thus, if the Document is in
part a textbook of mathematics, a Secondary Section may not explain
any mathematics.)  The relationship could be a matter of historical
connection with the subject or with related matters, or of legal,
commercial, philosophical, ethical or political position regarding
them.

     <p>The &ldquo;Invariant Sections&rdquo; are certain Secondary Sections whose titles
are designated, as being those of Invariant Sections, in the notice
that says that the Document is released under this License.  If a
section does not fit the above definition of Secondary then it is not
allowed to be designated as Invariant.  The Document may contain zero
Invariant Sections.  If the Document does not identify any Invariant
Sections then there are none.

     <p>The &ldquo;Cover Texts&rdquo; are certain short passages of text that are listed,
as Front-Cover Texts or Back-Cover Texts, in the notice that says that
the Document is released under this License.  A Front-Cover Text may
be at most 5 words, and a Back-Cover Text may be at most 25 words.

     <p>A &ldquo;Transparent&rdquo; copy of the Document means a machine-readable copy,
represented in a format whose specification is available to the
general public, that is suitable for revising the document
straightforwardly with generic text editors or (for images composed of
pixels) generic paint programs or (for drawings) some widely available
drawing editor, and that is suitable for input to text formatters or
for automatic translation to a variety of formats suitable for input
to text formatters.  A copy made in an otherwise Transparent file
format whose markup, or absence of markup, has been arranged to thwart
or discourage subsequent modification by readers is not Transparent. 
An image format is not Transparent if used for any substantial amount
of text.  A copy that is not &ldquo;Transparent&rdquo; is called &ldquo;Opaque&rdquo;.

     <p>Examples of suitable formats for Transparent copies include plain
<span class="sc">ascii</span> without markup, Texinfo input format, LaTeX input
format, <acronym>SGML</acronym> or <acronym>XML</acronym> using a publicly available
<acronym>DTD</acronym>, and standard-conforming simple <acronym>HTML</acronym>,
PostScript or <acronym>PDF</acronym> designed for human modification.  Examples
of transparent image formats include <acronym>PNG</acronym>, <acronym>XCF</acronym> and
<acronym>JPG</acronym>.  Opaque formats include proprietary formats that can be
read and edited only by proprietary word processors, <acronym>SGML</acronym> or
<acronym>XML</acronym> for which the <acronym>DTD</acronym> and/or processing tools are
not generally available, and the machine-generated <acronym>HTML</acronym>,
PostScript or <acronym>PDF</acronym> produced by some word processors for
output purposes only.

     <p>The &ldquo;Title Page&rdquo; means, for a printed book, the title page itself,
plus such following pages as are needed to hold, legibly, the material
this License requires to appear in the title page.  For works in
formats which do not have any title page as such, &ldquo;Title Page&rdquo; means
the text near the most prominent appearance of the work's title,
preceding the beginning of the body of the text.

     <p>A section &ldquo;Entitled XYZ&rdquo; means a named subunit of the Document whose
title either is precisely XYZ or contains XYZ in parentheses following
text that translates XYZ in another language.  (Here XYZ stands for a
specific section name mentioned below, such as &ldquo;Acknowledgements&rdquo;,
&ldquo;Dedications&rdquo;, &ldquo;Endorsements&rdquo;, or &ldquo;History&rdquo;.)  To &ldquo;Preserve the Title&rdquo;
of such a section when you modify the Document means that it remains a
section &ldquo;Entitled XYZ&rdquo; according to this definition.

     <p>The Document may include Warranty Disclaimers next to the notice which
states that this License applies to the Document.  These Warranty
Disclaimers are considered to be included by reference in this
License, but only as regards disclaiming warranties: any other
implication that these Warranty Disclaimers may have is void and has
no effect on the meaning of this License.

     <li>VERBATIM COPYING

     <p>You may copy and distribute the Document in any medium, either
commercially or noncommercially, provided that this License, the
copyright notices, and the license notice saying this License applies
to the Document are reproduced in all copies, and that you add no other
conditions whatsoever to those of this License.  You may not use
technical measures to obstruct or control the reading or further
copying of the copies you make or distribute.  However, you may accept
compensation in exchange for copies.  If you distribute a large enough
number of copies you must also follow the conditions in section 3.

     <p>You may also lend copies, under the same conditions stated above, and
you may publicly display copies.

     <li>COPYING IN QUANTITY

     <p>If you publish printed copies (or copies in media that commonly have
printed covers) of the Document, numbering more than 100, and the
Document's license notice requires Cover Texts, you must enclose the
copies in covers that carry, clearly and legibly, all these Cover
Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on
the back cover.  Both covers must also clearly and legibly identify
you as the publisher of these copies.  The front cover must present
the full title with all words of the title equally prominent and
visible.  You may add other material on the covers in addition. 
Copying with changes limited to the covers, as long as they preserve
the title of the Document and satisfy these conditions, can be treated
as verbatim copying in other respects.

     <p>If the required texts for either cover are too voluminous to fit
legibly, you should put the first ones listed (as many as fit
reasonably) on the actual cover, and continue the rest onto adjacent
pages.

     <p>If you publish or distribute Opaque copies of the Document numbering
more than 100, you must either include a machine-readable Transparent
copy along with each Opaque copy, or state in or with each Opaque copy
a computer-network location from which the general network-using
public has access to download using public-standard network protocols
a complete Transparent copy of the Document, free of added material. 
If you use the latter option, you must take reasonably prudent steps,
when you begin distribution of Opaque copies in quantity, to ensure
that this Transparent copy will remain thus accessible at the stated
location until at least one year after the last time you distribute an
Opaque copy (directly or through your agents or retailers) of that
edition to the public.

     <p>It is requested, but not required, that you contact the authors of the
Document well before redistributing any large number of copies, to give
them a chance to provide you with an updated version of the Document.

     <li>MODIFICATIONS

     <p>You may copy and distribute a Modified Version of the Document under
the conditions of sections 2 and 3 above, provided that you release
the Modified Version under precisely this License, with the Modified
Version filling the role of the Document, thus licensing distribution
and modification of the Modified Version to whoever possesses a copy
of it.  In addition, you must do these things in the Modified Version:

          <ol type=A start=1>
<li>Use in the Title Page (and on the covers, if any) a title distinct
from that of the Document, and from those of previous versions
(which should, if there were any, be listed in the History section
of the Document).  You may use the same title as a previous version
if the original publisher of that version gives permission.

          <li>List on the Title Page, as authors, one or more persons or entities
responsible for authorship of the modifications in the Modified
Version, together with at least five of the principal authors of the
Document (all of its principal authors, if it has fewer than five),
unless they release you from this requirement.

          <li>State on the Title page the name of the publisher of the
Modified Version, as the publisher.

          <li>Preserve all the copyright notices of the Document.

          <li>Add an appropriate copyright notice for your modifications
adjacent to the other copyright notices.

          <li>Include, immediately after the copyright notices, a license notice
giving the public permission to use the Modified Version under the
terms of this License, in the form shown in the Addendum below.

          <li>Preserve in that license notice the full lists of Invariant Sections
and required Cover Texts given in the Document's license notice.

          <li>Include an unaltered copy of this License.

          <li>Preserve the section Entitled &ldquo;History&rdquo;, Preserve its Title, and add
to it an item stating at least the title, year, new authors, and
publisher of the Modified Version as given on the Title Page.  If
there is no section Entitled &ldquo;History&rdquo; in the Document, create one
stating the title, year, authors, and publisher of the Document as
given on its Title Page, then add an item describing the Modified
Version as stated in the previous sentence.

          <li>Preserve the network location, if any, given in the Document for
public access to a Transparent copy of the Document, and likewise
the network locations given in the Document for previous versions
it was based on.  These may be placed in the &ldquo;History&rdquo; section. 
You may omit a network location for a work that was published at
least four years before the Document itself, or if the original
publisher of the version it refers to gives permission.

          <li>For any section Entitled &ldquo;Acknowledgements&rdquo; or &ldquo;Dedications&rdquo;, Preserve
the Title of the section, and preserve in the section all the
substance and tone of each of the contributor acknowledgements and/or
dedications given therein.

          <li>Preserve all the Invariant Sections of the Document,
unaltered in their text and in their titles.  Section numbers
or the equivalent are not considered part of the section titles.

          <li>Delete any section Entitled &ldquo;Endorsements&rdquo;.  Such a section
may not be included in the Modified Version.

          <li>Do not retitle any existing section to be Entitled &ldquo;Endorsements&rdquo; or
to conflict in title with any Invariant Section.

          <li>Preserve any Warranty Disclaimers.
          </ol>

     <p>If the Modified Version includes new front-matter sections or
appendices that qualify as Secondary Sections and contain no material
copied from the Document, you may at your option designate some or all
of these sections as invariant.  To do this, add their titles to the
list of Invariant Sections in the Modified Version's license notice. 
These titles must be distinct from any other section titles.

     <p>You may add a section Entitled &ldquo;Endorsements&rdquo;, provided it contains
nothing but endorsements of your Modified Version by various
parties&mdash;for example, statements of peer review or that the text has
been approved by an organization as the authoritative definition of a
standard.

     <p>You may add a passage of up to five words as a Front-Cover Text, and a
passage of up to 25 words as a Back-Cover Text, to the end of the list
of Cover Texts in the Modified Version.  Only one passage of
Front-Cover Text and one of Back-Cover Text may be added by (or
through arrangements made by) any one entity.  If the Document already
includes a cover text for the same cover, previously added by you or
by arrangement made by the same entity you are acting on behalf of,
you may not add another; but you may replace the old one, on explicit
permission from the previous publisher that added the old one.

     <p>The author(s) and publisher(s) of the Document do not by this License
give permission to use their names for publicity for or to assert or
imply endorsement of any Modified Version.

     <li>COMBINING DOCUMENTS

     <p>You may combine the Document with other documents released under this
License, under the terms defined in section 4 above for modified
versions, provided that you include in the combination all of the
Invariant Sections of all of the original documents, unmodified, and
list them all as Invariant Sections of your combined work in its
license notice, and that you preserve all their Warranty Disclaimers.

     <p>The combined work need only contain one copy of this License, and
multiple identical Invariant Sections may be replaced with a single
copy.  If there are multiple Invariant Sections with the same name but
different contents, make the title of each such section unique by
adding at the end of it, in parentheses, the name of the original
author or publisher of that section if known, or else a unique number. 
Make the same adjustment to the section titles in the list of
Invariant Sections in the license notice of the combined work.

     <p>In the combination, you must combine any sections Entitled &ldquo;History&rdquo;
in the various original documents, forming one section Entitled
&ldquo;History&rdquo;; likewise combine any sections Entitled &ldquo;Acknowledgements&rdquo;,
and any sections Entitled &ldquo;Dedications&rdquo;.  You must delete all
sections Entitled &ldquo;Endorsements.&rdquo;

     <li>COLLECTIONS OF DOCUMENTS

     <p>You may make a collection consisting of the Document and other documents
released under this License, and replace the individual copies of this
License in the various documents with a single copy that is included in
the collection, provided that you follow the rules of this License for
verbatim copying of each of the documents in all other respects.

     <p>You may extract a single document from such a collection, and distribute
it individually under this License, provided you insert a copy of this
License into the extracted document, and follow this License in all
other respects regarding verbatim copying of that document.

     <li>AGGREGATION WITH INDEPENDENT WORKS

     <p>A compilation of the Document or its derivatives with other separate
and independent documents or works, in or on a volume of a storage or
distribution medium, is called an &ldquo;aggregate&rdquo; if the copyright
resulting from the compilation is not used to limit the legal rights
of the compilation's users beyond what the individual works permit. 
When the Document is included in an aggregate, this License does not
apply to the other works in the aggregate which are not themselves
derivative works of the Document.

     <p>If the Cover Text requirement of section 3 is applicable to these
copies of the Document, then if the Document is less than one half of
the entire aggregate, the Document's Cover Texts may be placed on
covers that bracket the Document within the aggregate, or the
electronic equivalent of covers if the Document is in electronic form. 
Otherwise they must appear on printed covers that bracket the whole
aggregate.

     <li>TRANSLATION

     <p>Translation is considered a kind of modification, so you may
distribute translations of the Document under the terms of section 4. 
Replacing Invariant Sections with translations requires special
permission from their copyright holders, but you may include
translations of some or all Invariant Sections in addition to the
original versions of these Invariant Sections.  You may include a
translation of this License, and all the license notices in the
Document, and any Warranty Disclaimers, provided that you also include
the original English version of this License and the original versions
of those notices and disclaimers.  In case of a disagreement between
the translation and the original version of this License or a notice
or disclaimer, the original version will prevail.

     <p>If a section in the Document is Entitled &ldquo;Acknowledgements&rdquo;,
&ldquo;Dedications&rdquo;, or &ldquo;History&rdquo;, the requirement (section 4) to Preserve
its Title (section 1) will typically require changing the actual
title.

     <li>TERMINATION

     <p>You may not copy, modify, sublicense, or distribute the Document except
as expressly provided for under this License.  Any other attempt to
copy, modify, sublicense or distribute the Document is void, and will
automatically terminate your rights under this License.  However,
parties who have received copies, or rights, from you under this
License will not have their licenses terminated so long as such
parties remain in full compliance.

     <li>FUTURE REVISIONS OF THIS LICENSE

     <p>The Free Software Foundation may publish new, revised versions
of the GNU Free Documentation License from time to time.  Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.  See
<a href="http://www.gnu.org/copyleft/">http://www.gnu.org/copyleft/</a>.

     <p>Each version of the License is given a distinguishing version number. 
If the Document specifies that a particular numbered version of this
License &ldquo;or any later version&rdquo; applies to it, you have the option of
following the terms and conditions either of that specified version or
of any later version that has been published (not as a draft) by the
Free Software Foundation.  If the Document does not specify a version
number of this License, you may choose any version ever published (not
as a draft) by the Free Software Foundation.
        </ol>

<h3 class="heading">ADDENDUM: How to use this License for your documents</h3>

<p>To use this License in a document you have written, include a copy of
the License in the document and put the following copyright and
license notices just after the title page:

<pre class="smallexample">       Copyright (C)  <var>year</var>  <var>your name</var>.
       Permission is granted to copy, distribute and/or modify this document
       under the terms of the GNU Free Documentation License, Version 1.2
       or any later version published by the Free Software Foundation;
       with no Invariant Sections, no Front-Cover Texts, and no Back-Cover
       Texts.  A copy of the license is included in the section entitled ``GNU
       Free Documentation License''.
</pre>
   <p>If you have Invariant Sections, Front-Cover Texts and Back-Cover Texts,
replace the &ldquo;with...Texts.&rdquo; line with this:

<pre class="smallexample">         with the Invariant Sections being <var>list their titles</var>, with
         the Front-Cover Texts being <var>list</var>, and with the Back-Cover Texts
         being <var>list</var>.
</pre>
   <p>If you have Invariant Sections without Cover Texts, or some other
combination of the three, merge those two alternatives to suit the
situation.

   <p>If your document contains nontrivial examples of program code, we
recommend releasing these examples in parallel under your choice of
free software license, such as the GNU General Public License,
to permit their use in free software.

<!-- Local Variables: -->
<!-- ispell-local-pdict: "ispell-dict" -->
<!-- End: -->
<div class="node">
<p><hr>
<a name="GNU-LGPL"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#GNU-GPL">GNU GPL</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#GNU-Free-Documentation-License">GNU Free Documentation License</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Copying-Information">Copying Information</a>

</div>

<h3 class="appendixsec">B.2 GNU Lesser General Public License</h3>

<p><a name="index-LGPL_002c-GNU-Lesser-General-Public-License-122"></a><a name="index-License_002c-GNU-LGPL-123"></a><div align="center">Version 2.1, February 1999</div>

<pre class="display">     Copyright &copy; 1991, 1999 Free Software Foundation, Inc.
     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
     
     Everyone is permitted to copy and distribute verbatim copies
     of this license document, but changing it is not allowed.
     
     [This is the first released version of the Lesser GPL.  It also counts
     as the successor of the GNU Library Public License, version 2, hence the
     version number 2.1.]
</pre>
<h4 class="subheading">Preamble</h4>

<p>The licenses for most software are designed to take away your
freedom to share and change it.  By contrast, the GNU General Public
Licenses are intended to guarantee your freedom to share and change
free software&mdash;to make sure the software is free for all its users.

   <p>This license, the Lesser General Public License, applies to some
specially designated software&mdash;typically libraries&mdash;of the Free
Software Foundation and other authors who decide to use it.  You can use
it too, but we suggest you first think carefully about whether this
license or the ordinary General Public License is the better strategy to
use in any particular case, based on the explanations below.

   <p>When we speak of free software, we are referring to freedom of use,
not price.  Our General Public Licenses are designed to make sure that
you have the freedom to distribute copies of free software (and charge
for this service if you wish); that you receive source code or can get
it if you want it; that you can change the software and use pieces of it
in new free programs; and that you are informed that you can do these
things.

   <p>To protect your rights, we need to make restrictions that forbid
distributors to deny you these rights or to ask you to surrender these
rights.  These restrictions translate to certain responsibilities for
you if you distribute copies of the library or if you modify it.

   <p>For example, if you distribute copies of the library, whether gratis
or for a fee, you must give the recipients all the rights that we gave
you.  You must make sure that they, too, receive or can get the source
code.  If you link other code with the library, you must provide
complete object files to the recipients, so that they can relink them
with the library after making changes to the library and recompiling
it.  And you must show them these terms so they know their rights.

   <p>We protect your rights with a two-step method: (1) we copyright the
library, and (2) we offer you this license, which gives you legal
permission to copy, distribute and/or modify the library.

   <p>To protect each distributor, we want to make it very clear that
there is no warranty for the free library.  Also, if the library is
modified by someone else and passed on, the recipients should know
that what they have is not the original version, so that the original
author's reputation will not be affected by problems that might be
introduced by others.

   <p>Finally, software patents pose a constant threat to the existence of
any free program.  We wish to make sure that a company cannot
effectively restrict the users of a free program by obtaining a
restrictive license from a patent holder.  Therefore, we insist that
any patent license obtained for a version of the library must be
consistent with the full freedom of use specified in this license.

   <p>Most GNU software, including some libraries, is covered by the
ordinary GNU General Public License.  This license, the GNU Lesser
General Public License, applies to certain designated libraries, and
is quite different from the ordinary General Public License.  We use
this license for certain libraries in order to permit linking those
libraries into non-free programs.

   <p>When a program is linked with a library, whether statically or using
a shared library, the combination of the two is legally speaking a
combined work, a derivative of the original library.  The ordinary
General Public License therefore permits such linking only if the
entire combination fits its criteria of freedom.  The Lesser General
Public License permits more lax criteria for linking other code with
the library.

   <p>We call this license the <dfn>Lesser</dfn> General Public License because it
does <em>Less</em> to protect the user's freedom than the ordinary General
Public License.  It also provides other free software developers Less
of an advantage over competing non-free programs.  These disadvantages
are the reason we use the ordinary General Public License for many
libraries.  However, the Lesser license provides advantages in certain
special circumstances.

   <p>For example, on rare occasions, there may be a special need to
encourage the widest possible use of a certain library, so that it becomes
a de-facto standard.  To achieve this, non-free programs must be
allowed to use the library.  A more frequent case is that a free
library does the same job as widely used non-free libraries.  In this
case, there is little to gain by limiting the free library to free
software only, so we use the Lesser General Public License.

   <p>In other cases, permission to use a particular library in non-free
programs enables a greater number of people to use a large body of
free software.  For example, permission to use the GNU C Library in
non-free programs enables many more people to use the whole GNU
operating system, as well as its variant, the GNU/Linux operating
system.

   <p>Although the Lesser General Public License is Less protective of the
users' freedom, it does ensure that the user of a program that is
linked with the Library has the freedom and the wherewithal to run
that program using a modified version of the Library.

   <p>The precise terms and conditions for copying, distribution and
modification follow.  Pay close attention to the difference between a
&ldquo;work based on the library&rdquo; and a &ldquo;work that uses the library&rdquo;.  The
former contains code derived from the library, whereas the latter must
be combined with the library in order to run.

<h4 class="subheading">TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION</h4>

     <ol type=1 start=0>
<li>This License Agreement applies to any software library or other program
which contains a notice placed by the copyright holder or other
authorized party saying it may be distributed under the terms of this
Lesser General Public License (also called &ldquo;this License&rdquo;).  Each
licensee is addressed as &ldquo;you&rdquo;.

     <p>A &ldquo;library&rdquo; means a collection of software functions and/or data
prepared so as to be conveniently linked with application programs
(which use some of those functions and data) to form executables.

     <p>The &ldquo;Library&rdquo;, below, refers to any such software library or work
which has been distributed under these terms.  A &ldquo;work based on the
Library&rdquo; means either the Library or any derivative work under
copyright law: that is to say, a work containing the Library or a
portion of it, either verbatim or with modifications and/or translated
straightforwardly into another language.  (Hereinafter, translation is
included without limitation in the term &ldquo;modification&rdquo;.)

     <p>&ldquo;Source code&rdquo; for a work means the preferred form of the work for
making modifications to it.  For a library, complete source code means
all the source code for all modules it contains, plus any associated
interface definition files, plus the scripts used to control compilation
and installation of the library.

     <p>Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope.  The act of
running a program using the Library is not restricted, and output from
such a program is covered only if its contents constitute a work based
on the Library (independent of the use of the Library in a tool for
writing it).  Whether that is true depends on what the Library does
and what the program that uses the Library does.

     <li>You may copy and distribute verbatim copies of the Library's
complete source code as you receive it, in any medium, provided that
you conspicuously and appropriately publish on each copy an
appropriate copyright notice and disclaimer of warranty; keep intact
all the notices that refer to this License and to the absence of any
warranty; and distribute a copy of this License along with the
Library.

     <p>You may charge a fee for the physical act of transferring a copy,
and you may at your option offer warranty protection in exchange for a
fee.

     <li>You may modify your copy or copies of the Library or any portion
of it, thus forming a work based on the Library, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:

          <ol type=a start=1>
<li>The modified work must itself be a software library.

          <li>You must cause the files modified to carry prominent notices
stating that you changed the files and the date of any change.

          <li>You must cause the whole of the work to be licensed at no
charge to all third parties under the terms of this License.

          <li>If a facility in the modified Library refers to a function or a
table of data to be supplied by an application program that uses
the facility, other than as an argument passed when the facility
is invoked, then you must make a good faith effort to ensure that,
in the event an application does not supply such function or
table, the facility still operates, and performs whatever part of
its purpose remains meaningful.

          <p>(For example, a function in a library to compute square roots has
a purpose that is entirely well-defined independent of the
application.  Therefore, Subsection 2d requires that any
application-supplied function or table used by this function must
be optional: if the application does not supply it, the square
root function must still compute square roots.)
          </ol>

     <p>These requirements apply to the modified work as a whole.  If
identifiable sections of that work are not derived from the Library,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works.  But when you
distribute the same sections as part of a whole which is a work based
on the Library, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote
it.

     <p>Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Library.

     <p>In addition, mere aggregation of another work not based on the Library
with the Library (or with a work based on the Library) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.

     <li>You may opt to apply the terms of the ordinary GNU General Public
License instead of this License to a given copy of the Library.  To do
this, you must alter all the notices that refer to this License, so
that they refer to the ordinary GNU General Public License, version 2,
instead of to this License.  (If a newer version than version 2 of the
ordinary GNU General Public License has appeared, then you can specify
that version instead if you wish.)  Do not make any other change in
these notices.

     <p>Once this change is made in a given copy, it is irreversible for
that copy, so the ordinary GNU General Public License applies to all
subsequent copies and derivative works made from that copy.

     <p>This option is useful when you wish to copy part of the code of
the Library into a program that is not a library.

     <li>You may copy and distribute the Library (or a portion or
derivative of it, under Section 2) in object code or executable form
under the terms of Sections 1 and 2 above provided that you accompany
it with the complete corresponding machine-readable source code, which
must be distributed under the terms of Sections 1 and 2 above on a
medium customarily used for software interchange.

     <p>If distribution of object code is made by offering access to copy
from a designated place, then offering equivalent access to copy the
source code from the same place satisfies the requirement to
distribute the source code, even though third parties are not
compelled to copy the source along with the object code.

     <li>A program that contains no derivative of any portion of the
Library, but is designed to work with the Library by being compiled or
linked with it, is called a &ldquo;work that uses the Library&rdquo;.  Such a
work, in isolation, is not a derivative work of the Library, and
therefore falls outside the scope of this License.

     <p>However, linking a &ldquo;work that uses the Library&rdquo; with the Library
creates an executable that is a derivative of the Library (because it
contains portions of the Library), rather than a &ldquo;work that uses the
library&rdquo;.  The executable is therefore covered by this License. 
Section 6 states terms for distribution of such executables.

     <p>When a &ldquo;work that uses the Library&rdquo; uses material from a header file
that is part of the Library, the object code for the work may be a
derivative work of the Library even though the source code is not. 
Whether this is true is especially significant if the work can be
linked without the Library, or if the work is itself a library.  The
threshold for this to be true is not precisely defined by law.

     <p>If such an object file uses only numerical parameters, data
structure layouts and accessors, and small macros and small inline
functions (ten lines or less in length), then the use of the object
file is unrestricted, regardless of whether it is legally a derivative
work.  (Executables containing this object code plus portions of the
Library will still fall under Section 6.)

     <p>Otherwise, if the work is a derivative of the Library, you may
distribute the object code for the work under the terms of Section 6. 
Any executables containing that work also fall under Section 6,
whether or not they are linked directly with the Library itself.

     <li>As an exception to the Sections above, you may also combine or
link a &ldquo;work that uses the Library&rdquo; with the Library to produce a
work containing portions of the Library, and distribute that work
under terms of your choice, provided that the terms permit
modification of the work for the customer's own use and reverse
engineering for debugging such modifications.

     <p>You must give prominent notice with each copy of the work that the
Library is used in it and that the Library and its use are covered by
this License.  You must supply a copy of this License.  If the work
during execution displays copyright notices, you must include the
copyright notice for the Library among them, as well as a reference
directing the user to the copy of this License.  Also, you must do one
of these things:

          <ol type=a start=1>
<li>Accompany the work with the complete corresponding
machine-readable source code for the Library including whatever
changes were used in the work (which must be distributed under
Sections 1 and 2 above); and, if the work is an executable linked
with the Library, with the complete machine-readable &ldquo;work that
uses the Library&rdquo;, as object code and/or source code, so that the
user can modify the Library and then relink to produce a modified
executable containing the modified Library.  (It is understood
that the user who changes the contents of definitions files in the
Library will not necessarily be able to recompile the application
to use the modified definitions.)

          <li>Use a suitable shared library mechanism for linking with the Library.  A
suitable mechanism is one that (1) uses at run time a copy of the
library already present on the user's computer system, rather than
copying library functions into the executable, and (2) will operate
properly with a modified version of the library, if the user installs
one, as long as the modified version is interface-compatible with the
version that the work was made with.

          <li>Accompany the work with a written offer, valid for at
least three years, to give the same user the materials
specified in Subsection 6a, above, for a charge no more
than the cost of performing this distribution.

          <li>If distribution of the work is made by offering access to copy
from a designated place, offer equivalent access to copy the above
specified materials from the same place.

          <li>Verify that the user has already received a copy of these
materials or that you have already sent this user a copy.
          </ol>

     <p>For an executable, the required form of the &ldquo;work that uses the
Library&rdquo; must include any data and utility programs needed for
reproducing the executable from it.  However, as a special exception,
the materials to be distributed need not include anything that is
normally distributed (in either source or binary form) with the major
components (compiler, kernel, and so on) of the operating system on
which the executable runs, unless that component itself accompanies the
executable.

     <p>It may happen that this requirement contradicts the license
restrictions of other proprietary libraries that do not normally
accompany the operating system.  Such a contradiction means you cannot
use both them and the Library together in an executable that you
distribute.

     <li>You may place library facilities that are a work based on the
Library side-by-side in a single library together with other library
facilities not covered by this License, and distribute such a combined
library, provided that the separate distribution of the work based on
the Library and of the other library facilities is otherwise
permitted, and provided that you do these two things:

          <ol type=a start=1>
<li>Accompany the combined library with a copy of the same work
based on the Library, uncombined with any other library
facilities.  This must be distributed under the terms of the
Sections above.

          <li>Give prominent notice with the combined library of the fact
that part of it is a work based on the Library, and explaining
where to find the accompanying uncombined form of the same work.
          </ol>

     <li>You may not copy, modify, sublicense, link with, or distribute
the Library except as expressly provided under this License.  Any
attempt otherwise to copy, modify, sublicense, link with, or
distribute the Library is void, and will automatically terminate your
rights under this License.  However, parties who have received copies,
or rights, from you under this License will not have their licenses
terminated so long as such parties remain in full compliance.

     <li>You are not required to accept this License, since you have not
signed it.  However, nothing else grants you permission to modify or
distribute the Library or its derivative works.  These actions are
prohibited by law if you do not accept this License.  Therefore, by
modifying or distributing the Library (or any work based on the
Library), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Library or works based on it.

     <li>Each time you redistribute the Library (or any work based on the
Library), the recipient automatically receives a license from the
original licensor to copy, distribute, link with or modify the Library
subject to these terms and conditions.  You may not impose any further
restrictions on the recipients' exercise of the rights granted herein. 
You are not responsible for enforcing compliance by third parties with
this License.

     <li>If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License.  If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Library at all.  For example, if a patent
license would not permit royalty-free redistribution of the Library by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Library.

     <p>If any portion of this section is held invalid or unenforceable under any
particular circumstance, the balance of the section is intended to apply,
and the section as a whole is intended to apply in other circumstances.

     <p>It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system which is
implemented by public license practices.  Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.

     <p>This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.

     <li>If the distribution and/or use of the Library is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Library under this License may add
an explicit geographical distribution limitation excluding those countries,
so that distribution is permitted only in or among countries not thus
excluded.  In such case, this License incorporates the limitation as if
written in the body of this License.

     <li>The Free Software Foundation may publish revised and/or new
versions of the Lesser General Public License from time to time. 
Such new versions will be similar in spirit to the present version,
but may differ in detail to address new problems or concerns.

     <p>Each version is given a distinguishing version number.  If the Library
specifies a version number of this License which applies to it and
&ldquo;any later version&rdquo;, you have the option of following the terms and
conditions either of that version or of any later version published by
the Free Software Foundation.  If the Library does not specify a
license version number, you may choose any version ever published by
the Free Software Foundation.

     <li>If you wish to incorporate parts of the Library into other free
programs whose distribution conditions are incompatible with these,
write to the author to ask for permission.  For software which is
copyrighted by the Free Software Foundation, write to the Free
Software Foundation; we sometimes make exceptions for this.  Our
decision will be guided by the two goals of preserving the free status
of all derivatives of our free software and of promoting the sharing
and reuse of software generally.

     <li>BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. 
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
OTHER PARTIES PROVIDE THE LIBRARY &ldquo;AS IS&rdquo; WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
LIBRARY IS WITH YOU.  SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.

     <li>IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.
     </ol>

<h4 class="subheading">How to Apply These Terms to Your New Libraries</h4>

<p>If you develop a new library, and you want it to be of the greatest
possible use to the public, we recommend making it free software that
everyone can redistribute and change.  You can do so by permitting
redistribution under these terms (or, alternatively, under the terms of the
ordinary General Public License).

   <p>To apply these terms, attach the following notices to the library.  It is
safest to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least the
&ldquo;copyright&rdquo; line and a pointer to where the full notice is found.

<pre class="smallexample">     <var>one line to give the library's name and an idea of what it does.</var>
     Copyright (C) <var>year</var>  <var>name of author</var>
     
     This library is free software; you can redistribute it and/or modify it
     under the terms of the GNU Lesser General Public License as published by
     the Free Software Foundation; either version 2.1 of the License, or (at
     your option) any later version.
     
     This library 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
     Lesser General Public License for more details.
     
     You should have received a copy of the GNU Lesser General Public
     License along with this library; if not, write to the Free Software
     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
     USA.
</pre>
   <p>Also add information on how to contact you by electronic and paper mail.

   <p>You should also get your employer (if you work as a programmer) or your
school, if any, to sign a &ldquo;copyright disclaimer&rdquo; for the library, if
necessary.  Here is a sample; alter the names:

<pre class="smallexample">     Yoyodyne, Inc., hereby disclaims all copyright interest in the library
     `Frob' (a library for tweaking knobs) written by James Random Hacker.
     
     <var>signature of Ty Coon</var>, 1 April 1990
     Ty Coon, President of Vice
</pre>
   <p>That's all there is to it!

<div class="node">
<p><hr>
<a name="GNU-GPL"></a>
Previous:&nbsp;<a rel="previous" accesskey="p" href="#GNU-LGPL">GNU LGPL</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Copying-Information">Copying Information</a>

</div>

<h3 class="appendixsec">B.3 GNU General Public License</h3>

<p><a name="index-GPL_002c-GNU-General-Public-License-124"></a><a name="index-License_002c-GNU-GPL-125"></a><div align="center">Version 2, June 1991</div>

<!-- This file is intended to be included in another file. -->
<pre class="display">     Copyright &copy; 1989, 1991 Free Software Foundation, Inc.
     51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
     
     Everyone is permitted to copy and distribute verbatim copies
     of this license document, but changing it is not allowed.
</pre>
<h3 class="heading">Preamble</h3>

<p>The licenses for most software are designed to take away your
freedom to share and change it.  By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software&mdash;to make sure the software is free for all its users.  This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it.  (Some other Free Software Foundation software is covered by
the GNU Lesser General Public License instead.)  You can apply it to
your programs, too.

   <p>When we speak of free software, we are referring to freedom, not
price.  Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.

   <p>To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights. 
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.

   <p>For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have.  You must make sure that they, too, receive or can get the
source code.  And you must show them these terms so they know their
rights.

   <p>We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.

   <p>Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software.  If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.

   <p>Finally, any free program is threatened constantly by software
patents.  We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary.  To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.

   <p>The precise terms and conditions for copying, distribution and
modification follow.

<h3 class="heading">TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION</h3>

     <ol type=1 start=0>
<li>This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License.  The &ldquo;Program&rdquo;, below,
refers to any such program or work, and a &ldquo;work based on the Program&rdquo;
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language.  (Hereinafter, translation is included without limitation in
the term &ldquo;modification&rdquo;.)  Each licensee is addressed as &ldquo;you&rdquo;.

     <p>Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope.  The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program). 
Whether that is true depends on what the Program does.

     <li>You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.

     <p>You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.

     <li>You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:

          <ol type=a start=1>
<li>You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.

          <li>You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.

          <li>If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License.  (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
          </ol>

     <p>These requirements apply to the modified work as a whole.  If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works.  But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.

     <p>Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.

     <p>In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.

     <li>You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:

          <ol type=a start=1>
<li>Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,

          <li>Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,

          <li>Accompany it with the information you received as to the offer
to distribute corresponding source code.  (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
          </ol>

     <p>The source code for a work means the preferred form of the work for
making modifications to it.  For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable.  However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.

     <p>If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.

     <li>You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License.  Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License. 
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.

     <li>You are not required to accept this License, since you have not
signed it.  However, nothing else grants you permission to modify or
distribute the Program or its derivative works.  These actions are
prohibited by law if you do not accept this License.  Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.

     <li>Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions.  You may not impose any further
restrictions on the recipients' exercise of the rights granted herein. 
You are not responsible for enforcing compliance by third parties to
this License.

     <li>If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License.  If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all.  For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.

     <p>If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.

     <p>It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices.  Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.

     <p>This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.

     <li>If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded.  In such case, this License incorporates
the limitation as if written in the body of this License.

     <li>The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time.  Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.

     <p>Each version is given a distinguishing version number.  If the Program
specifies a version number of this License which applies to it and &ldquo;any
later version&rdquo;, you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation.  If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.

     <li>If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission.  For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this.  Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.

     <li>BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM &ldquo;AS IS&rdquo; WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.

     <li>IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
     </ol>

<h3 class="heading">Appendix: How to Apply These Terms to Your New Programs</h3>

<p>If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.

   <p>To do so, attach the following notices to the program.  It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the &ldquo;copyright&rdquo; line and a pointer to where the full notice is found.

<pre class="smallexample">     <var>one line to give the program's name and a brief idea of what it does.</var>
     Copyright (C) <var>yyyy</var>  <var>name of author</var>
     
     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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
</pre>
   <p>Also add information on how to contact you by electronic and paper mail.

   <p>If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:

<pre class="smallexample">     Gnomovision version 69, Copyright (C) <var>year</var> <var>name of author</var>
     Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
     This is free software, and you are welcome to redistribute it
     under certain conditions; type `show c' for details.
</pre>
   <p>The hypothetical commands `<samp><span class="samp">show w</span></samp>' and `<samp><span class="samp">show c</span></samp>' should show
the appropriate parts of the General Public License.  Of course, the
commands you use may be called something other than `<samp><span class="samp">show w</span></samp>' and
`<samp><span class="samp">show c</span></samp>'; they could even be mouse-clicks or menu items&mdash;whatever
suits your program.

   <p>You should also get your employer (if you work as a programmer) or your
school, if any, to sign a &ldquo;copyright disclaimer&rdquo; for the program, if
necessary.  Here is a sample; alter the names:

<pre class="example">     Yoyodyne, Inc., hereby disclaims all copyright interest in the program
     `Gnomovision' (which makes passes at compilers) written by James Hacker.
     
     <var>signature of Ty Coon</var>, 1 April 1989
     Ty Coon, President of Vice
</pre>
   <p>This General Public License does not permit incorporating your program into
proprietary programs.  If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library.  If this is what you want to do, use the GNU Lesser General
Public License instead of this License.

<div class="node">
<p><hr>
<a name="Function-and-Variable-Index"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Concept-Index">Concept Index</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Copying-Information">Copying Information</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="unnumbered">Function and Variable Index</h2>

<ul class="index-fn" compact>
<li><a href="#index-idna_002dto_002dascii-119"><code>idna-to-ascii</code></a>: <a href="#Emacs-API">Emacs API</a></li>
<li><a href="#index-idna_002dto_002dunicode-120"><code>idna-to-unicode</code></a>: <a href="#Emacs-API">Emacs API</a></li>
<li><a href="#index-idna_005fstrerror-86"><code>idna_strerror</code></a>: <a href="#IDNA-Functions">IDNA Functions</a></li>
<li><a href="#index-idna_005fto_005fascii_005f4i-76"><code>idna_to_ascii_4i</code></a>: <a href="#IDNA-Functions">IDNA Functions</a></li>
<li><a href="#index-idna_005fto_005fascii_005f4z-78"><code>idna_to_ascii_4z</code></a>: <a href="#IDNA-Functions">IDNA Functions</a></li>
<li><a href="#index-idna_005fto_005fascii_005f8z-79"><code>idna_to_ascii_8z</code></a>: <a href="#IDNA-Functions">IDNA Functions</a></li>
<li><a href="#index-idna_005fto_005fascii_005flz-80"><code>idna_to_ascii_lz</code></a>: <a href="#IDNA-Functions">IDNA Functions</a></li>
<li><a href="#index-idna_005fto_005funicode_005f44i-77"><code>idna_to_unicode_44i</code></a>: <a href="#IDNA-Functions">IDNA Functions</a></li>
<li><a href="#index-idna_005fto_005funicode_005f4z4z-81"><code>idna_to_unicode_4z4z</code></a>: <a href="#IDNA-Functions">IDNA Functions</a></li>
<li><a href="#index-idna_005fto_005funicode_005f8z4z-82"><code>idna_to_unicode_8z4z</code></a>: <a href="#IDNA-Functions">IDNA Functions</a></li>
<li><a href="#index-idna_005fto_005funicode_005f8z8z-83"><code>idna_to_unicode_8z8z</code></a>: <a href="#IDNA-Functions">IDNA Functions</a></li>
<li><a href="#index-idna_005fto_005funicode_005f8zlz-84"><code>idna_to_unicode_8zlz</code></a>: <a href="#IDNA-Functions">IDNA Functions</a></li>
<li><a href="#index-idna_005fto_005funicode_005flzlz-85"><code>idna_to_unicode_lzlz</code></a>: <a href="#IDNA-Functions">IDNA Functions</a></li>
<li><a href="#index-pr29_005f4-101"><code>pr29_4</code></a>: <a href="#PR29-Functions">PR29 Functions</a></li>
<li><a href="#index-pr29_005f4z-102"><code>pr29_4z</code></a>: <a href="#PR29-Functions">PR29 Functions</a></li>
<li><a href="#index-pr29_005f8z-103"><code>pr29_8z</code></a>: <a href="#PR29-Functions">PR29 Functions</a></li>
<li><a href="#index-pr29_005fstrerror-104"><code>pr29_strerror</code></a>: <a href="#PR29-Functions">PR29 Functions</a></li>
<li><a href="#index-punycode_002ddecode-114"><code>punycode-decode</code></a>: <a href="#Emacs-API">Emacs API</a></li>
<li><a href="#index-punycode_002dencode-113"><code>punycode-encode</code></a>: <a href="#Emacs-API">Emacs API</a></li>
<li><a href="#index-punycode_005fdecode-70"><code>punycode_decode</code></a>: <a href="#Punycode-Functions">Punycode Functions</a></li>
<li><a href="#index-punycode_005fencode-69"><code>punycode_encode</code></a>: <a href="#Punycode-Functions">Punycode Functions</a></li>
<li><a href="#index-punycode_005fstrerror-71"><code>punycode_strerror</code></a>: <a href="#Punycode-Functions">Punycode Functions</a></li>
<li><a href="#index-stringprep-59"><code>stringprep</code></a>: <a href="#Stringprep-Functions">Stringprep Functions</a></li>
<li><a href="#index-stringprep_005f4i-57"><code>stringprep_4i</code></a>: <a href="#Stringprep-Functions">Stringprep Functions</a></li>
<li><a href="#index-stringprep_005f4zi-58"><code>stringprep_4zi</code></a>: <a href="#Stringprep-Functions">Stringprep Functions</a></li>
<li><a href="#index-stringprep_005fcheck_005fversion-38"><code>stringprep_check_version</code></a>: <a href="#Version-Check">Version Check</a></li>
<li><a href="#index-stringprep_005fconvert-50"><code>stringprep_convert</code></a>: <a href="#Utility-Functions">Utility Functions</a></li>
<li><a href="#index-stringprep_005fiscsi-63"><code>stringprep_iscsi</code></a>: <a href="#Stringprep-Functions">Stringprep Functions</a></li>
<li><a href="#index-stringprep_005flocale_005fcharset-49"><code>stringprep_locale_charset</code></a>: <a href="#Utility-Functions">Utility Functions</a></li>
<li><a href="#index-stringprep_005flocale_005fto_005futf8-51"><code>stringprep_locale_to_utf8</code></a>: <a href="#Utility-Functions">Utility Functions</a></li>
<li><a href="#index-stringprep_005fnameprep_005fno_005funassigned-62"><code>stringprep_nameprep_no_unassigned</code></a>: <a href="#Stringprep-Functions">Stringprep Functions</a></li>
<li><a href="#index-stringprep_005fplain-64"><code>stringprep_plain</code></a>: <a href="#Stringprep-Functions">Stringprep Functions</a></li>
<li><a href="#index-stringprep_005fprofile-60"><code>stringprep_profile</code></a>: <a href="#Stringprep-Functions">Stringprep Functions</a></li>
<li><a href="#index-stringprep_005fstrerror-61"><code>stringprep_strerror</code></a>: <a href="#Stringprep-Functions">Stringprep Functions</a></li>
<li><a href="#index-stringprep_005fucs4_005fnfkc_005fnormalize-47"><code>stringprep_ucs4_nfkc_normalize</code></a>: <a href="#Utility-Functions">Utility Functions</a></li>
<li><a href="#index-stringprep_005fucs4_005fto_005futf8-45"><code>stringprep_ucs4_to_utf8</code></a>: <a href="#Utility-Functions">Utility Functions</a></li>
<li><a href="#index-stringprep_005funichar_005fto_005futf8-43"><code>stringprep_unichar_to_utf8</code></a>: <a href="#Utility-Functions">Utility Functions</a></li>
<li><a href="#index-stringprep_005futf8_005fnfkc_005fnormalize-48"><code>stringprep_utf8_nfkc_normalize</code></a>: <a href="#Utility-Functions">Utility Functions</a></li>
<li><a href="#index-stringprep_005futf8_005fto_005flocale-52"><code>stringprep_utf8_to_locale</code></a>: <a href="#Utility-Functions">Utility Functions</a></li>
<li><a href="#index-stringprep_005futf8_005fto_005fucs4-46"><code>stringprep_utf8_to_ucs4</code></a>: <a href="#Utility-Functions">Utility Functions</a></li>
<li><a href="#index-stringprep_005futf8_005fto_005funichar-44"><code>stringprep_utf8_to_unichar</code></a>: <a href="#Utility-Functions">Utility Functions</a></li>
<li><a href="#index-stringprep_005fxmpp_005fnodeprep-65"><code>stringprep_xmpp_nodeprep</code></a>: <a href="#Stringprep-Functions">Stringprep Functions</a></li>
<li><a href="#index-stringprep_005fxmpp_005fresourceprep-66"><code>stringprep_xmpp_resourceprep</code></a>: <a href="#Stringprep-Functions">Stringprep Functions</a></li>
<li><a href="#index-tld_005fcheck_005f4-95"><code>tld_check_4</code></a>: <a href="#TLD-Functions">TLD Functions</a></li>
<li><a href="#index-tld_005fcheck_005f4t-88"><code>tld_check_4t</code></a>: <a href="#TLD-Functions">TLD Functions</a></li>
<li><a href="#index-tld_005fcheck_005f4tz-89"><code>tld_check_4tz</code></a>: <a href="#TLD-Functions">TLD Functions</a></li>
<li><a href="#index-tld_005fcheck_005f4z-96"><code>tld_check_4z</code></a>: <a href="#TLD-Functions">TLD Functions</a></li>
<li><a href="#index-tld_005fcheck_005f8z-97"><code>tld_check_8z</code></a>: <a href="#TLD-Functions">TLD Functions</a></li>
<li><a href="#index-tld_005fcheck_005flz-98"><code>tld_check_lz</code></a>: <a href="#TLD-Functions">TLD Functions</a></li>
<li><a href="#index-tld_005fdefault_005ftable-94"><code>tld_default_table</code></a>: <a href="#TLD-Functions">TLD Functions</a></li>
<li><a href="#index-tld_005fget_005f4-90"><code>tld_get_4</code></a>: <a href="#TLD-Functions">TLD Functions</a></li>
<li><a href="#index-tld_005fget_005f4z-91"><code>tld_get_4z</code></a>: <a href="#TLD-Functions">TLD Functions</a></li>
<li><a href="#index-tld_005fget_005ftable-93"><code>tld_get_table</code></a>: <a href="#TLD-Functions">TLD Functions</a></li>
<li><a href="#index-tld_005fget_005fz-92"><code>tld_get_z</code></a>: <a href="#TLD-Functions">TLD Functions</a></li>
<li><a href="#index-tld_005fstrerror-99"><code>tld_strerror</code></a>: <a href="#TLD-Functions">TLD Functions</a></li>
   </ul><div class="node">
<p><hr>
<a name="Concept-Index"></a>
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Function-and-Variable-Index">Function and Variable Index</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="unnumbered">Concept Index</h2>



<ul class="index-cp" compact>
<li><a href="#index-AIX-15">AIX</a>: <a href="#Supported-Platforms">Supported Platforms</a></li>
<li><a href="#index-ARM-29">ARM</a>: <a href="#Supported-Platforms">Supported Platforms</a></li>
<li><a href="#index-Autoconf-tests-40">Autoconf tests</a>: <a href="#Autoconf-tests">Autoconf tests</a></li>
<li><a href="#index-command-line-108">command line</a>: <a href="#Invoking-idn">Invoking idn</a></li>
<li><a href="#index-Compiling-your-application-39">Compiling your application</a>: <a href="#Building-the-source">Building the source</a></li>
<li><a href="#index-Configure-tests-41">Configure tests</a>: <a href="#Autoconf-tests">Autoconf tests</a></li>
<li><a href="#index-Contributing-36">Contributing</a>: <a href="#Contributing">Contributing</a></li>
<li><a href="#index-Debian-1">Debian</a>: <a href="#Supported-Platforms">Supported Platforms</a></li>
<li><a href="#index-Download-34">Download</a>: <a href="#Downloading-and-Installing">Downloading and Installing</a></li>
<li><a href="#index-Examples-105">Examples</a>: <a href="#Examples">Examples</a></li>
<li><a href="#index-FDL_002c-GNU-Free-Documentation-License-121">FDL, GNU Free Documentation License</a>: <a href="#GNU-Free-Documentation-License">GNU Free Documentation License</a></li>
<li><a href="#index-FreeBSD-23">FreeBSD</a>: <a href="#Supported-Platforms">Supported Platforms</a></li>
<li><a href="#index-GPL_002c-GNU-General-Public-License-124">GPL, GNU General Public License</a>: <a href="#GNU-GPL">GNU GPL</a></li>
<li><a href="#index-Hacking-37">Hacking</a>: <a href="#Contributing">Contributing</a></li>
<li><a href="#index-HP_002dUX-17">HP-UX</a>: <a href="#Supported-Platforms">Supported Platforms</a></li>
<li><a href="#index-idn-106"><code>idn</code></a>: <a href="#Invoking-idn">Invoking idn</a></li>
<li><a href="#index-IDNA-Functions-72">IDNA Functions</a>: <a href="#IDNA-Functions">IDNA Functions</a></li>
<li><a href="#index-Installation-33">Installation</a>: <a href="#Downloading-and-Installing">Downloading and Installing</a></li>
<li><a href="#index-invoking-_0040command_007bidn_007d-107">invoking <samp><span class="command">idn</span></samp></a>: <a href="#Invoking-idn">Invoking idn</a></li>
<li><a href="#index-IRIX-14">IRIX</a>: <a href="#Supported-Platforms">Supported Platforms</a></li>
<li><a href="#index-LGPL_002c-GNU-Lesser-General-Public-License-122">LGPL, GNU Lesser General Public License</a>: <a href="#GNU-LGPL">GNU LGPL</a></li>
<li><a href="#index-License_002c-GNU-GPL-125">License, GNU GPL</a>: <a href="#GNU-GPL">GNU GPL</a></li>
<li><a href="#index-License_002c-GNU-LGPL-123">License, GNU LGPL</a>: <a href="#GNU-LGPL">GNU LGPL</a></li>
<li><a href="#index-MacOS-X-24">MacOS X</a>: <a href="#Supported-Platforms">Supported Platforms</a></li>
<li><a href="#index-Mandrake-13">Mandrake</a>: <a href="#Supported-Platforms">Supported Platforms</a></li>
<li><a href="#index-Microsoft-31">Microsoft</a>: <a href="#Supported-Platforms">Supported Platforms</a></li>
<li><a href="#index-mingw32-32">mingw32</a>: <a href="#Supported-Platforms">Supported Platforms</a></li>
<li><a href="#index-Motorola-Coldfire-26">Motorola Coldfire</a>: <a href="#Supported-Platforms">Supported Platforms</a></li>
<li><a href="#index-NetBSD-21">NetBSD</a>: <a href="#Supported-Platforms">Supported Platforms</a></li>
<li><a href="#index-OpenBSD-22">OpenBSD</a>: <a href="#Supported-Platforms">Supported Platforms</a></li>
<li><a href="#index-OpenPower-720-8">OpenPower 720</a>: <a href="#Supported-Platforms">Supported Platforms</a></li>
<li><a href="#index-PR29-Functions-100">PR29 Functions</a>: <a href="#PR29-Functions">PR29 Functions</a></li>
<li><a href="#index-Punycode-Functions-67">Punycode Functions</a>: <a href="#Punycode-Functions">Punycode Functions</a></li>
<li><a href="#index-RedHat-9">RedHat</a>: <a href="#Supported-Platforms">Supported Platforms</a></li>
<li><a href="#index-RedHat-Advanced-Server-11">RedHat Advanced Server</a>: <a href="#Supported-Platforms">Supported Platforms</a></li>
<li><a href="#index-Reporting-Bugs-35">Reporting Bugs</a>: <a href="#Bug-Reports">Bug Reports</a></li>
<li><a href="#index-Solaris-18">Solaris</a>: <a href="#Supported-Platforms">Supported Platforms</a></li>
<li><a href="#index-Stringprep-Functions-53">Stringprep Functions</a>: <a href="#Stringprep-Functions">Stringprep Functions</a></li>
<li><a href="#index-SuSE-4">SuSE</a>: <a href="#Supported-Platforms">Supported Platforms</a></li>
<li><a href="#index-SuSE-Linux-5">SuSE Linux</a>: <a href="#Supported-Platforms">Supported Platforms</a></li>
<li><a href="#index-TLD-Functions-87">TLD Functions</a>: <a href="#TLD-Functions">TLD Functions</a></li>
<li><a href="#index-Tru64-3">Tru64</a>: <a href="#Supported-Platforms">Supported Platforms</a></li>
<li><a href="#index-uClibc-28">uClibc</a>: <a href="#Supported-Platforms">Supported Platforms</a></li>
<li><a href="#index-uClinux-27">uClinux</a>: <a href="#Supported-Platforms">Supported Platforms</a></li>
<li><a href="#index-Utility-Functions-42">Utility Functions</a>: <a href="#Utility-Functions">Utility Functions</a></li>
<li><a href="#index-Windows-16">Windows</a>: <a href="#Supported-Platforms">Supported Platforms</a></li>
   </ul></body></html>