1/* $Id: normalizer.h,v 1.1 2003/06/04 00:25:40 marka Exp $ */
2/*
3 * Copyright (c) 2000 Japan Network Information Center.  All rights reserved.
4 *
5 * By using this file, you agree to the terms and conditions set forth bellow.
6 *
7 * 			LICENSE TERMS AND CONDITIONS
8 *
9 * The following License Terms and Conditions apply, unless a different
10 * license is obtained from Japan Network Information Center ("JPNIC"),
11 * a Japanese association, Kokusai-Kougyou-Kanda Bldg 6F, 2-3-4 Uchi-Kanda,
12 * Chiyoda-ku, Tokyo 101-0047, Japan.
13 *
14 * 1. Use, Modification and Redistribution (including distribution of any
15 *    modified or derived work) in source and/or binary forms is permitted
16 *    under this License Terms and Conditions.
17 *
18 * 2. Redistribution of source code must retain the copyright notices as they
19 *    appear in each source code file, this License Terms and Conditions.
20 *
21 * 3. Redistribution in binary form must reproduce the Copyright Notice,
22 *    this License Terms and Conditions, in the documentation and/or other
23 *    materials provided with the distribution.  For the purposes of binary
24 *    distribution the "Copyright Notice" refers to the following language:
25 *    "Copyright (c) 2000-2002 Japan Network Information Center.  All rights reserved."
26 *
27 * 4. The name of JPNIC may not be used to endorse or promote products
28 *    derived from this Software without specific prior written approval of
29 *    JPNIC.
30 *
31 * 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
32 *    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 *    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
34 *    PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL JPNIC BE LIABLE
35 *    FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
36 *    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
37 *    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
38 *    BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
39 *    WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
40 *    OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
41 *    ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
42 */
43
44#ifndef IDN_NORMALIZER_H
45#define IDN_NORMALIZER_H 1
46
47#ifdef __cplusplus
48extern "C" {
49#endif
50
51/*
52 * Domain name normalizer.
53 *
54 * Perform normalization on the specified strings.  String must be
55 * in UCS4 encoding.
56 */
57
58#include <idn/export.h>
59#include <idn/result.h>
60
61/*
62 * Normalizer type (opaque).
63 */
64typedef struct idn_normalizer *idn_normalizer_t;
65
66/*
67 * Normalizer procedure type.
68 */
69typedef idn_result_t (*idn_normalizer_proc_t)(const unsigned long *from,
70					      unsigned long *to, size_t tolen);
71
72/*
73 * Initialize this module.
74 *
75 * Returns:
76 *	idn_success		-- ok.
77 *	idn_nomemory		-- malloc failed.
78 */
79IDN_EXPORT idn_result_t
80idn_normalizer_initialize(void);
81
82/*
83 * Create a empty normalizer.
84 *
85 * Returns:
86 *	idn_success		-- ok.
87 *	idn_nomemory		-- malloc failed.
88 */
89IDN_EXPORT idn_result_t
90idn_normalizer_create(idn_normalizer_t *ctxp);
91
92/*
93 * Decrement reference count of the normalizer `ctx' created by
94 * 'idn_normalizer_create', if it is still refered by another object.
95 * Otherwise, release all the memory allocated to the normalizer.
96 */
97IDN_EXPORT void
98idn_normalizer_destroy(idn_normalizer_t ctx);
99
100/*
101 * Increment reference count of the normalizer `ctx' created by
102 * 'idn_normalizer_create'.
103 */
104IDN_EXPORT void
105idn_normalizer_incrref(idn_normalizer_t ctx);
106
107/*
108 * Add a normalization scheme to a normalizer.
109 *
110 * Multiple shemes can be added to a normalizer, and they will be
111 * applied in order.
112 *
113 * Returns:
114 *	idn_success		-- ok.
115 *	idn_invalid_name	-- unknown scheme was specified.
116 *	idn_nomemory		-- malloc failed.
117 */
118IDN_EXPORT idn_result_t
119idn_normalizer_add(idn_normalizer_t ctx, const char *scheme_name);
120
121IDN_EXPORT idn_result_t
122idn_normalizer_addall(idn_normalizer_t ctx, const char **scheme_names,
123		      int nschemes);
124
125/*
126 * Perform normalization(s) defined by a normalizer to the specified string,
127 * If the normalizer has two or more normalization schemes, they are
128 * applied in order.
129 *
130 * Returns:
131 *	idn_success		-- ok.
132 *	idn_buffer_overflow	-- output buffer is too small.
133 *	idn_nomemory		-- malloc failed.
134 */
135IDN_EXPORT idn_result_t
136idn_normalizer_normalize(idn_normalizer_t ctx, const unsigned long *from,
137			 unsigned long *to, size_t tolen);
138
139/*
140 * Register a new normalization scheme.
141 *
142 * You can override the default normalization schemes, if you want.
143 *
144 * Returns:
145 *	idn_success		-- ok.
146 *	idn_nomemory		-- malloc failed.
147 */
148IDN_EXPORT idn_result_t
149idn_normalizer_register(const char *scheme_name, idn_normalizer_proc_t proc);
150
151#ifdef __cplusplus
152}
153#endif
154
155#endif /* IDN_NORMALIZER_H */
156