1 /* $NetBSD: util.c,v 1.4 2014/12/10 04:37:55 christos Exp $ */
4 static char *rcsid
= "Id: util.c,v 1.1 2003/06/04 00:26:45 marka Exp ";
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.
59 #include <idn/assert.h>
60 #include <idn/result.h>
61 #include <idn/logmacro.h>
66 #define IDNKEY_IDNKIT "Software\\JPNIC\\IDN"
71 * Note that these macros evaluate the argument multiple times. Be careful.
73 #define ASCII_ISDIGIT(c) \
74 ('0' <= (c) && (c) <= '9')
75 #define ASCII_ISUPPER(c) \
76 ('A' <= (c) && (c) <= 'Z')
77 #define ASCII_ISLOWER(c) \
78 ('a' <= (c) && (c) <= 'z')
79 #define ASCII_ISALPHA(c) \
80 (ASCII_ISUPPER(c) || ASCII_ISLOWER(c))
81 #define ASCII_ISALNUM(c) \
82 (ASCII_ISDIGIT(c) || ASCII_ISUPPER(c) || ASCII_ISLOWER(c))
84 #define ASCII_TOUPPER(c) \
85 (('a' <= (c) && (c) <= 'z') ? ((c) - 'a' + 'A') : (c))
86 #define ASCII_TOLOWER(c) \
87 (('A' <= (c) && (c) <= 'Z') ? ((c) - 'A' + 'a') : (c))
90 idn__util_asciihaveaceprefix(const char *str
, const char *prefix
) {
91 assert(str
!= NULL
&& prefix
!= NULL
);
93 while (*prefix
!= '\0') {
94 if (ASCII_TOLOWER(*str
) != ASCII_TOLOWER(*prefix
))
104 idn__util_ucs4haveaceprefix(const unsigned long *str
, const char *prefix
) {
105 assert(str
!= NULL
&& prefix
!= NULL
);
107 while (*prefix
!= '\0') {
108 if (ASCII_TOLOWER(*str
) != ASCII_TOLOWER(*prefix
))
118 idn__util_ucs4isasciirange(const unsigned long *str
) {
119 while (*str
!= '\0') {
130 idn__util_getregistrystring(idn__util_hkey_t topkey
, const char *name
,
131 char *str
, size_t length
)
138 assert((topkey
== idn__util_hkey_currentuser
||
139 topkey
== idn__util_hkey_localmachine
) &&
140 name
!= NULL
&& str
!= NULL
);
142 if (topkey
== idn__util_hkey_currentuser
) {
143 top
= HKEY_CURRENT_USER
;
144 } else { /* idn__util_hkey_localmachine */
145 top
= HKEY_LOCAL_MACHINE
;
148 stat
= RegOpenKeyEx(top
, IDNKEY_IDNKIT
, 0, KEY_READ
, &hk
);
149 if (stat
!= ERROR_SUCCESS
) {
154 stat
= RegQueryValueEx(hk
, (LPCTSTR
)name
, NULL
,
155 &type
, (LPBYTE
)str
, &len
);
158 if (stat
!= ERROR_SUCCESS
|| type
!= REG_SZ
) {