Use valid HTML.
[libidn.git] / libidn.texi
blob3cb21275f05c2835872dac4b424ef7f58f12609a
1 \input texinfo   @c -*-texinfo-*-
2 @c This file is part of the GNU Libidn Manual.
3 @c Copyright (C) 2002, 2003 Simon Josefsson
4 @c See below for copying conditions.
6 @setfilename libidn.info
7 @include version.texi
8 @settitle GNU Libidn @value{VERSION}
10 @syncodeindex pg cp
12 @copying
13 This manual is for GNU Libidn version @value{VERSION},
14 @value{UPDATED}.
16 Copyright @copyright{} 2002, 2003 Simon Josefsson.
18 @quotation
19 Permission is granted to copy, distribute and/or modify this document
20 under the terms of the GNU Free Documentation License, Version 1.1 or
21 any later version published by the Free Software Foundation; with no
22 Invariant Sections, with the Front-Cover Texts being ``A GNU Manual,''
23 and with the Back-Cover Texts as in (a) below.  A copy of the
24 license is included in the section entitled ``GNU Free Documentation
25 License.''
27 (a) The FSF's Back-Cover Text is: ``You have freedom to copy and modify
28 this GNU Manual, like GNU software.  Copies published by the Free
29 Software Foundation raise funds for GNU development.''
30 @end quotation
31 @end copying
33 @dircategory GNU Libraries
34 @direntry
35 * libidn: (libidn).     Internationalized string processing library.
36 @end direntry
38 @dircategory GNU utilities
39 @direntry
40 * idn: (libidn)Invoking idn.            Command line interface to GNU Libidn.
41 @end direntry
43 @dircategory Emacs
44 @direntry
45 * IDN Library: (libidn)Emacs API.       Emacs API for IDN functions.
46 @end direntry
48 @titlepage
49 @title GNU Libidn
50 @subtitle for version @value{VERSION}, @value{UPDATED}
51 @author Simon Josefsson (@email{bug-libidn@@gnu.org})
52 @page
53 @vskip 0pt plus 1filll
54 @insertcopying
55 @end titlepage
57 @contents
59 @ifnottex
60 @node Top
61 @top GNU Libidn
63 @insertcopying
64 @end ifnottex
66 @menu
67 * Introduction::                How to use this manual.
68 * Preparation::                 What you should do before using the library.
69 * Stringprep Functions::        Stringprep functions.
70 * Punycode Functions::          Punycode functions.
71 * IDNA Functions::              IDNA functions.
72 * Examples::                    Demonstrate how to use the library.
73 * Acknowledgements::            Whom to blame.
75 * Invoking idn::                Command line interface to the library.
77 * Emacs API::                   Emacs Lisp API for Libidn.
79 Indices
81 * Concept Index::
82 * Function and Variable Index::
84 Appendices
86 * Library Copying::             How you can copy and share GNU Libidn.
87 * Copying This Manual::         How you can copy and share this manual.
89 @end menu
92 @node Introduction
93 @chapter Introduction
95 GNU Libidn is an implementation of the Stringprep, Punycode and IDNA
96 specifications defined by the IETF Internationalized Domain Names
97 (IDN) working group, used for internationalized domain names.  The
98 package is available under the GNU Lesser General Public License.
100 The library contains a generic Stringprep implementation that does
101 Unicode 3.2 NFKC normalization, mapping and prohibitation of
102 characters, and bidirectional character handling.  Profiles for iSCSI,
103 Kerberos 5, Nameprep, SASL and XMPP are included.  Punycode and ASCII
104 Compatible Encoding (ACE) via IDNA are supported.
106 The Stringprep API consists of two main functions, one for converting
107 data from the system's native representation into UTF-8, and one
108 function to perform the Stringprep processing.  Adding a new
109 Stringprep profile for your application within the API is
110 straightforward.  The Punycode API consists of one encoding function
111 and one decoding function.  The IDNA API consists of the ToASCII and
112 ToUnicode functions, as well as an high-level interface for converting
113 entire domain names to and from the ACE encoded form.
115 The library is used by, e.g., GNU SASL and Shishi to process user
116 names and passwords.  Libidn can be built into GNU Libc to enable a
117 new system-wide getaddrinfo() flag for IDN processing.
119 GNU Libidn is developed for the GNU/Linux system, but runs on over 20
120 Unix platforms (including Solaris, IRIX, AIX, and Tru64) and Windows.
122 @menu
123 * Getting Started::
124 * Features::
125 * Supported Platforms::
126 * Bug Reports::
127 @end menu
129 @node Getting Started
130 @section Getting Started
132 This manual documents the library programming interface.  All
133 functions and data types provided by the library are explained.
135 The reader is assumed to possess basic familiarity with
136 internationalization concepts and network programming in C or C++.
138 This manual can be used in several ways.  If read from the beginning
139 to the end, it gives a good introduction into the library and how it
140 can be used in an application.  Forward references are included where
141 necessary.  Later on, the manual can be used as a reference manual to
142 get just the information needed about any particular interface of the
143 library.  Experienced programmers might want to start looking at the
144 examples at the end of the manual (@pxref{Examples}), and then only
145 read up those parts of the interface which are unclear.
147 @node Features
148 @section Features
150 This library might have a couple of advantages over other libraries
151 doing a similar job.
153 @table @asis
154 @item It's Free Software
155 Anybody can use, modify, and redistribute it under the terms of the
156 GNU Lesser General Public License.
158 @item It's thread-safe
159 No global state is kept in the library.
161 @item It's portable
162 It should work on all Unix like operating systems, including Windows.
164 @end table
166 @node Supported Platforms
167 @section Supported Platforms
169 Libidn has at some point in time been tested on the following
170 platforms.
172 @enumerate
174 @item Debian GNU/Linux 3.0 (Woody)
175 @cindex Debian
177 GCC 2.95.4 and GNU Make. This is the main development platform.
178 @code{alphaev67-unknown-linux-gnu}, @code{alphaev6-unknown-linux-gnu},
179 @code{hppa64-unknown-linux-gnu}, @code{i686-pc-linux-gnu},
180 @code{ia64-unknown-linux-gnu}.
182 @item Tru64 UNIX
183 @cindex Tru64
185 Tru64 UNIX C compiler and Tru64 Make. @code{alphaev67-dec-osf5.1},
186 @code{alphaev68-dec-osf5.1}.
188 @item SuSE Linux 7.1
189 @cindex SuSE
191 GCC 2.96 and GNU Make. @code{alphaev6-unknown-linux-gnu},
192 @code{alphaev67-unknown-linux-gnu}.
194 @item SuSE Linux 7.2a
195 @cindex SuSE Linux
197 GCC 3.0 and GNU Make. @code{ia64-unknown-linux-gnu}.
199 @item RedHat Linux 7.2
200 @cindex RedHat
202 GCC 2.96 and GNU Make. @code{alphaev6-unknown-linux-gnu},
203 @code{alphaev67-unknown-linux-gnu}, @code{ia64-unknown-linux-gnu}.
205 @item RedHat Linux 8.0
206 @cindex RedHat
208 GCC 3.2 and GNU Make. @code{i686-pc-linux-gnu}.
210 @item RedHat Advanced Server 2.1
211 @cindex RedHat Advanced Server
213 GCC 2.96 and GNU Make. @code{i686-pc-linux-gnu}.
215 @item Slackware Linux 8.0.01
216 @cindex RedHat
218 GCC 2.95.3 and GNU Make. @code{i686-pc-linux-gnu}.
220 @item Mandrake Linux 9.0
221 @cindex Mandrake
223 GCC 3.2 and GNU Make. @code{i686-pc-linux-gnu}.
225 @item IRIX 6.5
226 @cindex IRIX
228 MIPS C compiler, IRIX Make. @code{mips-sgi-irix6.5}.
230 @item AIX 4.3.2
231 @cindex AIX
233 IBM C for AIX compiler, AIX Make.  @code{rs6000-ibm-aix4.3.2.0}.
235 @item Microsoft Windows 2000 (Cygwin)
236 @cindex Windows
238 GCC 3.2, GNU make. @code{i686-pc-cygwin}.
240 @item HP-UX 11
241 @cindex HP-UX
243 HP-UX C compiler and HP Make. @code{ia64-hp-hpux11.22},
244 @code{hppa2.0w-hp-hpux11.11}.
246 @item SUN Solaris 2.8
247 @cindex Solaris
249 Sun WorkShop Compiler C 6.0 and SUN Make. @code{sparc-sun-solaris2.8}.
251 @item NetBSD 1.6
252 @cindex NetBSD
254 GCC 2.95.3 and GNU Make. @code{alpha-unknown-netbsd1.6},
255 @code{i386-unknown-netbsdelf1.6}.
257 @item OpenBSD 3.1 and 3.2
258 @cindex OpenBSD
260 GCC 2.95.3 and GNU Make. @code{alpha-unknown-openbsd3.1},
261 @code{i386-unknown-openbsd3.1}.
263 @item FreeBSD 4.7
264 @cindex FreeBSD
266 GCC 2.95.4 and GNU Make. @code{alpha-unknown-freebsd4.7},
267 @code{i386-unknown-freebsd4.7}.
269 @end enumerate
271 If you use Libidn on, or port Libidn to, a new platform please report
272 it to the author.
274 @node Bug Reports
275 @section Bug Reports
276 @cindex Reporting Bugs
278 If you think you have found a bug in Libidn, please investigate it and
279 report it.
281 @itemize @bullet
283 @item Please make sure that the bug is really in Libidn, and
284 preferably also check that it hasn't already been fixed in the latest
285 version.
287 @item You have to send us a test case that makes it possible for us to
288 reproduce the bug.
290 @item You also have to explain what is wrong; if you get a crash, or
291 if the results printed are not good and in that case, in what way.
292 Make sure that the bug report includes all information you would need
293 to fix this kind of bug for someone else.
295 @end itemize
297 Please make an effort to produce a self-contained report, with
298 something definite that can be tested or debugged.  Vague queries or
299 piecemeal messages are difficult to act on and don't help the
300 development effort.
302 If your bug report is good, we will do our best to help you to get a
303 corrected version of the software; if the bug report is poor, we won't
304 do anything about it (apart from asking you to send better bug
305 reports).
307 If you think something in this manual is unclear, or downright
308 incorrect, or if the language needs to be improved, please also send a
309 note.
311 Send your bug report to:
313 @center @samp{bug-libidn@@gnu.org}
316 @c **********************************************************
317 @c *******************  Preparation  ************************
318 @c **********************************************************
319 @node Preparation
320 @chapter Preparation
322 To use `Libidn', you have to perform some changes to your sources and
323 the build system.  The necessary changes are small and explained in
324 the following sections.  At the end of this chapter, it is described
325 how the library is initialized, and how the requirements of the
326 library are verified.
328 A faster way to find out how to adapt your application for use with
329 `Libidn' may be to look at the examples at the end of this manual
330 (@pxref{Examples}).
332 @menu
333 * Header::
334 * Initialization::
335 * Version Check::
336 * Building the source::
337 @end menu
339 @node Header
340 @section Header
342 The library contains a few independent parts, and each part export the
343 interfaces (data types and functions) in a header file.  You must
344 include the appropriate header files in all programs using the
345 library, either directly or through some other header file, like this:
347 @example
348 #include <stringprep.h>
349 @end example
351 The header files and the functions they define are categorized as
352 follows:
354 @table @asis
355 @item stringprep.h
357 The low-level stringprep API entry point.  For IDN applications, this
358 is usually invoked via IDNA. Some applications, specifically non-IDN
359 ones, may want to prepare strings directly though, and should include
360 this header file.
362 The name space of the stringprep part of Libidn is @code{stringprep*}
363 for function names, @code{Stringprep*} for data types and
364 @code{STRINGPREP_*} for other symbols.  In addition the same name
365 prefixes with one prepended underscore are reserved for internal use
366 and should never be used by an application.
368 @item punycode.h
370 The entry point to Punycode encoding and decoding functions.  Normally
371 punycode is used via the idna.h interface, but some application may
372 want to perform raw punycode operations.
374 The name space of the punycode part of Libidn is @code{punycode_*} for
375 function names, @code{Punycode*} for data types and @code{PUNYCODE_*}
376 for other symbols.  In addition the same name prefixes with one
377 prepended underscore are reserved for internal use and should never be
378 used by an application.
380 @item idna.h
382 The entry point to the IDNA functions.  This is the normal entry point
383 for applications that need IDN functionality.
385 The name space of the IDNA part of Libidn is @code{idna_*} for
386 function names, @code{Idna*} for data types and @code{IDNA_*} for
387 other symbols.  In addition the same name prefixes with one prepended
388 underscore are reserved for internal use and should never be used by
389 an application.
391 @end table
393 @node Initialization
394 @section Initialization
396 Libidn is stateless and does not need any initialization.
398 @node Version Check
399 @section Version Check
401 It is often desirable to check that the version of `Libidn' used is
402 indeed one which fits all requirements.  Even with binary
403 compatibility new features may have been introduced but due to problem
404 with the dynamic linker an old version is actually used.  So you may
405 want to check that the version is okay right after program startup.
407 @include libidn-api-version.texi
409 The normal way to use the function is to put something similar to the
410 following first in your @code{main()}:
412 @example
413   if (!stringprep_check_version (STRINGPREP_VERSION))
414     @{
415       printf ("stringprep_check_version() failed:\n"
416               "Header file incompatible with shared library.\n");
417       exit(1);
418     @}
419 @end example
421 @node Building the source
422 @section Building the source
423 @cindex Compiling your application
425 If you want to compile a source file including e.g. the `idna.h' header
426 file, you must make sure that the compiler can find it in the
427 directory hierarchy.  This is accomplished by adding the path to the
428 directory in which the header file is located to the compilers include
429 file search path (via the @option{-I} option).
431 However, the path to the include file is determined at the time the
432 source is configured.  To solve this problem, `Libidn' uses the
433 external package @command{pkg-config} that knows the path to the
434 include file and other configuration options.  The options that need
435 to be added to the compiler invocation at compile time are output by
436 the @option{--cflags} option to @command{pkg-config libidn}.  The
437 following example shows how it can be used at the command line:
439 @example
440 gcc -c foo.c `pkg-config libidn --cflags`
441 @end example
443 Adding the output of @samp{pkg-config libidn --cflags} to the
444 compilers command line will ensure that the compiler can find e.g. the
445 idna.h header file.
447 A similar problem occurs when linking the program with the library.
448 Again, the compiler has to find the library files.  For this to work,
449 the path to the library files has to be added to the library search
450 path (via the @option{-L} option).  For this, the option
451 @option{--libs} to @command{pkg-config libidn} can be used.  For
452 convenience, this option also outputs all other options that are
453 required to link the program with the `libidn' libarary.  The example
454 shows how to link @file{foo.o} with the `libidn' library to a program
455 @command{foo}.
457 @example
458 gcc -o foo foo.o `pkg-config libidn --libs`
459 @end example
461 Of course you can also combine both examples to a single command by
462 specifying both options to @command{pkg-config}:
464 @example
465 gcc -o foo foo.c `pkg-config libidn --cflags --libs`
466 @end example
468 @c **********************************************************
469 @c ******************  Stringprep Functions *****************
470 @c **********************************************************
471 @node Stringprep Functions
472 @chapter Stringprep Functions
473 @cindex Stringprep Functions
475 Stringprep describes a framework for preparing Unicode text strings in
476 order to increase the likelihood that string input and string
477 comparison work in ways that make sense for typical users throughout
478 the world. The stringprep protocol is useful for protocol identifier
479 values, company and personal names, internationalized domain names,
480 and other text strings.
482 @defcv {Enumerated type} Stringprep_profile_flags STRINGPREP_NO_NFKC
483 STRINGPREP_NO_NFKC disables the NFKC normalization, as well as
484 selecting the non-NFKC case folding tables.  Usually the profile
485 specifies BIDI and NFKC settings.
486 @end defcv
488 @defcv {Enumerated type} Stringprep_profile_flags STRINGPREP_NO_BIDI
489 STRINGPREP_NO_BIDI disables the BIDI step.  Usually the profile
490 specifies BIDI and NFKC settings.
491 @end defcv
493 @defcv {Enumerated type} Stringprep_profile_flags STRINGPREP_NO_UNASSIGNED
494 STRINGPREP_NO_UNASSIGNED causes stringprep() abort with an error if
495 string contains unassigned characters according to profile.
496 @end defcv
498 @include libidn-api-stringprep.texi
500 @c **********************************************************
501 @c *******************  Punycode Functions ******************
502 @c **********************************************************
503 @node Punycode Functions
504 @chapter Punycode Functions
505 @cindex Punycode Functions
507 Punycode is a simple and efficient transfer encoding syntax designed
508 for use with Internationalized Domain Names in Applications. It
509 uniquely and reversibly transforms a Unicode string into an ASCII
510 string. ASCII characters in the Unicode string are represented
511 literally, and non-ASCII characters are represented by ASCII
512 characters that are allowed in host name labels (letters, digits, and
513 hyphens). This document defines a general algorithm called Bootstring
514 that allows a string of basic code points to uniquely represent any
515 string of code points drawn from a larger set. Punycode is an instance
516 of Bootstring that uses particular parameter values specified by this
517 document, appropriate for IDNA.
519 @include libidn-api-punycode.texi
521 @c **********************************************************
522 @c ********************* IDNA Functions *********************
523 @c **********************************************************
524 @node IDNA Functions
525 @chapter IDNA Functions
526 @cindex IDNA Functions
528 Until now, there has been no standard method for domain names to use
529 characters outside the ASCII repertoire. The IDNA document defines
530 internationalized domain names (IDNs) and a mechanism called IDNA for
531 handling them in a standard fashion. IDNs use characters drawn from a
532 large repertoire (Unicode), but IDNA allows the non-ASCII characters
533 to be represented using only the ASCII characters already allowed in
534 so-called host names today. This backward-compatible representation is
535 required in existing protocols like DNS, so that IDNs can be
536 introduced with no changes to the existing infrastructure. IDNA is
537 only meant for processing domain names, not free text.
539 @include libidn-api-idna.texi
541 @c **********************************************************
542 @c ***********************  Examples  ***********************
543 @c **********************************************************
544 @node Examples
545 @chapter Examples
546 @cindex Examples
548 This chapter contains example code which illustrate how `Libidn' can
549 be used when writing your own application.
551 @menu
552 * Example 1::           Example using stringprep.
553 * Example 2::           Example using punycode.
554 * Example 3::           Example using IDNA ToASCII.
555 * Example 4::           Example using IDNA ToUnicode.
556 @end menu
558 @node Example 1
559 @section Example 1
561 This example demonstrates how the stringprep functions are used.
563 @example
564 @include example.c.texi
565 @end example
568 @node Example 2
569 @section Example 2
571 This example demonstrates how the punycode functions are used.
573 @example
574 @include example2.c.texi
575 @end example
578 @node Example 3
579 @section Example 3
581 This example demonstrates how the library is used to convert
582 internationalized domain names into ASCII compatible names.
584 @example
585 @include example3.c.texi
586 @end example
589 @node Example 4
590 @section Example 4
592 This example demonstrates how the library is used to convert ASCII
593 compatible names to internationalized domain names.
595 @example
596 @include example4.c.texi
597 @end example
599 @c **********************************************************
600 @c *********************  Invoking idn  *********************
601 @c **********************************************************
602 @node Invoking idn
603 @chapter Invoking idn
605 @pindex idn
606 @cindex invoking @command{idn}
607 @cindex command line
609 @majorheading Name
611 GNU Libidn (idn) -- Internationalized Domain Names command line tool
613 @majorheading Description
614 @code{idn} is a utility part of GNU Libidn.  It allows preparation of
615 strings, encoding and decoding of punycode data, and IDNA
616 ToASCII/ToUnicode operations to be performed on the command line,
617 without the need to write a program that uses libidn.
619 Data is read, line by line, from the standard input, and one of the
620 operations indicated by command parameters are performed and the
621 output is printed to standard output.  If any errors are encountered,
622 the execution of the applications is aborted.
624 @majorheading Options
625 @code{idn} recognizes these commands:
627 @verbatim
628        -h  --help
629               Print help and exit
631        -V  --version
632               Print version and exit
634        -s --stringprep
635               Prepare string according to nameprep profile
637        -e  --punycode-encode
638               Encode UTF-8 to Punycode
640        -d  --punycode-decode
641               Decode Punycode to UTF-8
643        -a  --idna-to-ascii
644               Convert UTF-8 to ACE according to IDNA
646        -u  --idna-to-unicode
647               Convert ACE to UTF-8 according to IDNA
649        --allow-unassigned
650               Toggle IDNA AllowUnassigned flag (default=off)
652        --usestd3asciirules
653               Toggle IDNA UseSTD3ASCIIRules flag (default=off)
655        -pSTRING   --profile=STRING
656               Use specified stringprep profile instead
658               Valid stringprep profiles are 'generic', 'Nameprep',
659               'KRBprep', 'Nodeprep', 'Resourceprep', 'plain',
660               'SASLprep', and 'ISCSIprep'.
662        --debug
663               Print debugging information (default=off)
665        --quiet
666               Don't print the welcome greeting (default=off)
667 @end verbatim
669 @majorheading Environment Variables
671 The @var{CHARSET} environment variable can be used to override what
672 character set to be used for decoding incoming data on the standard
673 input, and to encode data to the standard output.  If your system is
674 set up correctly, the application will guess which character set is
675 used automatically.  Example usage:
677 @verbatim
678 $ CHARSET=ISO-8859-1 idn --punycode-encode
680 @end verbatim
682 @node Emacs API
683 @chapter Emacs API
685 Included in Libidn are @file{punycode.el} and @file{idna.el} that
686 provides an Emacs Lisp API to (a limited set of) the Libidn API.  This
687 section describes the API.
689 @defvar punycode-program
690 Name of the GNU Libidn @file{idn} application.  The default is
691 @samp{env CHARSET=UTF-8 idn}.  This variable can be customized.
692 @end defvar
694 @defvar punycode-encode-parameters
695 Parameters passed to @var{punycode-program} to invoke punycode
696 encoding mode.  The default is @samp{--quiet --punycode-encode}.  This
697 variable can be customized.
698 @end defvar
700 @defvar punycode-decode-parameters
701 Parameters passed to @var{punycode-program} to invoke punycode
702 decoding mode.  The default is @samp{--quiet --punycode-decode}.  This
703 variable can be customized.
704 @end defvar
706 @defun punycode-encode string
707 Returns a Punycode encoding of the @var{string}, after converting the
708 input into UTF-8.
709 @end defun
711 @defun punycode-decode string
712 Returns a possibly multibyte string which is the decoding of the
713 @var{string} which is a punycode encoded string.
714 @end defun
716 @defvar idna-program
717 Name of the GNU Libidn @file{idn} application.  The default is
718 @samp{env CHARSET=UTF-8 idn}.  This variable can be customized.
719 @end defvar
721 @defvar idna-to-ascii-parameters
722 Parameters passed to @var{idna-program} to invoke IDNA ToASCII mode.
723 The default is @samp{--quiet --idna-to-ascii}.  This variable can be
724 customized.
725 @end defvar
727 @defvar idna-to-unicode-parameters
728 Parameters passed @var{idna-program} to invoke IDNA ToUnicode mode.
729 The default is @samp{--quiet --idna-to-unicode}.  This variable can be
730 customized.
731 @end defvar
733 @defun idna-to-ascii string
734 Returns an ASCII Compatible Encoding (ACE) of the string computed by
735 the IDNA ToASCII operation on the input @var{string}, after converting
736 the input to UTF-8.
737 @end defun
739 @defun idna-to-unicode string
740 Returns a possibly multibyte string which is the output of the IDNA
741 ToUnicode operation computed on the input @var{string}.
742 @end defun
744 @c **********************************************************
745 @c *******************  Acknowledgements  *******************
746 @c **********************************************************
747 @node Acknowledgements
748 @chapter Acknowledgements
750 The punycode code was taken from the IETF IDN Punycode specification,
751 by Adam M. Costello.
753 Some functions (see nfkc.c and toutf8.c) has been borrowed from GLib
754 downloaded from www.gtk.org.
756 Several people reported bugs, sent patches or suggested improvements,
757 see the file THANKS.
759 @node Concept Index
760 @unnumbered Concept Index
762 @printindex cp
764 @node Function and Variable Index
765 @unnumbered Function and Variable Index
767 @printindex fn
769 @include lgpl.texi
771 @node Copying This Manual
772 @appendix Copying This Manual
774 @menu
775 * GNU Free Documentation License::  License for copying this manual.
776 @end menu
778 @include fdl.texi
780 @bye