4 * convert.c - convert domain name
8 * Copyright (c) 2000,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 "wrapcommon.h"
58 * prepare/dispose conversion context
62 idnConvDone(idn_resconf_t ctx
)
66 idn_resconf_destroy(ctx
);
79 idnLogPrintf(idn_log_level_info
, "idnkit version: %-.20s\n",
80 idn_version_getstring());
85 if ((r
= idn_resconf_initialize()) != idn_success
) {
86 idnPrintf("idnConvInit: cannot initialize idn library: %s\n",
87 idn_result_tostring(r
));
90 if ((r
= idn_resconf_create(&ctx
)) != idn_success
) {
91 idnPrintf("idnConvInit: cannot create context: %s\n",
92 idn_result_tostring(r
));
96 * load configuration file.
98 if ((r
= idn_resconf_loadfile(ctx
, NULL
)) != idn_success
) {
99 idnPrintf("idnConvInit: cannot read configuration file: %s\n",
100 idn_result_tostring(r
));
101 if ((r
= idn_resconf_setdefaults(ctx
)) != idn_success
) {
102 idnPrintf("idnConvInit: setting default configuration"
104 idn_result_tostring(r
));
108 idnPrintf("idnConvInit: using default configuration\n");
113 if (idnGetPrgEncoding(encoding
, sizeof(encoding
)) == TRUE
) {
114 idnPrintf("Encoding PRG <%-.100s>\n", encoding
);
115 r
= idn_resconf_setlocalconvertername(ctx
, encoding
,
116 IDN_CONVERTER_RTCHECK
);
117 if (r
!= idn_success
) {
118 idnPrintf("idnConvInit: invalid local codeset "
120 encoding
, idn_result_tostring(r
));
129 * idnConvReq - convert domain name in a DNS request
131 * convert local encoding to DNS encoding
135 idnConvReq(idn_resconf_t ctx
, const char FAR
*from
, char FAR
*to
, size_t tolen
)
141 idnLogPrintf(idn_log_level_trace
, "idnConvReq(from=%-.100s)\n", from
);
143 idnLogPrintf(idn_log_level_trace
, "idnConvReq: ctx is NULL\n");
144 if (strlen(from
) >= tolen
)
150 r
= idn_res_encodename(ctx
, IDN_ENCODE_APP
, from
, to
, tolen
);
152 if (r
== idn_success
) {
160 * idnConvRsp - convert domain name in a DNS response
162 * convert DNS encoding to local encoding
166 idnConvRsp(idn_resconf_t ctx
, const char FAR
*from
, char FAR
*to
, size_t tolen
)
170 idnLogPrintf(idn_log_level_trace
, "idnConvRsp(from=%-.100s)\n", from
);
172 if (strlen(from
) >= tolen
)
176 } else if (idn_res_decodename(ctx
, IDN_DECODE_APP
,
177 from
, to
, tolen
) == idn_success
) {