Print this page
rev 5696 : 6336885: RFE: Locale Data Deployment Enhancements
4609153: Provide locale data for Indic locales
5104387: Support for gl_ES locale (galician language)
6337471: desktop/system locale preferences support
7056139: (cal) SPI support for locale-dependent Calendar parameters
7058206: Provide CalendarData SPI for week params and display field value names
7073852: Support multiple scripts for digits and decimal symbols per locale
7079560: [Fmt-Da] Context dependent month names support in SimpleDateFormat
7171324: getAvailableLocales() of locale sensitive services should return the actual availability of locales
7151414: (cal) Support calendar type identification
7168528: LocaleServiceProvider needs to be aware of Locale extensions
7171372: (cal) locale's default Calendar should be created if unknown calendar is specified
Summary: JEP 127: Improve Locale Data Packaging and Adopt Unicode CLDR Data (part 1 w/o packaging changes. by Naoto Sato and Masayoshi Okutsu)
Split |
Close |
Expand all |
Collapse all |
--- old/src/solaris/native/java/lang/java_props_macosx.c
+++ new/src/solaris/native/java/lang/java_props_macosx.c
1 1 /*
2 2 * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
3 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 4 *
5 5 * This code is free software; you can redistribute it and/or modify it
6 6 * under the terms of the GNU General Public License version 2 only, as
7 7 * published by the Free Software Foundation. Oracle designates this
8 8 * particular file as subject to the "Classpath" exception as provided
9 9 * by Oracle in the LICENSE file that accompanied this code.
10 10 *
11 11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 14 * version 2 for more details (a copy is included in the LICENSE file that
15 15 * accompanied this code).
16 16 *
17 17 * You should have received a copy of the GNU General Public License version
18 18 * 2 along with this work; if not, write to the Free Software Foundation,
19 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 20 *
21 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 22 * or visit www.oracle.com if you need additional information or have any
23 23 * questions.
24 24 */
25 25
26 26 #include <dlfcn.h>
27 27 #include <sys/socket.h>
28 28 #include <netinet/in.h>
29 29 #include <arpa/inet.h>
30 30
31 31 #include <Security/AuthSession.h>
32 32 #include <CoreFoundation/CoreFoundation.h>
33 33 #include <SystemConfiguration/SystemConfiguration.h>
34 34
35 35 #include "java_props_macosx.h"
36 36
↓ open down ↓ |
36 lines elided |
↑ open up ↑ |
37 37
38 38 // need dlopen/dlsym trick to avoid pulling in JavaRuntimeSupport before libjava.dylib is loaded
39 39 static void *getJRSFramework() {
40 40 static void *jrsFwk = NULL;
41 41 if (jrsFwk == NULL) {
42 42 jrsFwk = dlopen("/System/Library/Frameworks/JavaVM.framework/Frameworks/JavaRuntimeSupport.framework/JavaRuntimeSupport", RTLD_LAZY | RTLD_LOCAL);
43 43 }
44 44 return jrsFwk;
45 45 }
46 46
47 -static char *getPosixLocale(int cat) {
47 +char *getPosixLocale(int cat) {
48 48 char *lc = setlocale(cat, NULL);
49 49 if ((lc == NULL) || (strcmp(lc, "C") == 0)) {
50 50 lc = getenv("LANG");
51 51 }
52 52 if (lc == NULL) return NULL;
53 53 return strdup(lc);
54 54 }
55 55
56 56 #define LOCALEIDLENGTH 128
57 -char *setupMacOSXLocale(int cat) {
57 +char *getMacOSXLocale(int cat) {
58 58 switch (cat) {
59 59 case LC_MESSAGES:
60 60 {
61 61 void *jrsFwk = getJRSFramework();
62 - if (jrsFwk == NULL) return getPosixLocale(cat);
62 + if (jrsFwk == NULL) return NULL;
63 63
64 64 char *(*JRSCopyPrimaryLanguage)() = dlsym(jrsFwk, "JRSCopyPrimaryLanguage");
65 65 char *primaryLanguage = JRSCopyPrimaryLanguage ? JRSCopyPrimaryLanguage() : NULL;
66 - if (primaryLanguage == NULL) return getPosixLocale(cat);
66 + if (primaryLanguage == NULL) return NULL;
67 67
68 68 char *(*JRSCopyCanonicalLanguageForPrimaryLanguage)(char *) = dlsym(jrsFwk, "JRSCopyCanonicalLanguageForPrimaryLanguage");
69 69 char *canonicalLanguage = JRSCopyCanonicalLanguageForPrimaryLanguage ? JRSCopyCanonicalLanguageForPrimaryLanguage(primaryLanguage) : NULL;
70 70 free (primaryLanguage);
71 - if (canonicalLanguage == NULL) return getPosixLocale(cat);
72 71
73 - void (*JRSSetDefaultLocalization)(char *) = dlsym(jrsFwk, "JRSSetDefaultLocalization");
74 - if (JRSSetDefaultLocalization) JRSSetDefaultLocalization(canonicalLanguage);
75 -
76 72 return canonicalLanguage;
77 73 }
78 74 break;
79 75 default:
80 76 {
81 77 char localeString[LOCALEIDLENGTH];
82 78 if (CFStringGetCString(CFLocaleGetIdentifier(CFLocaleCopyCurrent()),
83 79 localeString, LOCALEIDLENGTH, CFStringGetSystemEncoding())) {
84 80 return strdup(localeString);
85 81 }
86 82 }
87 83 break;
88 84 }
89 85
90 86 return NULL;
91 87 }
92 88
89 +char *setupMacOSXLocale(int cat) {
90 + char * ret = getMacOSXLocale(cat);
91 +
92 + if (cat == LC_MESSAGES && ret != NULL) {
93 + void *jrsFwk = getJRSFramework();
94 + if (jrsFwk != NULL) {
95 + void (*JRSSetDefaultLocalization)(char *) = dlsym(jrsFwk, "JRSSetDefaultLocalization");
96 + if (JRSSetDefaultLocalization) JRSSetDefaultLocalization(ret);
97 + }
98 + }
99 +
100 + if (ret == NULL) {
101 + return getPosixLocale(cat);
102 + } else {
103 + return ret;
104 + }
105 +}
106 +
93 107 /* There are several toolkit options on Mac OS X, so we should try to
94 108 * pick the "best" one, given what we know about the environment Java
95 109 * is running under
96 110 */
97 111
98 112 static PreferredToolkit getPreferredToolkitFromEnv() {
99 113 char *envVar = getenv("AWT_TOOLKIT");
100 114 if (envVar == NULL) return unset;
101 115
102 116 if (strcasecmp(envVar, "CToolkit") == 0) return CToolkit;
103 117 if (strcasecmp(envVar, "XToolkit") == 0) return XToolkit;
104 118 if (strcasecmp(envVar, "HToolkit") == 0) return HToolkit;
105 119 return unset;
106 120 }
107 121
108 122 static bool isInAquaSession() {
109 123 // Is the WindowServer available?
110 124 SecuritySessionId session_id;
111 125 SessionAttributeBits session_info;
112 126 OSStatus status = SessionGetInfo(callerSecuritySession, &session_id, &session_info);
113 127 if (status != noErr) return false;
114 128 if (!(session_info & sessionHasGraphicAccess)) return false;
115 129 return true;
116 130 }
117 131
118 132 static bool isXDisplayDefined() {
119 133 return getenv("DISPLAY") != NULL;
120 134 }
121 135
122 136 PreferredToolkit getPreferredToolkit() {
123 137 static PreferredToolkit pref = unset;
124 138 if (pref != unset) return pref;
125 139
126 140 PreferredToolkit prefFromEnv = getPreferredToolkitFromEnv();
127 141 if (prefFromEnv != unset) return pref = prefFromEnv;
128 142
129 143 if (isInAquaSession()) return pref = CToolkit;
130 144 if (isXDisplayDefined()) return pref = XToolkit;
131 145 return pref = HToolkit;
132 146 }
133 147
134 148 void setUnknownOSAndVersion(java_props_t *sprops) {
135 149 sprops->os_name = strdup("Unknown");
136 150 sprops->os_version = strdup("Unknown");
137 151 }
138 152
139 153 void setOSNameAndVersion(java_props_t *sprops) {
140 154 void *jrsFwk = getJRSFramework();
141 155 if (jrsFwk == NULL) {
142 156 setUnknownOSAndVersion(sprops);
143 157 return;
144 158 }
145 159
146 160 char *(*copyOSName)() = dlsym(jrsFwk, "JRSCopyOSName");
147 161 char *(*copyOSVersion)() = dlsym(jrsFwk, "JRSCopyOSVersion");
148 162 if (copyOSName == NULL || copyOSVersion == NULL) {
149 163 setUnknownOSAndVersion(sprops);
150 164 return;
151 165 }
152 166
153 167 sprops->os_name = copyOSName();
154 168 sprops->os_version = copyOSVersion();
155 169 }
156 170
157 171
158 172 static Boolean getProxyInfoForProtocol(CFDictionaryRef inDict, CFStringRef inEnabledKey, CFStringRef inHostKey, CFStringRef inPortKey, CFStringRef *outProxyHost, int *ioProxyPort) {
159 173 /* See if the proxy is enabled. */
160 174 CFNumberRef cf_enabled = CFDictionaryGetValue(inDict, inEnabledKey);
161 175 if (cf_enabled == NULL) {
162 176 return false;
163 177 }
164 178
165 179 int isEnabled = false;
166 180 if (!CFNumberGetValue(cf_enabled, kCFNumberIntType, &isEnabled)) {
167 181 return isEnabled;
168 182 }
169 183
170 184 if (!isEnabled) return false;
171 185 *outProxyHost = CFDictionaryGetValue(inDict, inHostKey);
172 186
173 187 // If cf_host is null, that means the checkbox is set,
174 188 // but no host was entered. We'll treat that as NOT ENABLED.
175 189 // If cf_port is null or cf_port isn't a number, that means
176 190 // no port number was entered. Treat this as ENABLED with the
177 191 // protocol's default port.
178 192 if (*outProxyHost == NULL) {
179 193 return false;
180 194 }
181 195
182 196 if (CFStringGetLength(*outProxyHost) == 0) {
183 197 return false;
184 198 }
185 199
186 200 int newPort = 0;
187 201 CFNumberRef cf_port = NULL;
188 202 if ((cf_port = CFDictionaryGetValue(inDict, inPortKey)) != NULL &&
189 203 CFNumberGetValue(cf_port, kCFNumberIntType, &newPort) &&
190 204 newPort > 0) {
191 205 *ioProxyPort = newPort;
192 206 } else {
193 207 // bad port or no port - leave *ioProxyPort unchanged
194 208 }
195 209
196 210 return true;
197 211 }
198 212
199 213 static char *createUTF8CString(const CFStringRef theString) {
200 214 if (theString == NULL) return NULL;
201 215
202 216 const CFIndex stringLength = CFStringGetLength(theString);
203 217 const CFIndex bufSize = CFStringGetMaximumSizeForEncoding(stringLength, kCFStringEncodingUTF8) + 1;
204 218 char *returnVal = (char *)malloc(bufSize);
205 219
206 220 if (CFStringGetCString(theString, returnVal, bufSize, kCFStringEncodingUTF8)) {
207 221 return returnVal;
208 222 }
209 223
210 224 free(returnVal);
211 225 return NULL;
212 226 }
213 227
214 228 // Return TRUE if str is a syntactically valid IP address.
215 229 // Using inet_pton() instead of inet_aton() for IPv6 support.
216 230 // len is only a hint; cstr must still be nul-terminated
217 231 static int looksLikeIPAddress(char *cstr, size_t len) {
218 232 if (len == 0 || (len == 1 && cstr[0] == '.')) return FALSE;
219 233
220 234 char dst[16]; // big enough for INET6
221 235 return (1 == inet_pton(AF_INET, cstr, dst) ||
222 236 1 == inet_pton(AF_INET6, cstr, dst));
223 237 }
224 238
225 239
226 240
227 241 // Convert Mac OS X proxy exception entry to Java syntax.
228 242 // See Radar #3441134 for details.
229 243 // Returns NULL if this exception should be ignored by Java.
230 244 // May generate a string with multiple exceptions separated by '|'.
231 245 static char * createConvertedException(CFStringRef cf_original) {
232 246 // This is done with char* instead of CFString because inet_pton()
233 247 // needs a C string.
234 248 char *c_exception = createUTF8CString(cf_original);
235 249 if (!c_exception) return NULL;
236 250
237 251 int c_len = strlen(c_exception);
238 252
239 253 // 1. sanitize exception prefix
240 254 if (c_len >= 1 && 0 == strncmp(c_exception, ".", 1)) {
241 255 memmove(c_exception, c_exception+1, c_len);
242 256 c_len -= 1;
243 257 } else if (c_len >= 2 && 0 == strncmp(c_exception, "*.", 2)) {
244 258 memmove(c_exception, c_exception+2, c_len-1);
245 259 c_len -= 2;
246 260 }
247 261
248 262 // 2. pre-reject other exception wildcards
249 263 if (strchr(c_exception, '*')) {
250 264 free(c_exception);
251 265 return NULL;
252 266 }
253 267
254 268 // 3. no IP wildcarding
255 269 if (looksLikeIPAddress(c_exception, c_len)) {
256 270 return c_exception;
257 271 }
258 272
259 273 // 4. allow domain suffixes
260 274 // c_exception is now "str\0" - change to "str|*.str\0"
261 275 c_exception = reallocf(c_exception, c_len+3+c_len+1);
262 276 if (!c_exception) return NULL;
263 277
264 278 strncpy(c_exception+c_len, "|*.", 3);
265 279 strncpy(c_exception+c_len+3, c_exception, c_len);
266 280 c_exception[c_len+3+c_len] = '\0';
267 281 return c_exception;
268 282 }
269 283
270 284
271 285 /*
272 286 * Method for fetching proxy info and storing it in the propery list.
273 287 */
274 288 void setProxyProperties(java_props_t *sProps) {
275 289 if (sProps == NULL) return;
276 290
277 291 char buf[16]; /* Used for %d of an int - 16 is plenty */
278 292 CFStringRef
279 293 cf_httpHost = NULL,
280 294 cf_httpsHost = NULL,
281 295 cf_ftpHost = NULL,
282 296 cf_socksHost = NULL,
283 297 cf_gopherHost = NULL;
284 298 int
285 299 httpPort = 80, // Default proxy port values
286 300 httpsPort = 443,
287 301 ftpPort = 21,
288 302 socksPort = 1080,
289 303 gopherPort = 70;
290 304
291 305 CFDictionaryRef dict = SCDynamicStoreCopyProxies(NULL);
292 306 if (dict == NULL) return;
293 307
294 308 /* Read the proxy exceptions list */
295 309 CFArrayRef cf_list = CFDictionaryGetValue(dict, kSCPropNetProxiesExceptionsList);
296 310
297 311 CFMutableStringRef cf_exceptionList = NULL;
298 312 if (cf_list != NULL) {
299 313 CFIndex len = CFArrayGetCount(cf_list), idx;
300 314
301 315 cf_exceptionList = CFStringCreateMutable(NULL, 0);
302 316 for (idx = (CFIndex)0; idx < len; idx++) {
303 317 CFStringRef cf_ehost;
304 318 if ((cf_ehost = CFArrayGetValueAtIndex(cf_list, idx))) {
305 319 /* Convert this exception from Mac OS X syntax to Java syntax.
306 320 See Radar #3441134 for details. This may generate a string
307 321 with multiple Java exceptions separated by '|'. */
308 322 char *c_exception = createConvertedException(cf_ehost);
309 323 if (c_exception) {
310 324 /* Append the host to the list of exclusions. */
311 325 if (CFStringGetLength(cf_exceptionList) > 0) {
312 326 CFStringAppendCString(cf_exceptionList, "|", kCFStringEncodingMacRoman);
313 327 }
314 328 CFStringAppendCString(cf_exceptionList, c_exception, kCFStringEncodingMacRoman);
315 329 free(c_exception);
316 330 }
317 331 }
318 332 }
319 333 }
320 334
321 335 if (cf_exceptionList != NULL) {
322 336 if (CFStringGetLength(cf_exceptionList) > 0) {
323 337 sProps->exceptionList = createUTF8CString(cf_exceptionList);
324 338 }
325 339 CFRelease(cf_exceptionList);
326 340 }
327 341
328 342 #define CHECK_PROXY(protocol, PROTOCOL) \
329 343 sProps->protocol##ProxyEnabled = \
330 344 getProxyInfoForProtocol(dict, kSCPropNetProxies##PROTOCOL##Enable, \
331 345 kSCPropNetProxies##PROTOCOL##Proxy, \
332 346 kSCPropNetProxies##PROTOCOL##Port, \
333 347 &cf_##protocol##Host, &protocol##Port); \
334 348 if (sProps->protocol##ProxyEnabled) { \
335 349 sProps->protocol##Host = createUTF8CString(cf_##protocol##Host); \
336 350 snprintf(buf, sizeof(buf), "%d", protocol##Port); \
337 351 sProps->protocol##Port = malloc(strlen(buf) + 1); \
338 352 strcpy(sProps->protocol##Port, buf); \
339 353 }
340 354
341 355 CHECK_PROXY(http, HTTP);
342 356 CHECK_PROXY(https, HTTPS);
343 357 CHECK_PROXY(ftp, FTP);
344 358 CHECK_PROXY(socks, SOCKS);
345 359 CHECK_PROXY(gopher, Gopher);
346 360
347 361 #undef CHECK_PROXY
348 362
349 363 CFRelease(dict);
350 364 }
↓ open down ↓ |
248 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX