1 /* $NetBSD: api.c,v 1.4 2014/12/10 04:37:55 christos Exp $ */
4 static char *rcsid
= "Id: api.c,v 1.1 2003/06/04 00:25:48 marka Exp ";
8 * Copyright (c) 2001,2002 Japan Network Information Center.
11 * By using this file, you agree to the terms and conditions set forth bellow.
13 * LICENSE TERMS AND CONDITIONS
15 * The following License Terms and Conditions apply, unless a different
16 * license is obtained from Japan Network Information Center ("JPNIC"),
17 * a Japanese association, Kokusai-Kougyou-Kanda Bldg 6F, 2-3-4 Uchi-Kanda,
18 * Chiyoda-ku, Tokyo 101-0047, Japan.
20 * 1. Use, Modification and Redistribution (including distribution of any
21 * modified or derived work) in source and/or binary forms is permitted
22 * under this License Terms and Conditions.
24 * 2. Redistribution of source code must retain the copyright notices as they
25 * appear in each source code file, this License Terms and Conditions.
27 * 3. Redistribution in binary form must reproduce the Copyright Notice,
28 * this License Terms and Conditions, in the documentation and/or other
29 * materials provided with the distribution. For the purposes of binary
30 * distribution the "Copyright Notice" refers to the following language:
31 * "Copyright (c) 2000-2002 Japan Network Information Center. All rights reserved."
33 * 4. The name of JPNIC may not be used to endorse or promote products
34 * derived from this Software without specific prior written approval of
37 * 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
38 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
39 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
40 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
41 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
42 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
43 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
44 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
45 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
46 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
47 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
55 #include <idn/result.h>
56 #include <idn/assert.h>
58 #include <idn/logmacro.h>
59 #include <idn/resconf.h>
61 #include <idn/debug.h>
64 static int initialized
;
65 static idn_resconf_t default_conf
;
67 static char *conf_file
;
70 idn_enable(int on_off
) {
71 idn_res_enable(on_off
);
75 idn__setconffile(const char *file
) {
79 TRACE(("idn__setconffile(%s)\n", (file
== NULL
) ? "<null>" : file
));
89 s
= (char *)malloc(strlen(file
) + 1);
101 TRACE(("idn__setconffile(): %s\n", idn_result_tostring(r
)));
106 idn_nameinit(int load_file
) {
109 TRACE(("idn_nameinit()\n"));
116 idn_resconf_initialize();
118 r
= idn_resconf_create(&default_conf
);
119 if (r
!= idn_success
)
123 r
= idn_resconf_loadfile(default_conf
, conf_file
);
125 r
= idn_resconf_setdefaults(default_conf
);
126 if (r
!= idn_success
)
132 if (r
!= idn_success
&& default_conf
!= NULL
) {
133 idn_resconf_destroy(default_conf
);
136 TRACE(("idn_nameinit(): %s\n", idn_result_tostring(r
)));
141 idn_encodename(idn_action_t actions
, const char *from
, char *to
, size_t tolen
) {
144 assert(from
!= NULL
&& to
!= NULL
);
146 TRACE(("idn_encodename(actions=%s, from=\"%s\")\n",
147 idn__res_actionstostring(actions
),
148 idn__debug_xstring(from
, 50)));
150 if (!initialized
&& ((r
= idn_nameinit(0)) != idn_success
))
153 r
= idn_res_encodename(default_conf
, actions
, from
, to
, tolen
);
156 if (r
== idn_success
) {
157 TRACE(("idn_encodename(): success (to=\"%s\")\n",
158 idn__debug_xstring(to
, 50)));
160 TRACE(("idn_encodename(): %s\n", idn_result_tostring(r
)));
166 idn_decodename(idn_action_t actions
, const char *from
, char *to
, size_t tolen
) {
169 assert(from
!= NULL
&& to
!= NULL
);
171 TRACE(("idn_decodename(actions=%s, from=\"%s\", tolen=%d)\n",
172 idn__res_actionstostring(actions
),
173 idn__debug_xstring(from
, 50), (int)tolen
));
175 if (!initialized
&& ((r
= idn_nameinit(0)) != idn_success
))
178 r
= idn_res_decodename(default_conf
, actions
, from
, to
, tolen
);
181 if (r
== idn_success
) {
182 TRACE(("idn_decodename(): success (to=\"%s\")\n",
183 idn__debug_xstring(to
, 50)));
185 TRACE(("idn_decodename(): %s\n", idn_result_tostring(r
)));
191 idn_decodename2(idn_action_t actions
, const char *from
, char *to
, size_t tolen
,
192 const char *auxencoding
) {
195 assert(from
!= NULL
&& to
!= NULL
);
197 TRACE(("idn_decodename2(actions=%s, from=\"%s\", tolen=%d)\n",
198 idn__res_actionstostring(actions
),
199 idn__debug_xstring(from
, 50), (int)tolen
));
201 if (!initialized
&& ((r
= idn_nameinit(0)) != idn_success
))
204 r
= idn_res_decodename2(default_conf
, actions
, from
, to
, tolen
,
208 if (r
== idn_success
) {
209 TRACE(("idn_decodename2(): success (to=\"%s\")\n",
210 idn__debug_xstring(to
, 50)));
212 TRACE(("idn_decodename2(): %s\n", idn_result_tostring(r
)));
218 * These functions are for backward compatibility.
220 #ifdef ENABLE_MDNKIT_COMPAT
224 return idn_nameinit(1);
228 mdn_encodename(int actions
, const char *from
, char *to
, size_t tolen
) {
231 assert(from
!= NULL
&& to
!= NULL
);
233 TRACE(("mdn_encodename(actions=%s, from=\"%s\")\n",
234 idn__res_actionstostring(actions
),
235 idn__debug_xstring(from
, 50)));
237 if (!initialized
&& ((r
= idn_nameinit(1)) != idn_success
))
240 return (idn_res_encodename(default_conf
, actions
, from
, to
, tolen
));
244 mdn_decodename(int actions
, const char *from
, char *to
, size_t tolen
) {
247 assert(from
!= NULL
&& to
!= NULL
);
249 TRACE(("idn_decodename(actions=%s, from=\"%s\", tolen=%d)\n",
250 idn__res_actionstostring(actions
),
251 idn__debug_xstring(from
, 50), (int)tolen
));
253 if (!initialized
&& ((r
= idn_nameinit(1)) != idn_success
))
256 return (idn_res_decodename(default_conf
, actions
, from
, to
, tolen
));
259 #endif /* ENABLE_MDNKIT_COMPAT */