jdk/src/java.base/macosx/native/libjava/java_props_macosx.c
author bchristi
Thu, 23 Jun 2016 14:14:06 -0700
changeset 39144 50f8aee9012d
parent 33653 c1ee09fe3274
child 39322 66ecf193683a
permissions -rw-r--r--
7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx] Summary: Replace JRS calls with Core Foundation calls Reviewed-by: naoto
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
/*
39144
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
     2
 * Copyright (c) 1998, 2016, 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) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    49
    switch (cat) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    50
    case LC_MESSAGES:
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    51
        {
39144
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    52
            // get preferred language code
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    53
            CFArrayRef languages = CFLocaleCopyPreferredLanguages();
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    54
            if (languages == NULL) {
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    55
                return NULL;
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    56
            }
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    57
            if (CFArrayGetCount(languages) <= 0) {
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    58
                CFRelease(languages);
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    59
                return NULL;
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    60
            }
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    61
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    62
            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
    63
            if (primaryLanguage == NULL) {
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    64
                CFRelease(languages);
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    65
                return NULL;
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    66
            }
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    67
            char languageString[LOCALEIDLENGTH];
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    68
            if (CFStringGetCString(primaryLanguage, languageString,
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    69
                                   LOCALEIDLENGTH, CFStringGetSystemEncoding()) == false) {
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    70
                CFRelease(languages);
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    71
                return NULL;
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    72
            }
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    73
            CFRelease(languages);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    74
39144
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    75
            // Language IDs use the language designators and (optional) region
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    76
            // and script designators of BCP 47.  So possible formats are:
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    77
            //
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    78
            // "en"         (language designator only)
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    79
            // "haw"        (3-letter lanuage designator)
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    80
            // "en-GB"      (language with alpha-2 region designator)
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    81
            // "es-419"     (language with 3-digit UN M.49 area code)
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    82
            // "zh-Hans"    (language with ISO 15924 script designator)
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    83
            //
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    84
            // In the case of region designators (alpha-2 or UN M.49), we convert
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    85
            // to our locale string format by changing '-' to '_'.  That is, if
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    86
            // the '-' is followed by fewer than 4 chars.
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    87
            char* scriptOrRegion = strchr(languageString, '-');
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    88
            if (scriptOrRegion != NULL && strlen(scriptOrRegion) < 5) {
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    89
                *scriptOrRegion = '_';
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    90
39144
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    91
                assert((strlen(scriptOrRegion) == 3 &&
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    92
                        // '-' followed by a 2 character region designator
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    93
                          isalpha(scriptOrRegion[1]) &&
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    94
                          isalpha(scriptOrRegion[2])) ||
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    95
                       (strlen(scriptOrRegion) == 4 &&
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    96
                        // '-' followed by a 3-digit UN M.49 area code
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    97
                          isdigit(scriptOrRegion[1]) &&
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    98
                          isdigit(scriptOrRegion[2]) &&
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    99
                          isdigit(scriptOrRegion[3])));
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
   100
            }
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
   101
            const char* retVal = languageString;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   102
39144
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
   103
            // 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
   104
            // 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
   105
            // 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
   106
            // "Portuguese (Brazil)" language.
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
   107
            // 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
   108
            char localeString[LOCALEIDLENGTH];
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
   109
            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
   110
                    CFStringGetCString(CFLocaleGetIdentifier(CFLocaleCopyCurrent()),
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
   111
                                       localeString, LOCALEIDLENGTH, CFStringGetSystemEncoding()) &&
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
   112
                    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
   113
                retVal = localeString;
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
   114
            }
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
   115
            return strdup(retVal);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   116
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   117
        break;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   118
    default:
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   119
        {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   120
            char localeString[LOCALEIDLENGTH];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   121
            if (CFStringGetCString(CFLocaleGetIdentifier(CFLocaleCopyCurrent()),
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   122
                                   localeString, LOCALEIDLENGTH, CFStringGetSystemEncoding())) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   123
                return strdup(localeString);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   124
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   125
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   126
        break;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   127
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   128
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   129
    return NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   130
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   131
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12047
diff changeset
   132
char *setupMacOSXLocale(int cat) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12047
diff changeset
   133
    char * ret = getMacOSXLocale(cat);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12047
diff changeset
   134
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12047
diff changeset
   135
    if (ret == NULL) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12047
diff changeset
   136
        return getPosixLocale(cat);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12047
diff changeset
   137
    } else {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12047
diff changeset
   138
        return ret;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12047
diff changeset
   139
    }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12047
diff changeset
   140
}
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12047
diff changeset
   141
21130
0f0b9c8f701a 8025673: [macosx] Disable X11 AWT toolkit
dholmes
parents: 19857
diff changeset
   142
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
   143
    // 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
   144
    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
   145
    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
   146
        // 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
   147
        return 1;
032532f158ae 8027912: [macosx] Provide means to force the headful mode on OS X when running via ssh
anthony
parents: 21130
diff changeset
   148
    }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   149
    // Is the WindowServer available?
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   150
    SecuritySessionId session_id;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   151
    SessionAttributeBits session_info;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   152
    OSStatus status = SessionGetInfo(callerSecuritySession, &session_id, &session_info);
21130
0f0b9c8f701a 8025673: [macosx] Disable X11 AWT toolkit
dholmes
parents: 19857
diff changeset
   153
    if (status == noErr) {
0f0b9c8f701a 8025673: [macosx] Disable X11 AWT toolkit
dholmes
parents: 19857
diff changeset
   154
        if (session_info & sessionHasGraphicAccess) {
0f0b9c8f701a 8025673: [macosx] Disable X11 AWT toolkit
dholmes
parents: 19857
diff changeset
   155
            return 1;
0f0b9c8f701a 8025673: [macosx] Disable X11 AWT toolkit
dholmes
parents: 19857
diff changeset
   156
        }
0f0b9c8f701a 8025673: [macosx] Disable X11 AWT toolkit
dholmes
parents: 19857
diff changeset
   157
    }
0f0b9c8f701a 8025673: [macosx] Disable X11 AWT toolkit
dholmes
parents: 19857
diff changeset
   158
    return 0;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   159
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   160
39144
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
   161
// 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
   162
// 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
   163
typedef struct {
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
   164
        NSInteger majorVersion;
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
   165
        NSInteger minorVersion;
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
   166
        NSInteger patchVersion;
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
   167
} OSVerStruct;
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
   168
14513
f6dc8c52e275 7178922: (props) re-visit how os.name is determined on Mac
bchristi
parents: 14342
diff changeset
   169
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
   170
    // 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
   171
    sprops->os_name = strdup("Mac OS X");
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   172
39144
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
   173
    char* osVersionCStr = NULL;
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
   174
    // 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
   175
    // 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
   176
    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
   177
        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
   178
        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
   179
                                       @selector(operatingSystemVersion));
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
   180
        NSString *nsVerStr = [NSString stringWithFormat:@"%ld.%ld.%ld",
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
   181
                (long)osVer.majorVersion, (long)osVer.minorVersion, (long)osVer.patchVersion];
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
   182
        // Copy out the char*
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
   183
        osVersionCStr = strdup([nsVerStr UTF8String]);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   184
    }
39144
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
   185
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
   186
    if (osVersionCStr == NULL) {
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
   187
        osVersionCStr = strdup("Unknown");
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
   188
    }
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
   189
    sprops->os_version = osVersionCStr;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   190
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   191
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   192
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   193
static Boolean getProxyInfoForProtocol(CFDictionaryRef inDict, CFStringRef inEnabledKey, CFStringRef inHostKey, CFStringRef inPortKey, CFStringRef *outProxyHost, int *ioProxyPort) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   194
    /* See if the proxy is enabled. */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   195
    CFNumberRef cf_enabled = CFDictionaryGetValue(inDict, inEnabledKey);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   196
    if (cf_enabled == NULL) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   197
        return false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   198
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   199
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   200
    int isEnabled = false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   201
    if (!CFNumberGetValue(cf_enabled, kCFNumberIntType, &isEnabled)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   202
        return isEnabled;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   203
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   204
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   205
    if (!isEnabled) return false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   206
    *outProxyHost = CFDictionaryGetValue(inDict, inHostKey);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   207
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   208
    // If cf_host is null, that means the checkbox is set,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   209
    //   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
   210
    // 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
   211
    //   no port number was entered. Treat this as ENABLED with the
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   212
    //   protocol's default port.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   213
    if (*outProxyHost == NULL) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   214
        return false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   215
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   216
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   217
    if (CFStringGetLength(*outProxyHost) == 0) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   218
        return false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   219
    }
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
    int newPort = 0;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   222
    CFNumberRef cf_port = NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   223
    if ((cf_port = CFDictionaryGetValue(inDict, inPortKey)) != NULL &&
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   224
        CFNumberGetValue(cf_port, kCFNumberIntType, &newPort) &&
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   225
        newPort > 0) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   226
        *ioProxyPort = newPort;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   227
    } else {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   228
        // bad port or no port - leave *ioProxyPort unchanged
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   229
    }
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
    return true;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   232
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   233
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   234
static char *createUTF8CString(const CFStringRef theString) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   235
    if (theString == NULL) return NULL;
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
    const CFIndex stringLength = CFStringGetLength(theString);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   238
    const CFIndex bufSize = CFStringGetMaximumSizeForEncoding(stringLength, kCFStringEncodingUTF8) + 1;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   239
    char *returnVal = (char *)malloc(bufSize);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   240
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   241
    if (CFStringGetCString(theString, returnVal, bufSize, kCFStringEncodingUTF8)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   242
        return returnVal;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   243
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   244
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   245
    free(returnVal);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   246
    return NULL;
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
// Return TRUE if str is a syntactically valid IP address.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   250
// Using inet_pton() instead of inet_aton() for IPv6 support.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   251
// len is only a hint; cstr must still be nul-terminated
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   252
static int looksLikeIPAddress(char *cstr, size_t len) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   253
    if (len == 0  ||  (len == 1 && cstr[0] == '.')) return FALSE;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   254
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   255
    char dst[16]; // big enough for INET6
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   256
    return (1 == inet_pton(AF_INET, cstr, dst)  ||
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   257
            1 == inet_pton(AF_INET6, cstr, dst));
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   258
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   259
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   260
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
// Convert Mac OS X proxy exception entry to Java syntax.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   263
// See Radar #3441134 for details.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   264
// Returns NULL if this exception should be ignored by Java.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   265
// May generate a string with multiple exceptions separated by '|'.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   266
static char * createConvertedException(CFStringRef cf_original) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   267
    // This is done with char* instead of CFString because inet_pton()
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   268
    // needs a C string.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   269
    char *c_exception = createUTF8CString(cf_original);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   270
    if (!c_exception) return NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   271
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   272
    int c_len = strlen(c_exception);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   273
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   274
    // 1. sanitize exception prefix
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   275
    if (c_len >= 1  &&  0 == strncmp(c_exception, ".", 1)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   276
        memmove(c_exception, c_exception+1, c_len);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   277
        c_len -= 1;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   278
    } else if (c_len >= 2  &&  0 == strncmp(c_exception, "*.", 2)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   279
        memmove(c_exception, c_exception+2, c_len-1);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   280
        c_len -= 2;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   281
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   282
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   283
    // 2. pre-reject other exception wildcards
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   284
    if (strchr(c_exception, '*')) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   285
        free(c_exception);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   286
        return NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   287
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   288
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   289
    // 3. no IP wildcarding
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   290
    if (looksLikeIPAddress(c_exception, c_len)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   291
        return c_exception;
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
    // 4. allow domain suffixes
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   295
    // c_exception is now "str\0" - change to "str|*.str\0"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   296
    c_exception = reallocf(c_exception, c_len+3+c_len+1);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   297
    if (!c_exception) return NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   298
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   299
    strncpy(c_exception+c_len, "|*.", 3);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   300
    strncpy(c_exception+c_len+3, c_exception, c_len);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   301
    c_exception[c_len+3+c_len] = '\0';
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   302
    return c_exception;
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
19857
d3a868255edb 7199674: (props) user.home property does not return an accessible location in sandboxed environment [macosx]
bchristi
parents: 14662
diff changeset
   305
/*
d3a868255edb 7199674: (props) user.home property does not return an accessible location in sandboxed environment [macosx]
bchristi
parents: 14662
diff changeset
   306
 * 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
   307
 * 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
   308
 * 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
   309
 */
d3a868255edb 7199674: (props) user.home property does not return an accessible location in sandboxed environment [macosx]
bchristi
parents: 14662
diff changeset
   310
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
   311
    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
   312
    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
   313
    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
   314
    [pool drain];
d3a868255edb 7199674: (props) user.home property does not return an accessible location in sandboxed environment [macosx]
bchristi
parents: 14662
diff changeset
   315
}
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   316
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   317
/*
19857
d3a868255edb 7199674: (props) user.home property does not return an accessible location in sandboxed environment [macosx]
bchristi
parents: 14662
diff changeset
   318
 * 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
   319
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   320
void setProxyProperties(java_props_t *sProps) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   321
    if (sProps == NULL) return;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   322
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   323
    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
   324
    CFStringRef
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   325
    cf_httpHost = NULL,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   326
    cf_httpsHost = NULL,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   327
    cf_ftpHost = NULL,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   328
    cf_socksHost = NULL,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   329
    cf_gopherHost = NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   330
    int
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   331
    httpPort = 80, // Default proxy port values
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   332
    httpsPort = 443,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   333
    ftpPort = 21,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   334
    socksPort = 1080,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   335
    gopherPort = 70;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   336
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   337
    CFDictionaryRef dict = SCDynamicStoreCopyProxies(NULL);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   338
    if (dict == NULL) return;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   339
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   340
    /* Read the proxy exceptions list */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   341
    CFArrayRef cf_list = CFDictionaryGetValue(dict, kSCPropNetProxiesExceptionsList);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   342
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   343
    CFMutableStringRef cf_exceptionList = NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   344
    if (cf_list != NULL) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   345
        CFIndex len = CFArrayGetCount(cf_list), idx;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   346
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   347
        cf_exceptionList = CFStringCreateMutable(NULL, 0);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   348
        for (idx = (CFIndex)0; idx < len; idx++) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   349
            CFStringRef cf_ehost;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   350
            if ((cf_ehost = CFArrayGetValueAtIndex(cf_list, idx))) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   351
                /* Convert this exception from Mac OS X syntax to Java syntax.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   352
                 See Radar #3441134 for details. This may generate a string
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   353
                 with multiple Java exceptions separated by '|'. */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   354
                char *c_exception = createConvertedException(cf_ehost);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   355
                if (c_exception) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   356
                    /* Append the host to the list of exclusions. */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   357
                    if (CFStringGetLength(cf_exceptionList) > 0) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   358
                        CFStringAppendCString(cf_exceptionList, "|", kCFStringEncodingMacRoman);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   359
                    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   360
                    CFStringAppendCString(cf_exceptionList, c_exception, kCFStringEncodingMacRoman);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   361
                    free(c_exception);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   362
                }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   363
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   364
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   365
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   366
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   367
    if (cf_exceptionList != NULL) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   368
        if (CFStringGetLength(cf_exceptionList) > 0) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   369
            sProps->exceptionList = createUTF8CString(cf_exceptionList);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   370
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   371
        CFRelease(cf_exceptionList);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   372
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   373
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   374
#define CHECK_PROXY(protocol, PROTOCOL)                                     \
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   375
    sProps->protocol##ProxyEnabled =                                        \
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   376
    getProxyInfoForProtocol(dict, kSCPropNetProxies##PROTOCOL##Enable,      \
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   377
    kSCPropNetProxies##PROTOCOL##Proxy,         \
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   378
    kSCPropNetProxies##PROTOCOL##Port,          \
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   379
    &cf_##protocol##Host, &protocol##Port);     \
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   380
    if (sProps->protocol##ProxyEnabled) {                                   \
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   381
        sProps->protocol##Host = createUTF8CString(cf_##protocol##Host);    \
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   382
        snprintf(buf, sizeof(buf), "%d", protocol##Port);                   \
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   383
        sProps->protocol##Port = malloc(strlen(buf) + 1);                   \
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   384
        strcpy(sProps->protocol##Port, buf);                                \
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   385
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   386
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   387
    CHECK_PROXY(http, HTTP);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   388
    CHECK_PROXY(https, HTTPS);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   389
    CHECK_PROXY(ftp, FTP);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   390
    CHECK_PROXY(socks, SOCKS);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   391
    CHECK_PROXY(gopher, Gopher);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   392
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   393
#undef CHECK_PROXY
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
    CFRelease(dict);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   396
}