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