author | naoto |
Mon, 06 Mar 2017 18:54:53 -0800 | |
changeset 44044 | f1398789e771 |
parent 43799 | 0e642fbacb25 |
child 45829 | 991121499947 |
permissions | -rw-r--r-- |
12047 | 1 |
/* |
43799 | 2 |
* Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved. |
12047 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
#include <sys/socket.h> |
|
27 |
#include <netinet/in.h> |
|
28 |
#include <arpa/inet.h> |
|
39144
50f8aee9012d
7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents:
33653
diff
changeset
|
29 |
#include <objc/objc-runtime.h> |
12047 | 30 |
|
31 |
#include <Security/AuthSession.h> |
|
32 |
#include <CoreFoundation/CoreFoundation.h> |
|
33 |
#include <SystemConfiguration/SystemConfiguration.h> |
|
19857
d3a868255edb
7199674: (props) user.home property does not return an accessible location in sandboxed environment [macosx]
bchristi
parents:
14662
diff
changeset
|
34 |
#include <Foundation/Foundation.h> |
12047 | 35 |
|
36 |
#include "java_props_macosx.h" |
|
37 |
||
13583 | 38 |
char *getPosixLocale(int cat) { |
12047 | 39 |
char *lc = setlocale(cat, NULL); |
40 |
if ((lc == NULL) || (strcmp(lc, "C") == 0)) { |
|
41 |
lc = getenv("LANG"); |
|
42 |
} |
|
43 |
if (lc == NULL) return NULL; |
|
44 |
return strdup(lc); |
|
45 |
} |
|
46 |
||
47 |
#define LOCALEIDLENGTH 128 |
|
13583 | 48 |
char *getMacOSXLocale(int cat) { |
44044
f1398789e771
8174736: [JCP] [Mac]Cannot launch JCP on Mac os with language set to "Chinese, Simplified" while region is not China
naoto
parents:
43799
diff
changeset
|
49 |
const char* retVal = NULL; |
f1398789e771
8174736: [JCP] [Mac]Cannot launch JCP on Mac os with language set to "Chinese, Simplified" while region is not China
naoto
parents:
43799
diff
changeset
|
50 |
|
12047 | 51 |
switch (cat) { |
52 |
case LC_MESSAGES: |
|
53 |
{ |
|
39144
50f8aee9012d
7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents:
33653
diff
changeset
|
54 |
// get preferred language code |
50f8aee9012d
7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents:
33653
diff
changeset
|
55 |
CFArrayRef languages = CFLocaleCopyPreferredLanguages(); |
50f8aee9012d
7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents:
33653
diff
changeset
|
56 |
if (languages == NULL) { |
50f8aee9012d
7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents:
33653
diff
changeset
|
57 |
return NULL; |
50f8aee9012d
7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents:
33653
diff
changeset
|
58 |
} |
50f8aee9012d
7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents:
33653
diff
changeset
|
59 |
if (CFArrayGetCount(languages) <= 0) { |
50f8aee9012d
7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents:
33653
diff
changeset
|
60 |
CFRelease(languages); |
50f8aee9012d
7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents:
33653
diff
changeset
|
61 |
return NULL; |
50f8aee9012d
7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents:
33653
diff
changeset
|
62 |
} |
50f8aee9012d
7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents:
33653
diff
changeset
|
63 |
|
50f8aee9012d
7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents:
33653
diff
changeset
|
64 |
CFStringRef primaryLanguage = (CFStringRef)CFArrayGetValueAtIndex(languages, 0); |
50f8aee9012d
7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents:
33653
diff
changeset
|
65 |
if (primaryLanguage == NULL) { |
50f8aee9012d
7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents:
33653
diff
changeset
|
66 |
CFRelease(languages); |
50f8aee9012d
7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents:
33653
diff
changeset
|
67 |
return NULL; |
50f8aee9012d
7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents:
33653
diff
changeset
|
68 |
} |
50f8aee9012d
7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents:
33653
diff
changeset
|
69 |
char languageString[LOCALEIDLENGTH]; |
50f8aee9012d
7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents:
33653
diff
changeset
|
70 |
if (CFStringGetCString(primaryLanguage, languageString, |
50f8aee9012d
7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents:
33653
diff
changeset
|
71 |
LOCALEIDLENGTH, CFStringGetSystemEncoding()) == false) { |
50f8aee9012d
7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents:
33653
diff
changeset
|
72 |
CFRelease(languages); |
50f8aee9012d
7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents:
33653
diff
changeset
|
73 |
return NULL; |
50f8aee9012d
7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents:
33653
diff
changeset
|
74 |
} |
50f8aee9012d
7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents:
33653
diff
changeset
|
75 |
CFRelease(languages); |
12047 | 76 |
|
44044
f1398789e771
8174736: [JCP] [Mac]Cannot launch JCP on Mac os with language set to "Chinese, Simplified" while region is not China
naoto
parents:
43799
diff
changeset
|
77 |
retVal = languageString; |
12047 | 78 |
|
39144
50f8aee9012d
7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents:
33653
diff
changeset
|
79 |
// Special case for Portuguese in Brazil: |
50f8aee9012d
7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents:
33653
diff
changeset
|
80 |
// The language code needs the "_BR" region code (to distinguish it |
50f8aee9012d
7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents:
33653
diff
changeset
|
81 |
// from Portuguese in Portugal), but this is missing when using the |
50f8aee9012d
7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents:
33653
diff
changeset
|
82 |
// "Portuguese (Brazil)" language. |
50f8aee9012d
7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents:
33653
diff
changeset
|
83 |
// If language is "pt" and the current locale is pt_BR, return pt_BR. |
50f8aee9012d
7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents:
33653
diff
changeset
|
84 |
char localeString[LOCALEIDLENGTH]; |
50f8aee9012d
7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents:
33653
diff
changeset
|
85 |
if (strcmp(retVal, "pt") == 0 && |
50f8aee9012d
7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents:
33653
diff
changeset
|
86 |
CFStringGetCString(CFLocaleGetIdentifier(CFLocaleCopyCurrent()), |
50f8aee9012d
7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents:
33653
diff
changeset
|
87 |
localeString, LOCALEIDLENGTH, CFStringGetSystemEncoding()) && |
50f8aee9012d
7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents:
33653
diff
changeset
|
88 |
strcmp(localeString, "pt_BR") == 0) { |
50f8aee9012d
7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents:
33653
diff
changeset
|
89 |
retVal = localeString; |
50f8aee9012d
7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents:
33653
diff
changeset
|
90 |
} |
12047 | 91 |
} |
92 |
break; |
|
93 |
default: |
|
94 |
{ |
|
95 |
char localeString[LOCALEIDLENGTH]; |
|
44044
f1398789e771
8174736: [JCP] [Mac]Cannot launch JCP on Mac os with language set to "Chinese, Simplified" while region is not China
naoto
parents:
43799
diff
changeset
|
96 |
if (!CFStringGetCString(CFLocaleGetIdentifier(CFLocaleCopyCurrent()), |
f1398789e771
8174736: [JCP] [Mac]Cannot launch JCP on Mac os with language set to "Chinese, Simplified" while region is not China
naoto
parents:
43799
diff
changeset
|
97 |
localeString, LOCALEIDLENGTH, CFStringGetSystemEncoding())) { |
f1398789e771
8174736: [JCP] [Mac]Cannot launch JCP on Mac os with language set to "Chinese, Simplified" while region is not China
naoto
parents:
43799
diff
changeset
|
98 |
return NULL; |
12047 | 99 |
} |
44044
f1398789e771
8174736: [JCP] [Mac]Cannot launch JCP on Mac os with language set to "Chinese, Simplified" while region is not China
naoto
parents:
43799
diff
changeset
|
100 |
retVal = localeString; |
12047 | 101 |
} |
102 |
break; |
|
103 |
} |
|
104 |
||
44044
f1398789e771
8174736: [JCP] [Mac]Cannot launch JCP on Mac os with language set to "Chinese, Simplified" while region is not China
naoto
parents:
43799
diff
changeset
|
105 |
if (retVal != NULL) { |
f1398789e771
8174736: [JCP] [Mac]Cannot launch JCP on Mac os with language set to "Chinese, Simplified" while region is not China
naoto
parents:
43799
diff
changeset
|
106 |
// Language IDs use the language designators and (optional) region |
f1398789e771
8174736: [JCP] [Mac]Cannot launch JCP on Mac os with language set to "Chinese, Simplified" while region is not China
naoto
parents:
43799
diff
changeset
|
107 |
// and script designators of BCP 47. So possible formats are: |
f1398789e771
8174736: [JCP] [Mac]Cannot launch JCP on Mac os with language set to "Chinese, Simplified" while region is not China
naoto
parents:
43799
diff
changeset
|
108 |
// |
f1398789e771
8174736: [JCP] [Mac]Cannot launch JCP on Mac os with language set to "Chinese, Simplified" while region is not China
naoto
parents:
43799
diff
changeset
|
109 |
// "en" (language designator only) |
f1398789e771
8174736: [JCP] [Mac]Cannot launch JCP on Mac os with language set to "Chinese, Simplified" while region is not China
naoto
parents:
43799
diff
changeset
|
110 |
// "haw" (3-letter lanuage designator) |
f1398789e771
8174736: [JCP] [Mac]Cannot launch JCP on Mac os with language set to "Chinese, Simplified" while region is not China
naoto
parents:
43799
diff
changeset
|
111 |
// "en-GB" (language with alpha-2 region designator) |
f1398789e771
8174736: [JCP] [Mac]Cannot launch JCP on Mac os with language set to "Chinese, Simplified" while region is not China
naoto
parents:
43799
diff
changeset
|
112 |
// "es-419" (language with 3-digit UN M.49 area code) |
f1398789e771
8174736: [JCP] [Mac]Cannot launch JCP on Mac os with language set to "Chinese, Simplified" while region is not China
naoto
parents:
43799
diff
changeset
|
113 |
// "zh-Hans" (language with ISO 15924 script designator) |
f1398789e771
8174736: [JCP] [Mac]Cannot launch JCP on Mac os with language set to "Chinese, Simplified" while region is not China
naoto
parents:
43799
diff
changeset
|
114 |
// "zh-Hans-US" (language with ISO 15924 script designator and region) |
f1398789e771
8174736: [JCP] [Mac]Cannot launch JCP on Mac os with language set to "Chinese, Simplified" while region is not China
naoto
parents:
43799
diff
changeset
|
115 |
// "zh-Hans-419" (language with ISO 15924 script designator and UN M.49) |
f1398789e771
8174736: [JCP] [Mac]Cannot launch JCP on Mac os with language set to "Chinese, Simplified" while region is not China
naoto
parents:
43799
diff
changeset
|
116 |
// |
f1398789e771
8174736: [JCP] [Mac]Cannot launch JCP on Mac os with language set to "Chinese, Simplified" while region is not China
naoto
parents:
43799
diff
changeset
|
117 |
// In the case of region designators (alpha-2 and/or UN M.49), we convert |
f1398789e771
8174736: [JCP] [Mac]Cannot launch JCP on Mac os with language set to "Chinese, Simplified" while region is not China
naoto
parents:
43799
diff
changeset
|
118 |
// to our locale string format by changing '-' to '_'. That is, if |
f1398789e771
8174736: [JCP] [Mac]Cannot launch JCP on Mac os with language set to "Chinese, Simplified" while region is not China
naoto
parents:
43799
diff
changeset
|
119 |
// the '-' is followed by fewer than 4 chars. |
f1398789e771
8174736: [JCP] [Mac]Cannot launch JCP on Mac os with language set to "Chinese, Simplified" while region is not China
naoto
parents:
43799
diff
changeset
|
120 |
char* scriptOrRegion = strchr(retVal, '-'); |
f1398789e771
8174736: [JCP] [Mac]Cannot launch JCP on Mac os with language set to "Chinese, Simplified" while region is not China
naoto
parents:
43799
diff
changeset
|
121 |
if (scriptOrRegion != NULL) { |
f1398789e771
8174736: [JCP] [Mac]Cannot launch JCP on Mac os with language set to "Chinese, Simplified" while region is not China
naoto
parents:
43799
diff
changeset
|
122 |
int length = strlen(scriptOrRegion); |
f1398789e771
8174736: [JCP] [Mac]Cannot launch JCP on Mac os with language set to "Chinese, Simplified" while region is not China
naoto
parents:
43799
diff
changeset
|
123 |
if (length > 5) { |
f1398789e771
8174736: [JCP] [Mac]Cannot launch JCP on Mac os with language set to "Chinese, Simplified" while region is not China
naoto
parents:
43799
diff
changeset
|
124 |
// Region and script both exist. Honor the script for now |
f1398789e771
8174736: [JCP] [Mac]Cannot launch JCP on Mac os with language set to "Chinese, Simplified" while region is not China
naoto
parents:
43799
diff
changeset
|
125 |
scriptOrRegion[5] = '\0'; |
f1398789e771
8174736: [JCP] [Mac]Cannot launch JCP on Mac os with language set to "Chinese, Simplified" while region is not China
naoto
parents:
43799
diff
changeset
|
126 |
} else if (length < 5) { |
f1398789e771
8174736: [JCP] [Mac]Cannot launch JCP on Mac os with language set to "Chinese, Simplified" while region is not China
naoto
parents:
43799
diff
changeset
|
127 |
*scriptOrRegion = '_'; |
f1398789e771
8174736: [JCP] [Mac]Cannot launch JCP on Mac os with language set to "Chinese, Simplified" while region is not China
naoto
parents:
43799
diff
changeset
|
128 |
|
f1398789e771
8174736: [JCP] [Mac]Cannot launch JCP on Mac os with language set to "Chinese, Simplified" while region is not China
naoto
parents:
43799
diff
changeset
|
129 |
assert((length == 3 && |
f1398789e771
8174736: [JCP] [Mac]Cannot launch JCP on Mac os with language set to "Chinese, Simplified" while region is not China
naoto
parents:
43799
diff
changeset
|
130 |
// '-' followed by a 2 character region designator |
f1398789e771
8174736: [JCP] [Mac]Cannot launch JCP on Mac os with language set to "Chinese, Simplified" while region is not China
naoto
parents:
43799
diff
changeset
|
131 |
isalpha(scriptOrRegion[1]) && |
f1398789e771
8174736: [JCP] [Mac]Cannot launch JCP on Mac os with language set to "Chinese, Simplified" while region is not China
naoto
parents:
43799
diff
changeset
|
132 |
isalpha(scriptOrRegion[2])) || |
f1398789e771
8174736: [JCP] [Mac]Cannot launch JCP on Mac os with language set to "Chinese, Simplified" while region is not China
naoto
parents:
43799
diff
changeset
|
133 |
(length == 4 && |
f1398789e771
8174736: [JCP] [Mac]Cannot launch JCP on Mac os with language set to "Chinese, Simplified" while region is not China
naoto
parents:
43799
diff
changeset
|
134 |
// '-' followed by a 3-digit UN M.49 area code |
f1398789e771
8174736: [JCP] [Mac]Cannot launch JCP on Mac os with language set to "Chinese, Simplified" while region is not China
naoto
parents:
43799
diff
changeset
|
135 |
isdigit(scriptOrRegion[1]) && |
f1398789e771
8174736: [JCP] [Mac]Cannot launch JCP on Mac os with language set to "Chinese, Simplified" while region is not China
naoto
parents:
43799
diff
changeset
|
136 |
isdigit(scriptOrRegion[2]) && |
f1398789e771
8174736: [JCP] [Mac]Cannot launch JCP on Mac os with language set to "Chinese, Simplified" while region is not China
naoto
parents:
43799
diff
changeset
|
137 |
isdigit(scriptOrRegion[3]))); |
f1398789e771
8174736: [JCP] [Mac]Cannot launch JCP on Mac os with language set to "Chinese, Simplified" while region is not China
naoto
parents:
43799
diff
changeset
|
138 |
} |
f1398789e771
8174736: [JCP] [Mac]Cannot launch JCP on Mac os with language set to "Chinese, Simplified" while region is not China
naoto
parents:
43799
diff
changeset
|
139 |
} |
f1398789e771
8174736: [JCP] [Mac]Cannot launch JCP on Mac os with language set to "Chinese, Simplified" while region is not China
naoto
parents:
43799
diff
changeset
|
140 |
|
f1398789e771
8174736: [JCP] [Mac]Cannot launch JCP on Mac os with language set to "Chinese, Simplified" while region is not China
naoto
parents:
43799
diff
changeset
|
141 |
return strdup(retVal); |
f1398789e771
8174736: [JCP] [Mac]Cannot launch JCP on Mac os with language set to "Chinese, Simplified" while region is not China
naoto
parents:
43799
diff
changeset
|
142 |
} |
12047 | 143 |
return NULL; |
144 |
} |
|
145 |
||
13583 | 146 |
char *setupMacOSXLocale(int cat) { |
147 |
char * ret = getMacOSXLocale(cat); |
|
148 |
||
149 |
if (ret == NULL) { |
|
150 |
return getPosixLocale(cat); |
|
151 |
} else { |
|
152 |
return ret; |
|
153 |
} |
|
154 |
} |
|
155 |
||
21130 | 156 |
int isInAquaSession() { |
21536
032532f158ae
8027912: [macosx] Provide means to force the headful mode on OS X when running via ssh
anthony
parents:
21130
diff
changeset
|
157 |
// environment variable to bypass the aqua session check |
032532f158ae
8027912: [macosx] Provide means to force the headful mode on OS X when running via ssh
anthony
parents:
21130
diff
changeset
|
158 |
char *ev = getenv("AWT_FORCE_HEADFUL"); |
032532f158ae
8027912: [macosx] Provide means to force the headful mode on OS X when running via ssh
anthony
parents:
21130
diff
changeset
|
159 |
if (ev && (strncasecmp(ev, "true", 4) == 0)) { |
032532f158ae
8027912: [macosx] Provide means to force the headful mode on OS X when running via ssh
anthony
parents:
21130
diff
changeset
|
160 |
// if "true" then tell the caller we're in an Aqua session without actually checking |
032532f158ae
8027912: [macosx] Provide means to force the headful mode on OS X when running via ssh
anthony
parents:
21130
diff
changeset
|
161 |
return 1; |
032532f158ae
8027912: [macosx] Provide means to force the headful mode on OS X when running via ssh
anthony
parents:
21130
diff
changeset
|
162 |
} |
12047 | 163 |
// Is the WindowServer available? |
164 |
SecuritySessionId session_id; |
|
165 |
SessionAttributeBits session_info; |
|
166 |
OSStatus status = SessionGetInfo(callerSecuritySession, &session_id, &session_info); |
|
21130 | 167 |
if (status == noErr) { |
168 |
if (session_info & sessionHasGraphicAccess) { |
|
169 |
return 1; |
|
170 |
} |
|
171 |
} |
|
172 |
return 0; |
|
12047 | 173 |
} |
174 |
||
39144
50f8aee9012d
7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents:
33653
diff
changeset
|
175 |
// 10.9 SDK does not include the NSOperatingSystemVersion struct. |
50f8aee9012d
7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents:
33653
diff
changeset
|
176 |
// For now, create our own |
50f8aee9012d
7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents:
33653
diff
changeset
|
177 |
typedef struct { |
50f8aee9012d
7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents:
33653
diff
changeset
|
178 |
NSInteger majorVersion; |
50f8aee9012d
7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents:
33653
diff
changeset
|
179 |
NSInteger minorVersion; |
50f8aee9012d
7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents:
33653
diff
changeset
|
180 |
NSInteger patchVersion; |
50f8aee9012d
7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents:
33653
diff
changeset
|
181 |
} OSVerStruct; |
50f8aee9012d
7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents:
33653
diff
changeset
|
182 |
|
14513
f6dc8c52e275
7178922: (props) re-visit how os.name is determined on Mac
bchristi
parents:
14342
diff
changeset
|
183 |
void setOSNameAndVersion(java_props_t *sprops) { |
39144
50f8aee9012d
7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents:
33653
diff
changeset
|
184 |
// Hardcode os_name, and fill in os_version |
14513
f6dc8c52e275
7178922: (props) re-visit how os.name is determined on Mac
bchristi
parents:
14342
diff
changeset
|
185 |
sprops->os_name = strdup("Mac OS X"); |
12047 | 186 |
|
39144
50f8aee9012d
7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents:
33653
diff
changeset
|
187 |
char* osVersionCStr = NULL; |
50f8aee9012d
7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents:
33653
diff
changeset
|
188 |
// Mac OS 10.9 includes the [NSProcessInfo operatingSystemVersion] function, |
50f8aee9012d
7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents:
33653
diff
changeset
|
189 |
// but it's not in the 10.9 SDK. So, call it via objc_msgSend_stret. |
50f8aee9012d
7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents:
33653
diff
changeset
|
190 |
if ([[NSProcessInfo processInfo] respondsToSelector:@selector(operatingSystemVersion)]) { |
50f8aee9012d
7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents:
33653
diff
changeset
|
191 |
OSVerStruct (*procInfoFn)(id rec, SEL sel) = (OSVerStruct(*)(id, SEL))objc_msgSend_stret; |
50f8aee9012d
7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents:
33653
diff
changeset
|
192 |
OSVerStruct osVer = procInfoFn([NSProcessInfo processInfo], |
50f8aee9012d
7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents:
33653
diff
changeset
|
193 |
@selector(operatingSystemVersion)); |
39765
c1aee33ef0c0
8161039: System.getProperty("os.version") returns incorrect version number on Mac
bchristi
parents:
39322
diff
changeset
|
194 |
NSString *nsVerStr; |
c1aee33ef0c0
8161039: System.getProperty("os.version") returns incorrect version number on Mac
bchristi
parents:
39322
diff
changeset
|
195 |
if (osVer.patchVersion == 0) { // Omit trailing ".0" |
c1aee33ef0c0
8161039: System.getProperty("os.version") returns incorrect version number on Mac
bchristi
parents:
39322
diff
changeset
|
196 |
nsVerStr = [NSString stringWithFormat:@"%ld.%ld", |
c1aee33ef0c0
8161039: System.getProperty("os.version") returns incorrect version number on Mac
bchristi
parents:
39322
diff
changeset
|
197 |
(long)osVer.majorVersion, (long)osVer.minorVersion]; |
c1aee33ef0c0
8161039: System.getProperty("os.version") returns incorrect version number on Mac
bchristi
parents:
39322
diff
changeset
|
198 |
} else { |
c1aee33ef0c0
8161039: System.getProperty("os.version") returns incorrect version number on Mac
bchristi
parents:
39322
diff
changeset
|
199 |
nsVerStr = [NSString stringWithFormat:@"%ld.%ld.%ld", |
c1aee33ef0c0
8161039: System.getProperty("os.version") returns incorrect version number on Mac
bchristi
parents:
39322
diff
changeset
|
200 |
(long)osVer.majorVersion, (long)osVer.minorVersion, (long)osVer.patchVersion]; |
c1aee33ef0c0
8161039: System.getProperty("os.version") returns incorrect version number on Mac
bchristi
parents:
39322
diff
changeset
|
201 |
} |
39144
50f8aee9012d
7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents:
33653
diff
changeset
|
202 |
// Copy out the char* |
50f8aee9012d
7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents:
33653
diff
changeset
|
203 |
osVersionCStr = strdup([nsVerStr UTF8String]); |
12047 | 204 |
} |
39322
66ecf193683a
8160370: System.getProperty("os.version") returns "Unknown" on Mac
bchristi
parents:
39144
diff
changeset
|
205 |
// Fallback if running on pre-10.9 Mac OS |
66ecf193683a
8160370: System.getProperty("os.version") returns "Unknown" on Mac
bchristi
parents:
39144
diff
changeset
|
206 |
if (osVersionCStr == NULL) { |
66ecf193683a
8160370: System.getProperty("os.version") returns "Unknown" on Mac
bchristi
parents:
39144
diff
changeset
|
207 |
NSDictionary *version = [NSDictionary dictionaryWithContentsOfFile : |
66ecf193683a
8160370: System.getProperty("os.version") returns "Unknown" on Mac
bchristi
parents:
39144
diff
changeset
|
208 |
@"/System/Library/CoreServices/SystemVersion.plist"]; |
66ecf193683a
8160370: System.getProperty("os.version") returns "Unknown" on Mac
bchristi
parents:
39144
diff
changeset
|
209 |
if (version != NULL) { |
66ecf193683a
8160370: System.getProperty("os.version") returns "Unknown" on Mac
bchristi
parents:
39144
diff
changeset
|
210 |
NSString *nsVerStr = [version objectForKey : @"ProductVersion"]; |
66ecf193683a
8160370: System.getProperty("os.version") returns "Unknown" on Mac
bchristi
parents:
39144
diff
changeset
|
211 |
if (nsVerStr != NULL) { |
66ecf193683a
8160370: System.getProperty("os.version") returns "Unknown" on Mac
bchristi
parents:
39144
diff
changeset
|
212 |
osVersionCStr = strdup([nsVerStr UTF8String]); |
66ecf193683a
8160370: System.getProperty("os.version") returns "Unknown" on Mac
bchristi
parents:
39144
diff
changeset
|
213 |
} |
66ecf193683a
8160370: System.getProperty("os.version") returns "Unknown" on Mac
bchristi
parents:
39144
diff
changeset
|
214 |
} |
66ecf193683a
8160370: System.getProperty("os.version") returns "Unknown" on Mac
bchristi
parents:
39144
diff
changeset
|
215 |
} |
39144
50f8aee9012d
7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents:
33653
diff
changeset
|
216 |
if (osVersionCStr == NULL) { |
50f8aee9012d
7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents:
33653
diff
changeset
|
217 |
osVersionCStr = strdup("Unknown"); |
50f8aee9012d
7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents:
33653
diff
changeset
|
218 |
} |
50f8aee9012d
7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents:
33653
diff
changeset
|
219 |
sprops->os_version = osVersionCStr; |
12047 | 220 |
} |
221 |
||
222 |
||
39322
66ecf193683a
8160370: System.getProperty("os.version") returns "Unknown" on Mac
bchristi
parents:
39144
diff
changeset
|
223 |
static Boolean getProxyInfoForProtocol(CFDictionaryRef inDict, CFStringRef inEnabledKey, |
66ecf193683a
8160370: System.getProperty("os.version") returns "Unknown" on Mac
bchristi
parents:
39144
diff
changeset
|
224 |
CFStringRef inHostKey, CFStringRef inPortKey, |
66ecf193683a
8160370: System.getProperty("os.version") returns "Unknown" on Mac
bchristi
parents:
39144
diff
changeset
|
225 |
CFStringRef *outProxyHost, int *ioProxyPort) { |
12047 | 226 |
/* See if the proxy is enabled. */ |
227 |
CFNumberRef cf_enabled = CFDictionaryGetValue(inDict, inEnabledKey); |
|
228 |
if (cf_enabled == NULL) { |
|
229 |
return false; |
|
230 |
} |
|
231 |
||
232 |
int isEnabled = false; |
|
233 |
if (!CFNumberGetValue(cf_enabled, kCFNumberIntType, &isEnabled)) { |
|
234 |
return isEnabled; |
|
235 |
} |
|
236 |
||
237 |
if (!isEnabled) return false; |
|
238 |
*outProxyHost = CFDictionaryGetValue(inDict, inHostKey); |
|
239 |
||
240 |
// If cf_host is null, that means the checkbox is set, |
|
241 |
// but no host was entered. We'll treat that as NOT ENABLED. |
|
242 |
// If cf_port is null or cf_port isn't a number, that means |
|
243 |
// no port number was entered. Treat this as ENABLED with the |
|
244 |
// protocol's default port. |
|
245 |
if (*outProxyHost == NULL) { |
|
246 |
return false; |
|
247 |
} |
|
248 |
||
249 |
if (CFStringGetLength(*outProxyHost) == 0) { |
|
250 |
return false; |
|
251 |
} |
|
252 |
||
253 |
int newPort = 0; |
|
254 |
CFNumberRef cf_port = NULL; |
|
255 |
if ((cf_port = CFDictionaryGetValue(inDict, inPortKey)) != NULL && |
|
256 |
CFNumberGetValue(cf_port, kCFNumberIntType, &newPort) && |
|
257 |
newPort > 0) { |
|
258 |
*ioProxyPort = newPort; |
|
259 |
} else { |
|
260 |
// bad port or no port - leave *ioProxyPort unchanged |
|
261 |
} |
|
262 |
||
263 |
return true; |
|
264 |
} |
|
265 |
||
266 |
static char *createUTF8CString(const CFStringRef theString) { |
|
267 |
if (theString == NULL) return NULL; |
|
268 |
||
269 |
const CFIndex stringLength = CFStringGetLength(theString); |
|
270 |
const CFIndex bufSize = CFStringGetMaximumSizeForEncoding(stringLength, kCFStringEncodingUTF8) + 1; |
|
271 |
char *returnVal = (char *)malloc(bufSize); |
|
272 |
||
273 |
if (CFStringGetCString(theString, returnVal, bufSize, kCFStringEncodingUTF8)) { |
|
274 |
return returnVal; |
|
275 |
} |
|
276 |
||
277 |
free(returnVal); |
|
278 |
return NULL; |
|
279 |
} |
|
280 |
||
281 |
// Return TRUE if str is a syntactically valid IP address. |
|
282 |
// Using inet_pton() instead of inet_aton() for IPv6 support. |
|
283 |
// len is only a hint; cstr must still be nul-terminated |
|
284 |
static int looksLikeIPAddress(char *cstr, size_t len) { |
|
285 |
if (len == 0 || (len == 1 && cstr[0] == '.')) return FALSE; |
|
286 |
||
287 |
char dst[16]; // big enough for INET6 |
|
288 |
return (1 == inet_pton(AF_INET, cstr, dst) || |
|
289 |
1 == inet_pton(AF_INET6, cstr, dst)); |
|
290 |
} |
|
291 |
||
292 |
||
293 |
||
294 |
// Convert Mac OS X proxy exception entry to Java syntax. |
|
295 |
// See Radar #3441134 for details. |
|
296 |
// Returns NULL if this exception should be ignored by Java. |
|
297 |
// May generate a string with multiple exceptions separated by '|'. |
|
298 |
static char * createConvertedException(CFStringRef cf_original) { |
|
299 |
// This is done with char* instead of CFString because inet_pton() |
|
300 |
// needs a C string. |
|
301 |
char *c_exception = createUTF8CString(cf_original); |
|
302 |
if (!c_exception) return NULL; |
|
303 |
||
304 |
int c_len = strlen(c_exception); |
|
305 |
||
306 |
// 1. sanitize exception prefix |
|
307 |
if (c_len >= 1 && 0 == strncmp(c_exception, ".", 1)) { |
|
308 |
memmove(c_exception, c_exception+1, c_len); |
|
309 |
c_len -= 1; |
|
310 |
} else if (c_len >= 2 && 0 == strncmp(c_exception, "*.", 2)) { |
|
311 |
memmove(c_exception, c_exception+2, c_len-1); |
|
312 |
c_len -= 2; |
|
313 |
} |
|
314 |
||
315 |
// 2. pre-reject other exception wildcards |
|
316 |
if (strchr(c_exception, '*')) { |
|
317 |
free(c_exception); |
|
318 |
return NULL; |
|
319 |
} |
|
320 |
||
321 |
// 3. no IP wildcarding |
|
322 |
if (looksLikeIPAddress(c_exception, c_len)) { |
|
323 |
return c_exception; |
|
324 |
} |
|
325 |
||
326 |
// 4. allow domain suffixes |
|
327 |
// c_exception is now "str\0" - change to "str|*.str\0" |
|
328 |
c_exception = reallocf(c_exception, c_len+3+c_len+1); |
|
329 |
if (!c_exception) return NULL; |
|
330 |
||
331 |
strncpy(c_exception+c_len, "|*.", 3); |
|
332 |
strncpy(c_exception+c_len+3, c_exception, c_len); |
|
333 |
c_exception[c_len+3+c_len] = '\0'; |
|
334 |
return c_exception; |
|
335 |
} |
|
336 |
||
19857
d3a868255edb
7199674: (props) user.home property does not return an accessible location in sandboxed environment [macosx]
bchristi
parents:
14662
diff
changeset
|
337 |
/* |
d3a868255edb
7199674: (props) user.home property does not return an accessible location in sandboxed environment [macosx]
bchristi
parents:
14662
diff
changeset
|
338 |
* Method for fetching the user.home path and storing it in the property list. |
d3a868255edb
7199674: (props) user.home property does not return an accessible location in sandboxed environment [macosx]
bchristi
parents:
14662
diff
changeset
|
339 |
* For signed .apps running in the Mac App Sandbox, user.home is set to the |
d3a868255edb
7199674: (props) user.home property does not return an accessible location in sandboxed environment [macosx]
bchristi
parents:
14662
diff
changeset
|
340 |
* app's sandbox container. |
d3a868255edb
7199674: (props) user.home property does not return an accessible location in sandboxed environment [macosx]
bchristi
parents:
14662
diff
changeset
|
341 |
*/ |
d3a868255edb
7199674: (props) user.home property does not return an accessible location in sandboxed environment [macosx]
bchristi
parents:
14662
diff
changeset
|
342 |
void setUserHome(java_props_t *sprops) { |
d3a868255edb
7199674: (props) user.home property does not return an accessible location in sandboxed environment [macosx]
bchristi
parents:
14662
diff
changeset
|
343 |
if (sprops == NULL) { return; } |
d3a868255edb
7199674: (props) user.home property does not return an accessible location in sandboxed environment [macosx]
bchristi
parents:
14662
diff
changeset
|
344 |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
d3a868255edb
7199674: (props) user.home property does not return an accessible location in sandboxed environment [macosx]
bchristi
parents:
14662
diff
changeset
|
345 |
sprops->user_home = createUTF8CString((CFStringRef)NSHomeDirectory()); |
d3a868255edb
7199674: (props) user.home property does not return an accessible location in sandboxed environment [macosx]
bchristi
parents:
14662
diff
changeset
|
346 |
[pool drain]; |
d3a868255edb
7199674: (props) user.home property does not return an accessible location in sandboxed environment [macosx]
bchristi
parents:
14662
diff
changeset
|
347 |
} |
12047 | 348 |
|
349 |
/* |
|
19857
d3a868255edb
7199674: (props) user.home property does not return an accessible location in sandboxed environment [macosx]
bchristi
parents:
14662
diff
changeset
|
350 |
* Method for fetching proxy info and storing it in the property list. |
12047 | 351 |
*/ |
352 |
void setProxyProperties(java_props_t *sProps) { |
|
353 |
if (sProps == NULL) return; |
|
354 |
||
355 |
char buf[16]; /* Used for %d of an int - 16 is plenty */ |
|
356 |
CFStringRef |
|
357 |
cf_httpHost = NULL, |
|
358 |
cf_httpsHost = NULL, |
|
359 |
cf_ftpHost = NULL, |
|
360 |
cf_socksHost = NULL, |
|
361 |
cf_gopherHost = NULL; |
|
362 |
int |
|
363 |
httpPort = 80, // Default proxy port values |
|
364 |
httpsPort = 443, |
|
365 |
ftpPort = 21, |
|
366 |
socksPort = 1080, |
|
367 |
gopherPort = 70; |
|
368 |
||
369 |
CFDictionaryRef dict = SCDynamicStoreCopyProxies(NULL); |
|
370 |
if (dict == NULL) return; |
|
371 |
||
372 |
/* Read the proxy exceptions list */ |
|
373 |
CFArrayRef cf_list = CFDictionaryGetValue(dict, kSCPropNetProxiesExceptionsList); |
|
374 |
||
375 |
CFMutableStringRef cf_exceptionList = NULL; |
|
376 |
if (cf_list != NULL) { |
|
377 |
CFIndex len = CFArrayGetCount(cf_list), idx; |
|
378 |
||
379 |
cf_exceptionList = CFStringCreateMutable(NULL, 0); |
|
380 |
for (idx = (CFIndex)0; idx < len; idx++) { |
|
381 |
CFStringRef cf_ehost; |
|
382 |
if ((cf_ehost = CFArrayGetValueAtIndex(cf_list, idx))) { |
|
383 |
/* Convert this exception from Mac OS X syntax to Java syntax. |
|
384 |
See Radar #3441134 for details. This may generate a string |
|
385 |
with multiple Java exceptions separated by '|'. */ |
|
386 |
char *c_exception = createConvertedException(cf_ehost); |
|
387 |
if (c_exception) { |
|
388 |
/* Append the host to the list of exclusions. */ |
|
389 |
if (CFStringGetLength(cf_exceptionList) > 0) { |
|
390 |
CFStringAppendCString(cf_exceptionList, "|", kCFStringEncodingMacRoman); |
|
391 |
} |
|
392 |
CFStringAppendCString(cf_exceptionList, c_exception, kCFStringEncodingMacRoman); |
|
393 |
free(c_exception); |
|
394 |
} |
|
395 |
} |
|
396 |
} |
|
397 |
} |
|
398 |
||
399 |
if (cf_exceptionList != NULL) { |
|
400 |
if (CFStringGetLength(cf_exceptionList) > 0) { |
|
401 |
sProps->exceptionList = createUTF8CString(cf_exceptionList); |
|
402 |
} |
|
403 |
CFRelease(cf_exceptionList); |
|
404 |
} |
|
405 |
||
406 |
#define CHECK_PROXY(protocol, PROTOCOL) \ |
|
407 |
sProps->protocol##ProxyEnabled = \ |
|
408 |
getProxyInfoForProtocol(dict, kSCPropNetProxies##PROTOCOL##Enable, \ |
|
409 |
kSCPropNetProxies##PROTOCOL##Proxy, \ |
|
410 |
kSCPropNetProxies##PROTOCOL##Port, \ |
|
411 |
&cf_##protocol##Host, &protocol##Port); \ |
|
412 |
if (sProps->protocol##ProxyEnabled) { \ |
|
413 |
sProps->protocol##Host = createUTF8CString(cf_##protocol##Host); \ |
|
414 |
snprintf(buf, sizeof(buf), "%d", protocol##Port); \ |
|
415 |
sProps->protocol##Port = malloc(strlen(buf) + 1); \ |
|
416 |
strcpy(sProps->protocol##Port, buf); \ |
|
417 |
} |
|
418 |
||
419 |
CHECK_PROXY(http, HTTP); |
|
420 |
CHECK_PROXY(https, HTTPS); |
|
421 |
CHECK_PROXY(ftp, FTP); |
|
422 |
CHECK_PROXY(socks, SOCKS); |
|
423 |
CHECK_PROXY(gopher, Gopher); |
|
424 |
||
425 |
#undef CHECK_PROXY |
|
426 |
||
427 |
CFRelease(dict); |
|
428 |
} |