1 /*	$NetBSD: nameprep.h,v 1.4 2014/12/10 04:37:55 christos Exp $	*/
2 
3 /* Id: nameprep.h,v 1.1 2003/06/04 00:25:39 marka Exp  */
4 /*
5  * Copyright (c) 2001 Japan Network Information Center.  All rights reserved.
6  *
7  * By using this file, you agree to the terms and conditions set forth bellow.
8  *
9  * 			LICENSE TERMS AND CONDITIONS
10  *
11  * The following License Terms and Conditions apply, unless a different
12  * license is obtained from Japan Network Information Center ("JPNIC"),
13  * a Japanese association, Kokusai-Kougyou-Kanda Bldg 6F, 2-3-4 Uchi-Kanda,
14  * Chiyoda-ku, Tokyo 101-0047, Japan.
15  *
16  * 1. Use, Modification and Redistribution (including distribution of any
17  *    modified or derived work) in source and/or binary forms is permitted
18  *    under this License Terms and Conditions.
19  *
20  * 2. Redistribution of source code must retain the copyright notices as they
21  *    appear in each source code file, this License Terms and Conditions.
22  *
23  * 3. Redistribution in binary form must reproduce the Copyright Notice,
24  *    this License Terms and Conditions, in the documentation and/or other
25  *    materials provided with the distribution.  For the purposes of binary
26  *    distribution the "Copyright Notice" refers to the following language:
27  *    "Copyright (c) 2000-2002 Japan Network Information Center.  All rights reserved."
28  *
29  * 4. The name of JPNIC may not be used to endorse or promote products
30  *    derived from this Software without specific prior written approval of
31  *    JPNIC.
32  *
33  * 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
34  *    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
35  *    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
36  *    PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL JPNIC BE LIABLE
37  *    FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
38  *    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
39  *    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
40  *    BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
41  *    WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
42  *    OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
43  *    ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
44  */
45 
46 #ifndef IDN_NAMEPREP_H
47 #define IDN_NAMEPREP_H 1
48 
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
52 
53 /*
54  * Perform NAMEPREP (mapping, prohibited/unassigned checking).
55  */
56 
57 #include <idn/export.h>
58 #include <idn/result.h>
59 
60 /*
61  * BIDI type codes.
62  */
63 typedef enum {
64 	idn_biditype_r_al,
65 	idn_biditype_l,
66 	idn_biditype_others
67 } idn_biditype_t;
68 
69 /*
70  * A Handle for nameprep operations.
71  */
72 typedef struct idn_nameprep *idn_nameprep_t;
73 
74 
75 /*
76  * The latest version of nameprep.
77  */
78 #define IDN_NAMEPREP_CURRENT	"RFC3491"
79 
80 /*
81  * Create a handle for nameprep operations.
82  * The handle is stored in '*handlep', which is used other functions
83  * in this module.
84  * The version of the NAMEPREP specification can be specified with
85  * 'version' parameter.  If 'version' is NULL, the latest version
86  * is used.
87  *
88  * Returns:
89  *	idn_success		-- ok.
90  *	idn_notfound		-- specified version not found.
91  */
92 IDN_EXPORT idn_result_t
93 idn_nameprep_create(const char *version, idn_nameprep_t *handlep);
94 
95 /*
96  * Close a handle, which was created by 'idn_nameprep_create'.
97  */
98 IDN_EXPORT void
99 idn_nameprep_destroy(idn_nameprep_t handle);
100 
101 /*
102  * Perform character mapping on an UCS4 string specified by 'from', and
103  * store the result into 'to', whose length is specified by 'tolen'.
104  *
105  * Returns:
106  *	idn_success		-- ok.
107  *	idn_buffer_overflow	-- result buffer is too small.
108  */
109 IDN_EXPORT idn_result_t
110 idn_nameprep_map(idn_nameprep_t handle, const unsigned long *from,
111 		 unsigned long *to, size_t tolen);
112 
113 /*
114  * Check if an UCS4 string 'str' contains any prohibited characters specified
115  * by the draft.  If found, the pointer to the first such character is stored
116  * into '*found'.  Otherwise '*found' will be NULL.
117  *
118  * Returns:
119  *	idn_success		-- check has been done properly. (But this
120  *				   does not mean that no prohibited character
121  *				   was found.  Check '*found' to see the
122  *				   result.)
123  */
124 IDN_EXPORT idn_result_t
125 idn_nameprep_isprohibited(idn_nameprep_t handle, const unsigned long *str,
126 			  const unsigned long **found);
127 
128 /*
129  * Check if an UCS4 string 'str' contains any unassigned characters specified
130  * by the draft.  If found, the pointer to the first such character is stored
131  * into '*found'.  Otherwise '*found' will be NULL.
132  *
133  * Returns:
134  *	idn_success		-- check has been done properly. (But this
135  *				   does not mean that no unassinged character
136  *				   was found.  Check '*found' to see the
137  *				   result.)
138  */
139 IDN_EXPORT idn_result_t
140 idn_nameprep_isunassigned(idn_nameprep_t handle, const unsigned long *str,
141 			  const unsigned long **found);
142 
143 /*
144  * Check if an UCS4 string 'str' is valid string specified by ``bidi check''
145  * of the draft.  If it is not valid, the pointer to the first invalid
146  * character is stored into '*found'.  Otherwise '*found' will be NULL.
147  *
148  * Returns:
149  *	idn_success		-- check has been done properly. (But this
150  *				   does not mean that the string was valid.
151  *				   Check '*found' to see the result.)
152  */
153 IDN_EXPORT idn_result_t
154 idn_nameprep_isvalidbidi(idn_nameprep_t handle, const unsigned long *str,
155 			 const unsigned long **found);
156 
157 /*
158  * The following functions are for internal use.
159  * They are used for this module to be add to the checker and mapper modules.
160  */
161 IDN_EXPORT idn_result_t
162 idn_nameprep_createproc(const char *parameter, void **handlep);
163 
164 IDN_EXPORT void
165 idn_nameprep_destroyproc(void *handle);
166 
167 IDN_EXPORT idn_result_t
168 idn_nameprep_mapproc(void *handle, const unsigned long *from,
169 		     unsigned long *to, size_t tolen);
170 
171 IDN_EXPORT idn_result_t
172 idn_nameprep_prohibitproc(void *handle, const unsigned long *str,
173 			  const unsigned long **found);
174 
175 IDN_EXPORT idn_result_t
176 idn_nameprep_unassignedproc(void *handle, const unsigned long *str,
177 			    const unsigned long **found);
178 
179 IDN_EXPORT idn_result_t
180 idn_nameprep_bidiproc(void *handle, const unsigned long *str,
181 		      const unsigned long **found);
182 
183 #ifdef __cplusplus
184 }
185 #endif
186 
187 #endif /* IDN_NAMEPREP_H */
188