1/* $Id: checker.h,v 1.1 2003/06/04 00:25:36 marka Exp $ */
2/*
3 * Copyright (c) 2001 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_CHECKER_H
45#define IDN_CHECKER_H 1
46
47#ifdef __cplusplus
48extern "C" {
49#endif
50
51/*
52 * Character Checker.
53 *
54 * Perfom checking characters in the specified domain name.
55 */
56
57#include <idn/result.h>
58#include <idn/filechecker.h>
59#include <idn/nameprep.h>
60
61/*
62 * Schems name prefixes for the standard nameprep prohibit/unassigned
63 * checks.
64 *
65 * If you'd like to add the unassigned check scheme of "RFC3491"
66 * to a checker context, IDN_CHECKER_UNASSIGNED_PREFIX + "RFC3491"
67 * (i.e. "unassigned#RFC3491") is the scheme name passed to
68 * idn_checker_add().
69 */
70#define IDN_CHECKER_PROHIBIT_PREFIX	"prohibit#"
71#define IDN_CHECKER_UNASSIGNED_PREFIX	"unassigned#"
72#define IDN_CHECKER_BIDI_PREFIX		"bidi#"
73
74/*
75 * Checker object type.
76 */
77typedef struct idn_checker *idn_checker_t;
78
79/*
80 * Initialize module.  Must be called before any other calls of
81 * the functions of this module.
82 *
83 * Returns:
84 *      idn_success             -- ok.
85 *      idn_nomemory            -- malloc failed.
86 */
87extern idn_result_t
88idn_checker_initialize(void);
89
90/*
91 * Create a checker context.
92 *
93 * Returns:
94 *      idn_success             -- ok.
95 *      idn_nomemory            -- malloc failed.
96 */
97extern idn_result_t
98idn_checker_create(idn_checker_t *ctxp);
99
100/*
101 * Decrement reference count of the checker `ctx' created by
102 * 'idn_checker_create', if it is still refered by another object.
103 * Otherwise, release all the memory allocated to the checker.
104 */
105extern void
106idn_checker_destroy(idn_checker_t ctx);
107
108/*
109 * Increment reference count of the checker `ctx' created by
110 * 'idn_checker_create'.
111 */
112extern void
113idn_checker_incrref(idn_checker_t ctx);
114
115/*
116 * Add checking scheme `name' to the checker to `ctx'.
117 *
118 * Returns:
119 *      idn_success             -- ok.
120 *      idn_invalid_name        -- the given name is not valid.
121 *      idn_nomemory            -- malloc failed.
122 */
123extern idn_result_t
124idn_checker_add(idn_checker_t ctx, const char *name);
125
126extern idn_result_t
127idn_checker_addall(idn_checker_t ctx, const char **names, int nnames);
128
129/*
130 * Check a domain name.  All checking schemes regsitered in `ctx' are
131 * applied in the regisration order.
132 *
133 * Returns:
134 *      idn_success             -- ok.
135 *      idn_nomemory            -- malloc failed.
136 *      idn_buffer_overflow     -- output buffer is too small.
137 */
138extern idn_result_t
139idn_checker_lookup(idn_checker_t ctx, const unsigned long *ucs4,
140		   const unsigned long **found);
141
142/*
143 * Checking procedure type.
144 */
145typedef idn_result_t (*idn_checker_createproc_t)(const char *parameter,
146						 void **ctxp);
147typedef void         (*idn_checker_destroyproc_t)(void *ctx);
148typedef idn_result_t (*idn_checker_lookupproc_t)(void *ctx,
149						 const unsigned long *ucs4,
150                                                 const unsigned long **found);
151
152/*
153 * Register a new checking scheme.
154 *
155 * You can override the default normalization schemes, if you want.
156 *
157 * Returns:
158 *      idn_success             -- ok.
159 *      idn_nomemory            -- malloc failed.
160 */
161extern idn_result_t
162idn_checker_register(const char *prefix,
163		     idn_checker_createproc_t create,
164		     idn_checker_destroyproc_t destroy,
165		     idn_checker_lookupproc_t lookup);
166
167#ifdef __cplusplus
168}
169#endif
170
171#endif /* IDN_CHECKER_H */
172