1 /*	$NetBSD: resconf.h,v 1.4 2014/12/10 04:37:55 christos Exp $	*/
2 
3 /* Id: resconf.h,v 1.1 2003/06/04 00:25:41 marka Exp  */
4 /*
5  * Copyright (c) 2000 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_RESCONF_H
47 #define IDN_RESCONF_H 1
48 
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
52 
53 /*
54  * IDN resolver configuration.
55  */
56 
57 #include <idn/export.h>
58 #include <idn/result.h>
59 #include <idn/converter.h>
60 #include <idn/normalizer.h>
61 #include <idn/checker.h>
62 #include <idn/mapper.h>
63 #include <idn/mapselector.h>
64 #include <idn/delimitermap.h>
65 
66 /*
67  * Configuration type (opaque).
68  */
69 typedef struct idn_resconf *idn_resconf_t;
70 
71 /*
72  * Initialize.
73  *
74  * Initialize this module and underlying ones.  Must be called before
75  * any other functions of this module.
76  *
77  * Returns:
78  *	idn_success		-- ok.
79  *	idn_nomemory		-- malloc failed.
80  */
81 IDN_EXPORT idn_result_t
82 idn_resconf_initialize(void);
83 
84 /*
85  * Create a configuration context.
86  *
87  * Create an empty context and store it in '*ctxp'.
88  *
89  * Returns:
90  *	idn_success		-- ok.
91  *	idn_nomemory		-- malloc failed.
92  */
93 IDN_EXPORT idn_result_t
94 idn_resconf_create(idn_resconf_t *ctxp);
95 
96 /*
97  * Destroy the configuration context.
98  *
99  * Destroy the configuration context created by 'idn_resconf_create',
100  * and release memory for it.
101  */
102 IDN_EXPORT void
103 idn_resconf_destroy(idn_resconf_t ctx);
104 
105 /*
106  * Increment reference count of the context created by 'idn_resconf_create'.
107  */
108 IDN_EXPORT void
109 idn_resconf_incrref(idn_resconf_t ctx);
110 
111 /*
112  * Set default configurations to resconf context.
113  *
114  * "default configurations" means current nameprep and IDN encoding
115  * which IDN standard document suggests.
116  *
117  * Warning: configurations set previously are removed.
118  *
119  * Returns:
120  *	idn_success		-- ok.
121  *	idn_invalid_syntax	-- syntax error found.
122  *	idn_invalid_name	-- invalid encoding/nomalization name is
123  *				   specified.
124  *	idn_nomemory		-- malloc failed.
125  */
126 IDN_EXPORT idn_result_t
127 idn_resconf_setdefaults(idn_resconf_t ctx);
128 
129 /*
130  * Load configuration file.
131  *
132  * Parse a configuration file whose name is specified by 'file',
133  * store the result in 'ctx'.  If 'file' is NULL, the default file is
134  * loaded.
135  *
136  * Returns:
137  *	idn_success		-- ok.
138  *	idn_nofile		-- couldn't open specified file.
139  *	idn_invalid_syntax	-- syntax error found.
140  *	idn_invalid_name	-- invalid encoding/nomalization name is
141  *				   specified.
142  *	idn_nomemory		-- malloc failed.
143  */
144 IDN_EXPORT idn_result_t
145 idn_resconf_loadfile(idn_resconf_t ctx, const char *file);
146 
147 /*
148  * Get the pathname of the default configuration file.
149  *
150  * Returns:
151  *	the pathname of the default configuration file.
152  */
153 IDN_EXPORT char *
154 idn_resconf_defaultfile(void);
155 
156 /*
157  * Get an object of lower module that `ctx' holds.
158  */
159 IDN_EXPORT idn_delimitermap_t
160 idn_resconf_getdelimitermap(idn_resconf_t ctx);
161 
162 IDN_EXPORT idn_converter_t
163 idn_resconf_getidnconverter(idn_resconf_t ctx);
164 
165 IDN_EXPORT idn_converter_t
166 idn_resconf_getauxidnconverter(idn_resconf_t ctx);
167 
168 IDN_EXPORT idn_converter_t
169 idn_resconf_getlocalconverter(idn_resconf_t ctx);
170 
171 IDN_EXPORT idn_mapselector_t
172 idn_resconf_getlocalmapselector(idn_resconf_t ctx);
173 
174 IDN_EXPORT idn_mapper_t
175 idn_resconf_getmapper(idn_resconf_t ctx);
176 
177 IDN_EXPORT idn_normalizer_t
178 idn_resconf_getnormalizer(idn_resconf_t ctx);
179 
180 IDN_EXPORT idn_checker_t
181 idn_resconf_getprohibitchecker(idn_resconf_t ctx);
182 
183 IDN_EXPORT idn_checker_t
184 idn_resconf_getunassignedchecker(idn_resconf_t ctx);
185 
186 IDN_EXPORT idn_checker_t
187 idn_resconf_getbidichecker(idn_resconf_t ctx);
188 
189 /*
190  * Set an object of lower module to `ctx'.
191  */
192 IDN_EXPORT void
193 idn_resconf_setdelimitermap(idn_resconf_t ctx,
194 			    idn_delimitermap_t delimiter_mapper);
195 
196 IDN_EXPORT void
197 idn_resconf_setidnconverter(idn_resconf_t ctx,
198                             idn_converter_t idn_coverter);
199 
200 IDN_EXPORT void
201 idn_resconf_setauxidnconverter(idn_resconf_t ctx,
202                                idn_converter_t aux_idn_coverter);
203 
204 IDN_EXPORT void
205 idn_resconf_setlocalconverter(idn_resconf_t ctx,
206 			      idn_converter_t local_converter);
207 
208 IDN_EXPORT void
209 idn_resconf_setlocalmapselector(idn_resconf_t ctx,
210 				idn_mapselector_t map_selector);
211 
212 IDN_EXPORT void
213 idn_resconf_setmapper(idn_resconf_t ctx, idn_mapper_t mapper);
214 
215 IDN_EXPORT void
216 idn_resconf_setnormalizer(idn_resconf_t ctx, idn_normalizer_t normalizer);
217 
218 IDN_EXPORT void
219 idn_resconf_setprohibitchecker(idn_resconf_t ctx,
220 			       idn_checker_t prohibit_checker);
221 
222 IDN_EXPORT void
223 idn_resconf_setunassignedchecker(idn_resconf_t ctx,
224 				 idn_checker_t unassigned_checker);
225 
226 IDN_EXPORT void
227 idn_resconf_setbidichecker(idn_resconf_t ctx,
228 			   idn_checker_t bidi_checker);
229 
230 /*
231  * Set name or add names to an object of lower module that `ctx' holds.
232  */
233 IDN_EXPORT idn_result_t
234 idn_resconf_setidnconvertername(idn_resconf_t ctx, const char *name,
235 				int flags);
236 
237 IDN_EXPORT idn_result_t
238 idn_resconf_setauxidnconvertername(idn_resconf_t ctx, const char *name,
239 				   int flags);
240 
241 IDN_EXPORT idn_result_t
242 idn_resconf_addalldelimitermapucs(idn_resconf_t ctx, unsigned long *v, int nv);
243 
244 IDN_EXPORT idn_result_t
245 idn_resconf_setlocalconvertername(idn_resconf_t ctx, const char *name,
246 				  int flags);
247 
248 IDN_EXPORT idn_result_t
249 idn_resconf_addalllocalmapselectornames(idn_resconf_t ctx, const char *tld,
250 					const char **names, int nnames);
251 
252 IDN_EXPORT idn_result_t
253 idn_resconf_addallmappernames(idn_resconf_t ctx, const char **names,
254 			      int nnames);
255 
256 IDN_EXPORT idn_result_t
257 idn_resconf_addallnormalizernames(idn_resconf_t ctx, const char **names,
258 				  int nnames);
259 
260 IDN_EXPORT idn_result_t
261 idn_resconf_addallprohibitcheckernames(idn_resconf_t ctx, const char **names,
262 				       int nnames);
263 
264 IDN_EXPORT idn_result_t
265 idn_resconf_addallunassignedcheckernames(idn_resconf_t ctx, const char **names,
266 					 int nnames);
267 
268 IDN_EXPORT idn_result_t
269 idn_resconf_addallbidicheckernames(idn_resconf_t ctx, const char **names,
270 				   int nnames);
271 
272 IDN_EXPORT idn_result_t
273 idn_resconf_setnameprepversion(idn_resconf_t ctx, const char *version);
274 
275 /*
276  * These macros are provided for backward compatibility to mDNkit 2.1
277  * and older.
278  */
279 IDN_EXPORT void
280 idn_resconf_setalternateconverter(idn_resconf_t ctx,
281                                   idn_converter_t alternate_converter);
282 
283 IDN_EXPORT idn_result_t
284 idn_resconf_setalternateconvertername(idn_resconf_t ctx, const char *name,
285 				      int flags);
286 
287 IDN_EXPORT idn_converter_t
288 idn_resconf_getalternateconverter(idn_resconf_t ctx);
289 
290 
291 /*
292  * These macros are provided for backward compatibility to idnkit 1.x.
293  */
294 #define idn_resconf_localconverter(ctx) \
295 	idn_resconf_getlocalconverter(ctx)
296 
297 #define idn_resconf_idnconverter(ctx) \
298 	idn_resconf_getidnconverter(ctx)
299 
300 #define idn_resconf_alternateconverter(ctx) \
301 	idn_resconf_getalternateconverter(ctx)
302 
303 #define idn_resconf_normalizer(ctx) \
304 	idn_resconf_getnormalizer(ctx)
305 
306 #define idn_resconf_mapper(ctx) \
307 	idn_resconf_getmapper(ctx)
308 
309 #define idn_resconf_delimitermap(ctx) \
310 	idn_resconf_getdelimitermap(ctx)
311 
312 #define idn_resconf_localmapselector(ctx) \
313 	idn_resconf_getlocalmapselector(ctx)
314 
315 #define idn_resconf_prohibitchecker(ctx) \
316 	idn_resconf_getprohibitchecker(ctx)
317 
318 #define idn_resconf_unassignedchecker(ctx) \
319 	idn_resconf_getunassignedchecker(ctx)
320 
321 #ifdef __cplusplus
322 }
323 #endif
324 
325 #endif /* IDN_RESCONF_H */
326