Add.
[libidn.git] / libidn.texi
blob1ff844ffd3a769280986c16f2f34139e9089ac84
1 \input texinfo   @c -*-texinfo-*-
2 @comment $Id$
3 @comment %**start of header
4 @setfilename libidn.info
5 @include version.texi
6 @settitle GNU Libidn @value{VERSION}
7 @syncodeindex pg cp
8 @comment %**end of header
9 @copying
10 This manual is for GNU Libidn
11 (version @value{VERSION}, @value{UPDATED}),
12 which is a library for internationalized string processing.
14 Copyright @copyright{} 2002, 2003 Simon Josefsson.
16 @quotation
17 Permission is granted to copy, distribute and/or modify this document
18 under the terms of the GNU Free Documentation License, Version 1.1 or
19 any later version published by the Free Software Foundation; with no
20 Invariant Sections, with the Front-Cover Texts being ``A GNU Manual,''
21 and with the Back-Cover Texts as in (a) below.  A copy of the
22 license is included in the section entitled ``GNU Free Documentation
23 License.''
25 (a) The FSF's Back-Cover Text is: ``You have freedom to copy and modify
26 this GNU Manual, like GNU software.  Copies published by the Free
27 Software Foundation raise funds for GNU development.''
28 @end quotation
29 @end copying
31 @dircategory GNU Libraries
32 @direntry
33 * libidn: (libidn).     Internationalized string processing library.
34 @end direntry
36 @titlepage
37 @title GNU Libidn
38 @subtitle for version @value{VERSION}, @value{UPDATED}
39 @author Simon Josefsson (@email{bug-libidn@@gnu.org})
40 @page
41 @vskip 0pt plus 1filll
42 @insertcopying
43 @end titlepage
45 @contents
47 @ifnottex
48 @node Top
49 @top GNU Libidn
51 @insertcopying
52 @end ifnottex
54 @menu
55 * Introduction::                How to use this manual.
56 * Preparation::                 What you should do before using the library.
57 * Stringprep Functions::        Stringprep functions.
58 * Punycode Functions::          Punycode functions.
59 * IDNA Functions::              IDNA functions.
60 * Examples::                    Demonstrate how to use the library.
61 * Acknowledgements::            Whom to blame.
63 Appendices
65 * Library Copying::             How you can copy and share GNU Libidn.
66 * Copying This Manual::         How you can copy and share this manual.
68 Indices
70 * Index::
71 @end menu
74 @node Introduction
75 @chapter Introduction
77 GNU Libidn is an implementation of the Stringprep, Punycode and IDNA
78 specifications defined by the IETF Internationalized Domain Names
79 (IDN) working group, used for internationalized domain names.  It is
80 available under the GNU Lesser General Public License.  Currently the
81 Nameprep, Kerberos 5, SASL and XMPP Stringprep profiles are supported.
83 The library contains a generic Stringprep implementation (including
84 Unicode 3.2 NFKC normalization, table mapping of characters, and
85 Bidirectional Character handling), a few Stringprep profiles, and an
86 implementation of the functionality defined by Punycode and IDNA.
88 The Stringprep API consists of two main functions, one for converting
89 data from the system's native representation into UTF-8, and one
90 function to perform the Stringprep processing.  Each stringprep
91 profile has a corresponding CPP macro.  Adding a new Stringprep
92 profile for your application within the API is straightforward.  The
93 Punycode API consists of one encoding function and one decoding
94 function.  The IDNA API consists of the ToASCII and ToUnicode
95 functions, as well as an high-level interface for converting entire
96 domain names to and from the ACE encoded form.
98 The library is used by forthcoming network applications to process
99 user names and passwords before they are input to cryptographic
100 operations.  Libidn can be built into GNU Libc to enable a new
101 getaddrinfo() flag for system-wide IDN processing.
103 GNU Libidn is developed for the GNU/Linux system, but runs on over 20
104 Unix platforms (including Solaris, IRIX, AIX, and Tru64) and Windows.
106 @menu
107 * Getting Started::
108 * Features::
109 * Supported Platforms::
110 * Bug Reports::
111 @end menu
113 @node Getting Started
114 @section Getting Started
116 This manual documents the library programming interface.  All
117 functions and data types provided by the library are explained.
119 The reader is assumed to possess basic familiarity with
120 internationalization concepts and network programming in C or C++.
122 This manual can be used in several ways.  If read from the beginning
123 to the end, it gives a good introduction into the library and how it
124 can be used in an application.  Forward references are included where
125 necessary.  Later on, the manual can be used as a reference manual to
126 get just the information needed about any particular interface of the
127 library.  Experienced programmers might want to start looking at the
128 examples at the end of the manual (@pxref{Examples}), and then only
129 read up those parts of the interface which are unclear.
131 @node Features
132 @section Features
134 This library might have a couple of advantages over other libraries
135 doing a similar job.
137 @table @asis
138 @item It's Free Software
139 Anybody can use, modify, and redistribute it under the terms of the
140 GNU Lesser General Public License.
142 @item It's thread-safe
143 No global state is kept in the library.
145 @item It's portable
146 It should work on all Unix like operating systems, including Windows.
148 @end table
150 @node Supported Platforms
151 @section Supported Platforms
153 Libidn has at some point in time been tested on the following
154 platforms.
156 @enumerate
158 @item Debian GNU/Linux 3.0 (Woody)
159 @cindex Debian
161 GCC 2.95.4 and GNU Make. This is the main development platform.
162 @code{alphaev67-unknown-linux-gnu}, @code{alphaev6-unknown-linux-gnu},
163 @code{hppa64-unknown-linux-gnu}, @code{i686-pc-linux-gnu},
164 @code{ia64-unknown-linux-gnu}.
166 @item Tru64 UNIX
167 @cindex Tru64
169 Tru64 UNIX C compiler and Tru64 Make. @code{alphaev67-dec-osf5.1},
170 @code{alphaev68-dec-osf5.1}.
172 @item SuSE Linux 7.1
173 @cindex SuSE
175 GCC 2.96 and GNU Make. @code{alphaev6-unknown-linux-gnu},
176 @code{alphaev67-unknown-linux-gnu}.
178 @item SuSE Linux 7.2a
179 @cindex SuSE Linux
181 GCC 3.0 and GNU Make. @code{ia64-unknown-linux-gnu}.
183 @item RedHat Linux 7.2
184 @cindex RedHat
186 GCC 2.96 and GNU Make. @code{alphaev6-unknown-linux-gnu},
187 @code{alphaev67-unknown-linux-gnu}, @code{ia64-unknown-linux-gnu}.
189 @item RedHat Linux 8.0
190 @cindex RedHat
192 GCC 3.2 and GNU Make. @code{i686-pc-linux-gnu}.
194 @item RedHat Advanced Server 2.1
195 @cindex RedHat Advanced Server
197 GCC 2.96 and GNU Make. @code{i686-pc-linux-gnu}.
199 @item Slackware Linux 8.0.01
200 @cindex RedHat
202 GCC 2.95.3 and GNU Make. @code{i686-pc-linux-gnu}.
204 @item Mandrake Linux 9.0
205 @cindex Mandrake
207 GCC 3.2 and GNU Make. @code{i686-pc-linux-gnu}.
209 @item IRIX 6.5
210 @cindex IRIX
212 MIPS C compiler, IRIX Make. @code{mips-sgi-irix6.5}.
214 @item AIX 4.3.2
215 @cindex AIX
217 IBM C for AIX compiler, AIX Make.  @code{rs6000-ibm-aix4.3.2.0}.
219 @item Microsoft Windows 2000 (Cygwin)
220 @cindex Windows
222 GCC 3.2, GNU make. @code{i686-pc-cygwin}.
224 @item HP-UX 11
225 @cindex HP-UX
227 HP-UX C compiler and HP Make. @code{ia64-hp-hpux11.22},
228 @code{hppa2.0w-hp-hpux11.11}.
230 @item SUN Solaris 2.8
231 @cindex Solaris
233 Sun WorkShop Compiler C 6.0 and SUN Make. @code{sparc-sun-solaris2.8}.
235 @item NetBSD 1.6
236 @cindex NetBSD
238 GCC 2.95.3 and GNU Make. @code{alpha-unknown-netbsd1.6},
239 @code{i386-unknown-netbsdelf1.6}.
241 @item OpenBSD 3.1 and 3.2
242 @cindex OpenBSD
244 GCC 2.95.3 and GNU Make. @code{alpha-unknown-openbsd3.1},
245 @code{i386-unknown-openbsd3.1}.
247 @item FreeBSD 4.7
248 @cindex FreeBSD
250 GCC 2.95.4 and GNU Make. @code{alpha-unknown-freebsd4.7},
251 @code{i386-unknown-freebsd4.7}.
253 @end enumerate
255 If you use Libidn on, or port Libidn to, a new platform please report
256 it to the author.
258 @node Bug Reports
259 @section Bug Reports
260 @cindex Reporting Bugs
262 If you think you have found a bug in Libidn, please investigate it and
263 report it.
265 @itemize @bullet
267 @item Please make sure that the bug is really in Libidn, and
268 preferably also check that it hasn't already been fixed in the latest
269 version.
271 @item You have to send us a test case that makes it possible for us to
272 reproduce the bug.
274 @item You also have to explain what is wrong; if you get a crash, or
275 if the results printed are not good and in that case, in what way.
276 Make sure that the bug report includes all information you would need
277 to fix this kind of bug for someone else.
279 @end itemize
281 Please make an effort to produce a self-contained report, with
282 something definite that can be tested or debugged.  Vague queries or
283 piecemeal messages are difficult to act on and don't help the
284 development effort.
286 If your bug report is good, we will do our best to help you to get a
287 corrected version of the software; if the bug report is poor, we won't
288 do anything about it (apart from asking you to send better bug
289 reports).
291 If you think something in this manual is unclear, or downright
292 incorrect, or if the language needs to be improved, please also send a
293 note.
295 Send your bug report to:
297 @center @samp{bug-libidn@@gnu.org}
300 @c **********************************************************
301 @c *******************  Preparation  ************************
302 @c **********************************************************
303 @node Preparation
304 @chapter Preparation
306 To use `Libidn', you have to perform some changes to your sources and
307 the build system.  The necessary changes are small and explained in
308 the following sections.  At the end of this chapter, it is described
309 how the library is initialized, and how the requirements of the
310 library are verified.
312 A faster way to find out how to adapt your application for use with
313 `Libidn' may be to look at the examples at the end of this manual
314 (@pxref{Examples}).
316 @menu
317 * Header::
318 * Initialization::
319 * Version Check::
320 * Building the source::
321 @end menu
323 @node Header
324 @section Header
326 The library contains a few independent parts, and each part export the
327 interfaces (data types and functions) in a header file.  You must
328 include the appropriate header files in all programs using the
329 library, either directly or through some other header file, like this:
331 @example
332 #include <stringprep.h>
333 @end example
335 The header files and the functions they define are categorized as
336 follows:
338 @table @asis
339 @item stringprep.h
341 The low-level stringprep API entry point.  Normal applications uses
342 one specific stringprep profile, and should rather include the
343 corresponding profile header file (see below).  If you are writing an
344 application that only makes use of the utility functions, including
345 this header file may be more appropriate however.
347 The name space of the stringprep part of Libidn is @code{stringprep*}
348 for function names, @code{Stringprep*} for data types and
349 @code{STRINGPREP_*} for other symbols.  In addition the same name
350 prefixes with one prepended underscore are reserved for internal use
351 and should never be used by an application.
353 @item stringprep_generic.h
355 The entry point to the generic tables specified in the stringprep
356 specification.  It is normally only needed by applications that want
357 to define its own stringprep profile, based on the generic tables.
359 This header file uses the same namespace as the main stringprep.h
360 header file.
362 @item stringprep_kerberos5.h
364 The entry point to the experimental Kerberos 5 profile of stringprep.
366 This header file uses the same namespace as the main stringprep.h
367 header file.
369 @item stringprep_nameprep.h
371 The entry point to the IDN (``nameprep'') profile of stringprep.  This
372 is the entry point used by applications needing low-level access to
373 the stringprep profile used in IDN.  Most applications requesting IDN
374 functionality will want idna.h instead though.
376 This header file uses the same namespace as the main stringprep.h
377 header file.
379 @item stringprep_plain.h
381 The entry point to the SASL ANONYMOUS (``plain'') profile of
382 stringprep.
384 This header file uses the same namespace as the main stringprep.h
385 header file.
387 @item stringprep_xmpp.h
389 The entry point to the experimental XMPP node (``nodeprep'') and
390 resource identifier (``resourceprep'') profiles of stringprep.
392 This header file uses the same namespace as the main stringprep.h
393 header file.
395 @item punycode.h
397 The entry point to Punycode encoding and decoding functions.  Normally
398 punycode is used via the idna.h interface, but some application may
399 want to perform raw punycode operations.
401 The name space of the punycode part of Libidn is @code{punycode_*} for
402 function names, @code{Punycode*} for data types and @code{PUNYCODE_*}
403 for other symbols.  In addition the same name prefixes with one
404 prepended underscore are reserved for internal use and should never be
405 used by an application.
407 @item idna.h
409 The entry point to the IDNA functions.  This is the normal entry point
410 for applications that need IDN functionality.
412 The name space of the IDNA part of Libidn is @code{idna_*} for
413 function names, @code{Idna*} for data types and @code{IDNA_*} for
414 other symbols.  In addition the same name prefixes with one prepended
415 underscore are reserved for internal use and should never be used by
416 an application.
418 @end table
420 @node Initialization
421 @section Initialization
423 Libidn is stateless and does not need any initialization.
425 @node Version Check
426 @section Version Check
428 It is often desirable to check that the version of `Libidn' used is
429 indeed one which fits all requirements.  Even with binary
430 compatibility new features may have been introduced but due to problem
431 with the dynamic linker an old version is actually used.  So you may
432 want to check that the version is okay right after program startup.
434 @include libidn-api-version.texi
436 The normal way to use the function is to put something similar to the
437 following first in your @code{main()}:
439 @example
440   if (!stringprep_check_version (STRINGPREP_VERSION))
441     @{
442       printf ("stringprep_check_version() failed:\n"
443               "Header file incompatible with shared library.\n");
444       exit(1);
445     @}
446 @end example
448 @node Building the source
449 @section Building the source
450 @cindex Compiling your application
452 If you want to compile a source file including e.g. the `idna.h' header
453 file, you must make sure that the compiler can find it in the
454 directory hierarchy.  This is accomplished by adding the path to the
455 directory in which the header file is located to the compilers include
456 file search path (via the @option{-I} option).
458 However, the path to the include file is determined at the time the
459 source is configured.  To solve this problem, `Libidn' uses the
460 external package @command{pkg-config} that knows the path to the
461 include file and other configuration options.  The options that need
462 to be added to the compiler invocation at compile time are output by
463 the @option{--cflags} option to @command{pkg-config libidn}.  The
464 following example shows how it can be used at the command line:
466 @example
467 gcc -c foo.c `pkg-config libidn --cflags`
468 @end example
470 Adding the output of @samp{pkg-config libidn --cflags} to the
471 compilers command line will ensure that the compiler can find e.g. the
472 idna.h header file.
474 A similar problem occurs when linking the program with the library.
475 Again, the compiler has to find the library files.  For this to work,
476 the path to the library files has to be added to the library search
477 path (via the @option{-L} option).  For this, the option
478 @option{--libs} to @command{pkg-config libidn} can be used.  For
479 convenience, this option also outputs all other options that are
480 required to link the program with the `libidn' libarary.  The example
481 shows how to link @file{foo.o} with the `libidn' library to a program
482 @command{foo}.
484 @example
485 gcc -o foo foo.o `pkg-config libidn --libs`
486 @end example
488 Of course you can also combine both examples to a single command by
489 specifying both options to @command{pkg-config}:
491 @example
492 gcc -o foo foo.c `pkg-config libidn --cflags --libs`
493 @end example
495 @c **********************************************************
496 @c ******************  Stringprep Functions *****************
497 @c **********************************************************
498 @node Stringprep Functions
499 @chapter Stringprep Functions
500 @cindex Stringprep Functions
502 Stringprep describes a framework for preparing Unicode text strings in
503 order to increase the likelihood that string input and string
504 comparison work in ways that make sense for typical users throughout
505 the world. The stringprep protocol is useful for protocol identifier
506 values, company and personal names, internationalized domain names,
507 and other text strings.
509 @defcv {Enumerated type} Stringprep_profile_flags STRINGPREP_NO_NFKC
510 STRINGPREP_NO_NFKC disables the NFKC normalization, as well as
511 selecting the non-NFKC case folding tables.  Usually the profile
512 specifies BIDI and NFKC settings.
513 @end defcv
515 @defcv {Enumerated type} Stringprep_profile_flags STRINGPREP_NO_BIDI
516 STRINGPREP_NO_BIDI disables the BIDI step.  Usually the profile
517 specifies BIDI and NFKC settings.
518 @end defcv
520 @defcv {Enumerated type} Stringprep_profile_flags STRINGPREP_NO_UNASSIGNED
521 STRINGPREP_NO_UNASSIGNED causes stringprep() abort with an error if
522 string contains unassigned characters according to profile.
523 @end defcv
525 @include libidn-api-stringprep.texi
527 @c **********************************************************
528 @c *******************  Punycode Functions ******************
529 @c **********************************************************
530 @node Punycode Functions
531 @chapter Punycode Functions
532 @cindex Punycode Functions
534 Punycode is a simple and efficient transfer encoding syntax designed
535 for use with Internationalized Domain Names in Applications. It
536 uniquely and reversibly transforms a Unicode string into an ASCII
537 string. ASCII characters in the Unicode string are represented
538 literally, and non-ASCII characters are represented by ASCII
539 characters that are allowed in host name labels (letters, digits, and
540 hyphens). This document defines a general algorithm called Bootstring
541 that allows a string of basic code points to uniquely represent any
542 string of code points drawn from a larger set. Punycode is an instance
543 of Bootstring that uses particular parameter values specified by this
544 document, appropriate for IDNA.
546 @include libidn-api-punycode.texi
548 @c **********************************************************
549 @c ********************* IDNA Functions *********************
550 @c **********************************************************
551 @node IDNA Functions
552 @chapter IDNA Functions
553 @cindex IDNA Functions
555 Until now, there has been no standard method for domain names to use
556 characters outside the ASCII repertoire. The IDNA document defines
557 internationalized domain names (IDNs) and a mechanism called IDNA for
558 handling them in a standard fashion. IDNs use characters drawn from a
559 large repertoire (Unicode), but IDNA allows the non-ASCII characters
560 to be represented using only the ASCII characters already allowed in
561 so-called host names today. This backward-compatible representation is
562 required in existing protocols like DNS, so that IDNs can be
563 introduced with no changes to the existing infrastructure. IDNA is
564 only meant for processing domain names, not free text.
566 @include libidn-api-idna.texi
568 @c **********************************************************
569 @c ***********************  Examples  ***********************
570 @c **********************************************************
571 @node Examples
572 @chapter Examples
573 @cindex Examples
575 This chapter contains example code which illustrate how `Libidn' can
576 be used when writing your own application.
578 @menu
579 * Example 1::           Example using stringprep.
580 * Example 2::           Example using punycode.
581 * Example 3::           Example using IDNA ToASCII.
582 * Example 4::           Example using IDNA ToUnicode.
583 @end menu
585 @node Example 1
586 @section Example 1
588 This example demonstrates how the stringprep functions are used.
590 @example
591 @include example.c.texi
592 @end example
595 @node Example 2
596 @section Example 2
598 This example demonstrates how the punycode functions are used.
600 @example
601 @include example2.c.texi
602 @end example
605 @node Example 3
606 @section Example 3
608 This example demonstrates how the library is used to convert
609 internationalized domain names into ASCII compatible names.
611 @example
612 @include example3.c.texi
613 @end example
616 @node Example 4
617 @section Example 4
619 This example demonstrates how the library is used to convert ASCII
620 compatible names to internationalized domain names.
622 @example
623 @include example4.c.texi
624 @end example
626 @c **********************************************************
627 @c *******************  Acknowledgements  *******************
628 @c **********************************************************
629 @node Acknowledgements
630 @chapter Acknowledgements
632 Simon Josefsson created the library autumn 2002 when he really should
633 have been studying mathematics.
635 The punycode code was taken from the IETF IDN Punycode specification,
636 by Adam M. Costello.
638 Some functions (see nfkc.c and toutf8.c) has been borrowed from GLib
639 downloaded from www.gtk.org.
641 Several people reported bugs, sent patches or suggested improvements,
642 see the file THANKS.
644 @include lgpl.texi
646 @node Copying This Manual
647 @appendix Copying This Manual
649 @menu
650 * GNU Free Documentation License::  License for copying this manual.
651 @end menu
653 @include fdl.texi
656 @node Index
657 @unnumbered Index
659 @printindex cp
661 @bye