jdk/src/java.base/macosx/native/libjava/java_props_macosx.c
author naoto
Mon, 06 Mar 2017 18:54:53 -0800
changeset 44044 f1398789e771
parent 43799 0e642fbacb25
child 45829 991121499947
permissions -rw-r--r--
8174736: [JCP] [Mac]Cannot launch JCP on Mac os with language set to "Chinese, Simplified" while region is not China Reviewed-by: bchristi
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     1
/*
43799
0e642fbacb25 8174779: Locale issues with Mac 10.12
naoto
parents: 39765
diff changeset
     2
 * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     4
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    10
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    15
 * accompanied this code).
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    16
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    20
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    23
 * questions.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    24
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    25
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    26
#include <sys/socket.h>
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    27
#include <netinet/in.h>
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    30
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    31
#include <Security/AuthSession.h>
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    32
#include <CoreFoundation/CoreFoundation.h>
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    35
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    36
#include "java_props_macosx.h"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    37
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12047
diff changeset
    38
char *getPosixLocale(int cat) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    39
    char *lc = setlocale(cat, NULL);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    40
    if ((lc == NULL) || (strcmp(lc, "C") == 0)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    41
        lc = getenv("LANG");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    42
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    43
    if (lc == NULL) return NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    44
    return strdup(lc);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    45
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    46
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    47
#define LOCALEIDLENGTH  128
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12047
diff changeset
    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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    51
    switch (cat) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    52
    case LC_MESSAGES:
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    91
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    92
        break;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    93
    default:
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    94
        {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   101
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   102
        break;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   103
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   143
    return NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   144
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   145
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12047
diff changeset
   146
char *setupMacOSXLocale(int cat) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12047
diff changeset
   147
    char * ret = getMacOSXLocale(cat);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12047
diff changeset
   148
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12047
diff changeset
   149
    if (ret == NULL) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12047
diff changeset
   150
        return getPosixLocale(cat);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12047
diff changeset
   151
    } else {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12047
diff changeset
   152
        return ret;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12047
diff changeset
   153
    }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12047
diff changeset
   154
}
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12047
diff changeset
   155
21130
0f0b9c8f701a 8025673: [macosx] Disable X11 AWT toolkit
dholmes
parents: 19857
diff changeset
   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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   163
    // Is the WindowServer available?
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   164
    SecuritySessionId session_id;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   165
    SessionAttributeBits session_info;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   166
    OSStatus status = SessionGetInfo(callerSecuritySession, &session_id, &session_info);
21130
0f0b9c8f701a 8025673: [macosx] Disable X11 AWT toolkit
dholmes
parents: 19857
diff changeset
   167
    if (status == noErr) {
0f0b9c8f701a 8025673: [macosx] Disable X11 AWT toolkit
dholmes
parents: 19857
diff changeset
   168
        if (session_info & sessionHasGraphicAccess) {
0f0b9c8f701a 8025673: [macosx] Disable X11 AWT toolkit
dholmes
parents: 19857
diff changeset
   169
            return 1;
0f0b9c8f701a 8025673: [macosx] Disable X11 AWT toolkit
dholmes
parents: 19857
diff changeset
   170
        }
0f0b9c8f701a 8025673: [macosx] Disable X11 AWT toolkit
dholmes
parents: 19857
diff changeset
   171
    }
0f0b9c8f701a 8025673: [macosx] Disable X11 AWT toolkit
dholmes
parents: 19857
diff changeset
   172
    return 0;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   173
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   220
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   221
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   226
    /* See if the proxy is enabled. */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   227
    CFNumberRef cf_enabled = CFDictionaryGetValue(inDict, inEnabledKey);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   228
    if (cf_enabled == NULL) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   229
        return false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   230
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   231
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   232
    int isEnabled = false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   233
    if (!CFNumberGetValue(cf_enabled, kCFNumberIntType, &isEnabled)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   234
        return isEnabled;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   235
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   236
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   237
    if (!isEnabled) return false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   238
    *outProxyHost = CFDictionaryGetValue(inDict, inHostKey);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   239
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   240
    // If cf_host is null, that means the checkbox is set,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   241
    //   but no host was entered. We'll treat that as NOT ENABLED.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   242
    // If cf_port is null or cf_port isn't a number, that means
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   243
    //   no port number was entered. Treat this as ENABLED with the
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   244
    //   protocol's default port.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   245
    if (*outProxyHost == NULL) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   246
        return false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   247
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   248
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   249
    if (CFStringGetLength(*outProxyHost) == 0) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   250
        return false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   251
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   252
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   253
    int newPort = 0;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   254
    CFNumberRef cf_port = NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   255
    if ((cf_port = CFDictionaryGetValue(inDict, inPortKey)) != NULL &&
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   256
        CFNumberGetValue(cf_port, kCFNumberIntType, &newPort) &&
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   257
        newPort > 0) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   258
        *ioProxyPort = newPort;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   259
    } else {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   260
        // bad port or no port - leave *ioProxyPort unchanged
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   261
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   262
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   263
    return true;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   264
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   265
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   266
static char *createUTF8CString(const CFStringRef theString) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   267
    if (theString == NULL) return NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   268
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   269
    const CFIndex stringLength = CFStringGetLength(theString);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   270
    const CFIndex bufSize = CFStringGetMaximumSizeForEncoding(stringLength, kCFStringEncodingUTF8) + 1;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   271
    char *returnVal = (char *)malloc(bufSize);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   272
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   273
    if (CFStringGetCString(theString, returnVal, bufSize, kCFStringEncodingUTF8)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   274
        return returnVal;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   275
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   276
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   277
    free(returnVal);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   278
    return NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   279
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   280
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   281
// Return TRUE if str is a syntactically valid IP address.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   282
// Using inet_pton() instead of inet_aton() for IPv6 support.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   283
// len is only a hint; cstr must still be nul-terminated
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   284
static int looksLikeIPAddress(char *cstr, size_t len) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   285
    if (len == 0  ||  (len == 1 && cstr[0] == '.')) return FALSE;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   286
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   287
    char dst[16]; // big enough for INET6
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   288
    return (1 == inet_pton(AF_INET, cstr, dst)  ||
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   289
            1 == inet_pton(AF_INET6, cstr, dst));
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   290
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   291
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   292
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   293
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   294
// Convert Mac OS X proxy exception entry to Java syntax.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   295
// See Radar #3441134 for details.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   296
// Returns NULL if this exception should be ignored by Java.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   297
// May generate a string with multiple exceptions separated by '|'.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   298
static char * createConvertedException(CFStringRef cf_original) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   299
    // This is done with char* instead of CFString because inet_pton()
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   300
    // needs a C string.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   301
    char *c_exception = createUTF8CString(cf_original);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   302
    if (!c_exception) return NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   303
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   304
    int c_len = strlen(c_exception);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   305
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   306
    // 1. sanitize exception prefix
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   307
    if (c_len >= 1  &&  0 == strncmp(c_exception, ".", 1)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   308
        memmove(c_exception, c_exception+1, c_len);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   309
        c_len -= 1;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   310
    } else if (c_len >= 2  &&  0 == strncmp(c_exception, "*.", 2)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   311
        memmove(c_exception, c_exception+2, c_len-1);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   312
        c_len -= 2;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   313
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   314
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   315
    // 2. pre-reject other exception wildcards
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   316
    if (strchr(c_exception, '*')) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   317
        free(c_exception);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   318
        return NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   319
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   320
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   321
    // 3. no IP wildcarding
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   322
    if (looksLikeIPAddress(c_exception, c_len)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   323
        return c_exception;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   324
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   325
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   326
    // 4. allow domain suffixes
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   327
    // c_exception is now "str\0" - change to "str|*.str\0"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   328
    c_exception = reallocf(c_exception, c_len+3+c_len+1);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   329
    if (!c_exception) return NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   330
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   331
    strncpy(c_exception+c_len, "|*.", 3);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   332
    strncpy(c_exception+c_len+3, c_exception, c_len);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   333
    c_exception[c_len+3+c_len] = '\0';
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   334
    return c_exception;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   335
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   348
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   351
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   352
void setProxyProperties(java_props_t *sProps) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   353
    if (sProps == NULL) return;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   354
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   355
    char buf[16];    /* Used for %d of an int - 16 is plenty */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   356
    CFStringRef
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   357
    cf_httpHost = NULL,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   358
    cf_httpsHost = NULL,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   359
    cf_ftpHost = NULL,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   360
    cf_socksHost = NULL,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   361
    cf_gopherHost = NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   362
    int
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   363
    httpPort = 80, // Default proxy port values
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   364
    httpsPort = 443,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   365
    ftpPort = 21,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   366
    socksPort = 1080,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   367
    gopherPort = 70;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   368
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   369
    CFDictionaryRef dict = SCDynamicStoreCopyProxies(NULL);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   370
    if (dict == NULL) return;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   371
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   372
    /* Read the proxy exceptions list */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   373
    CFArrayRef cf_list = CFDictionaryGetValue(dict, kSCPropNetProxiesExceptionsList);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   374
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   375
    CFMutableStringRef cf_exceptionList = NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   376
    if (cf_list != NULL) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   377
        CFIndex len = CFArrayGetCount(cf_list), idx;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   378
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   379
        cf_exceptionList = CFStringCreateMutable(NULL, 0);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   380
        for (idx = (CFIndex)0; idx < len; idx++) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   381
            CFStringRef cf_ehost;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   382
            if ((cf_ehost = CFArrayGetValueAtIndex(cf_list, idx))) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   383
                /* Convert this exception from Mac OS X syntax to Java syntax.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   384
                 See Radar #3441134 for details. This may generate a string
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   385
                 with multiple Java exceptions separated by '|'. */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   386
                char *c_exception = createConvertedException(cf_ehost);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   387
                if (c_exception) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   388
                    /* Append the host to the list of exclusions. */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   389
                    if (CFStringGetLength(cf_exceptionList) > 0) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   390
                        CFStringAppendCString(cf_exceptionList, "|", kCFStringEncodingMacRoman);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   391
                    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   392
                    CFStringAppendCString(cf_exceptionList, c_exception, kCFStringEncodingMacRoman);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   393
                    free(c_exception);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   394
                }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   395
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   396
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   397
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   398
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   399
    if (cf_exceptionList != NULL) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   400
        if (CFStringGetLength(cf_exceptionList) > 0) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   401
            sProps->exceptionList = createUTF8CString(cf_exceptionList);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   402
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   403
        CFRelease(cf_exceptionList);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   404
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   405
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   406
#define CHECK_PROXY(protocol, PROTOCOL)                                     \
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   407
    sProps->protocol##ProxyEnabled =                                        \
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   408
    getProxyInfoForProtocol(dict, kSCPropNetProxies##PROTOCOL##Enable,      \
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   409
    kSCPropNetProxies##PROTOCOL##Proxy,         \
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   410
    kSCPropNetProxies##PROTOCOL##Port,          \
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   411
    &cf_##protocol##Host, &protocol##Port);     \
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   412
    if (sProps->protocol##ProxyEnabled) {                                   \
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   413
        sProps->protocol##Host = createUTF8CString(cf_##protocol##Host);    \
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   414
        snprintf(buf, sizeof(buf), "%d", protocol##Port);                   \
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   415
        sProps->protocol##Port = malloc(strlen(buf) + 1);                   \
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   416
        strcpy(sProps->protocol##Port, buf);                                \
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   417
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   418
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   419
    CHECK_PROXY(http, HTTP);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   420
    CHECK_PROXY(https, HTTPS);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   421
    CHECK_PROXY(ftp, FTP);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   422
    CHECK_PROXY(socks, SOCKS);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   423
    CHECK_PROXY(gopher, Gopher);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   424
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   425
#undef CHECK_PROXY
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   426
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   427
    CFRelease(dict);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   428
}