src/java.base/macosx/native/libjava/java_props_macosx.c
author naoto
Thu, 19 Jul 2018 11:15:38 -0700
changeset 51169 0058ffa0a922
parent 50410 01e4ddc3c23f
child 52725 c470f977ade8
permissions -rw-r--r--
8206886: Java does not set the default format locale correctly on mac10.13 Reviewed-by: rriggs
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
/*
51169
0058ffa0a922 8206886: Java does not set the default format locale correctly on mac10.13
naoto
parents: 50410
diff changeset
     2
 * Copyright (c) 1998, 2018, 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
51169
0058ffa0a922 8206886: Java does not set the default format locale correctly on mac10.13
naoto
parents: 50410
diff changeset
    48
#ifndef kCFCoreFoundationVersionNumber10_11_Max
0058ffa0a922 8206886: Java does not set the default format locale correctly on mac10.13
naoto
parents: 50410
diff changeset
    49
#define kCFCoreFoundationVersionNumber10_11_Max 1299
0058ffa0a922 8206886: Java does not set the default format locale correctly on mac10.13
naoto
parents: 50410
diff changeset
    50
#endif
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12047
diff changeset
    51
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
    52
    const char* retVal = NULL;
50410
01e4ddc3c23f 8203324: Use out of scope in getMacOSXLocale of java_props_macosx.c:120
naoto
parents: 47352
diff changeset
    53
    char languageString[LOCALEIDLENGTH];
45829
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
    54
    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
    55
51169
0058ffa0a922 8206886: Java does not set the default format locale correctly on mac10.13
naoto
parents: 50410
diff changeset
    56
    // Since macOS 10.12, there is no separate language selection for
0058ffa0a922 8206886: Java does not set the default format locale correctly on mac10.13
naoto
parents: 50410
diff changeset
    57
    // "format" locale, e.g., date format. Use the preferred language
0058ffa0a922 8206886: Java does not set the default format locale correctly on mac10.13
naoto
parents: 50410
diff changeset
    58
    // for all LC_* categories.
0058ffa0a922 8206886: Java does not set the default format locale correctly on mac10.13
naoto
parents: 50410
diff changeset
    59
    if (kCFCoreFoundationVersionNumber >
0058ffa0a922 8206886: Java does not set the default format locale correctly on mac10.13
naoto
parents: 50410
diff changeset
    60
        kCFCoreFoundationVersionNumber10_11_Max) {
0058ffa0a922 8206886: Java does not set the default format locale correctly on mac10.13
naoto
parents: 50410
diff changeset
    61
        cat = LC_MESSAGES;
0058ffa0a922 8206886: Java does not set the default format locale correctly on mac10.13
naoto
parents: 50410
diff changeset
    62
    }
0058ffa0a922 8206886: Java does not set the default format locale correctly on mac10.13
naoto
parents: 50410
diff changeset
    63
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    64
    switch (cat) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    65
    case LC_MESSAGES:
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    66
        {
39144
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    67
            // get preferred language code
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    68
            CFArrayRef languages = CFLocaleCopyPreferredLanguages();
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    69
            if (languages == NULL) {
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    70
                return NULL;
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    71
            }
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    72
            if (CFArrayGetCount(languages) <= 0) {
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    73
                CFRelease(languages);
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    74
                return NULL;
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    75
            }
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    76
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    77
            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
    78
            if (primaryLanguage == NULL) {
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    79
                CFRelease(languages);
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    80
                return NULL;
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    81
            }
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    82
            if (CFStringGetCString(primaryLanguage, languageString,
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    83
                                   LOCALEIDLENGTH, CFStringGetSystemEncoding()) == false) {
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    84
                CFRelease(languages);
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    85
                return NULL;
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    86
            }
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    87
            CFRelease(languages);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    88
45829
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
    89
            // Explicitly supply region, if there is none
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
    90
            char *hyphenPos = strchr(languageString, '-');
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
    91
            int langStrLen = strlen(languageString);
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
    92
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
    93
            if (hyphenPos == NULL || // languageString contains ISO639 only, e.g., "en"
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
    94
                languageString + langStrLen - hyphenPos == 5) { // ISO639-ScriptCode, e.g., "en-Latn"
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
    95
                CFStringGetCString(CFLocaleGetIdentifier(CFLocaleCopyCurrent()),
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
    96
                               localeString, LOCALEIDLENGTH, CFStringGetSystemEncoding());
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
    97
                char *underscorePos = strrchr(localeString, '_');
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
    98
                char *region = NULL;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    99
45829
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   100
                if (underscorePos != NULL) {
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   101
                    region = underscorePos + 1;
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   102
                }
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   103
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   104
                if (region != NULL) {
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   105
                    strcat(languageString, "-");
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   106
                    strcat(languageString, region);
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   107
                }
39144
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
   108
            }
45829
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   109
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   110
            retVal = languageString;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   111
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   112
        break;
45829
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   113
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   114
    default:
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   115
        {
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
   116
            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
   117
                                    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
   118
                return NULL;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   119
            }
45829
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   120
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
   121
            retVal = localeString;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   122
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   123
        break;
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
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
   126
    if (retVal != NULL) {
47352
33ac30e17843 8187772: JVM crash when currency set on MacOS 10.10 and earlier
bchristi
parents: 47216
diff changeset
   127
        // convertToPOSIXLocale() does not expect any variant codes, so ignore
33ac30e17843 8187772: JVM crash when currency set on MacOS 10.10 and earlier
bchristi
parents: 47216
diff changeset
   128
        // '@' and anything following, if present.
33ac30e17843 8187772: JVM crash when currency set on MacOS 10.10 and earlier
bchristi
parents: 47216
diff changeset
   129
        char* rmAt = strchr(retVal, '@');
33ac30e17843 8187772: JVM crash when currency set on MacOS 10.10 and earlier
bchristi
parents: 47216
diff changeset
   130
        if (rmAt != NULL) {
33ac30e17843 8187772: JVM crash when currency set on MacOS 10.10 and earlier
bchristi
parents: 47216
diff changeset
   131
            *rmAt = '\0';
33ac30e17843 8187772: JVM crash when currency set on MacOS 10.10 and earlier
bchristi
parents: 47216
diff changeset
   132
        }
45829
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   133
        return strdup(convertToPOSIXLocale(retVal));
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   134
    }
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   135
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   136
    return NULL;
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   137
}
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
   138
45829
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   139
/* Language IDs use the language designators and (optional) region
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   140
 * and script designators of BCP 47.  So possible formats are:
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   141
 *
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   142
 * "en"         (language designator only)
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   143
 * "haw"        (3-letter lanuage designator)
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   144
 * "en-GB"      (language with alpha-2 region designator)
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   145
 * "es-419"     (language with 3-digit UN M.49 area code)
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   146
 * "zh-Hans"    (language with ISO 15924 script designator)
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   147
 * "zh-Hans-US"  (language with ISO 15924 script designator and region)
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   148
 * "zh-Hans-419" (language with ISO 15924 script designator and UN M.49)
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   149
 *
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   150
 * convert these tags into POSIX conforming locale string, i.e.,
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   151
 * lang{_region}{@script}. e.g., for "zh-Hans-US" into "zh_US@Hans"
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   152
 */
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   153
const char * convertToPOSIXLocale(const char* src) {
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   154
    char* scriptRegion = strchr(src, '-');
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   155
    if (scriptRegion != NULL) {
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   156
        int length = strlen(scriptRegion);
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   157
        char* region = strchr(scriptRegion + 1, '-');
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   158
        char* atMark = NULL;
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   159
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   160
        if (region == NULL) {
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   161
            // CFLocaleGetIdentifier() returns '_' before region
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   162
            region = strchr(scriptRegion + 1, '_');
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
   163
        }
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
   164
45829
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   165
        *scriptRegion = '_';
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   166
        if (length > 5) {
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   167
            // Region and script both exist.
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   168
            char tmpScript[4];
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   169
            int regionLength = length - 6;
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   170
            atMark = scriptRegion + 1 + regionLength;
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   171
            memcpy(tmpScript, scriptRegion + 1, 4);
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   172
            memmove(scriptRegion + 1, region + 1, regionLength);
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   173
            memcpy(atMark + 1, tmpScript, 4);
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   174
        } else if (length == 5) {
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   175
            // script only
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   176
            atMark = scriptRegion;
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   177
        }
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   178
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   179
        if (atMark != NULL) {
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   180
            *atMark = '@';
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   181
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   182
            // assert script code
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   183
            assert(isalpha(atMark[1]) &&
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   184
                   isalpha(atMark[2]) &&
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   185
                   isalpha(atMark[3]) &&
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   186
                   isalpha(atMark[4]));
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   187
        }
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   188
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   189
        assert(((length == 3 || length == 8) &&
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   190
            // '_' followed by a 2 character region designator
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   191
                isalpha(scriptRegion[1]) &&
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   192
                isalpha(scriptRegion[2])) ||
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   193
                ((length == 4 || length == 9) &&
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   194
            // '_' followed by a 3-digit UN M.49 area code
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   195
                isdigit(scriptRegion[1]) &&
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   196
                isdigit(scriptRegion[2]) &&
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   197
                isdigit(scriptRegion[3])) ||
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   198
            // '@' followed by a 4 character script code (already validated above)
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   199
                (length == 5));
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
   200
    }
45829
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   201
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   202
    return src;
12047
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
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12047
diff changeset
   205
char *setupMacOSXLocale(int cat) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12047
diff changeset
   206
    char * ret = getMacOSXLocale(cat);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12047
diff changeset
   207
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12047
diff changeset
   208
    if (ret == NULL) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12047
diff changeset
   209
        return getPosixLocale(cat);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12047
diff changeset
   210
    } else {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12047
diff changeset
   211
        return ret;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12047
diff changeset
   212
    }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12047
diff changeset
   213
}
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12047
diff changeset
   214
21130
0f0b9c8f701a 8025673: [macosx] Disable X11 AWT toolkit
dholmes
parents: 19857
diff changeset
   215
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
   216
    // 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
   217
    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
   218
    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
   219
        // 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
   220
        return 1;
032532f158ae 8027912: [macosx] Provide means to force the headful mode on OS X when running via ssh
anthony
parents: 21130
diff changeset
   221
    }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   222
    // Is the WindowServer available?
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   223
    SecuritySessionId session_id;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   224
    SessionAttributeBits session_info;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   225
    OSStatus status = SessionGetInfo(callerSecuritySession, &session_id, &session_info);
21130
0f0b9c8f701a 8025673: [macosx] Disable X11 AWT toolkit
dholmes
parents: 19857
diff changeset
   226
    if (status == noErr) {
0f0b9c8f701a 8025673: [macosx] Disable X11 AWT toolkit
dholmes
parents: 19857
diff changeset
   227
        if (session_info & sessionHasGraphicAccess) {
0f0b9c8f701a 8025673: [macosx] Disable X11 AWT toolkit
dholmes
parents: 19857
diff changeset
   228
            return 1;
0f0b9c8f701a 8025673: [macosx] Disable X11 AWT toolkit
dholmes
parents: 19857
diff changeset
   229
        }
0f0b9c8f701a 8025673: [macosx] Disable X11 AWT toolkit
dholmes
parents: 19857
diff changeset
   230
    }
0f0b9c8f701a 8025673: [macosx] Disable X11 AWT toolkit
dholmes
parents: 19857
diff changeset
   231
    return 0;
12047
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
39144
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
   234
// 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
   235
// 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
   236
typedef struct {
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
   237
        NSInteger majorVersion;
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
   238
        NSInteger minorVersion;
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
   239
        NSInteger patchVersion;
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
   240
} OSVerStruct;
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
   241
14513
f6dc8c52e275 7178922: (props) re-visit how os.name is determined on Mac
bchristi
parents: 14342
diff changeset
   242
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
   243
    // 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
   244
    sprops->os_name = strdup("Mac OS X");
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   245
39144
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
   246
    char* osVersionCStr = NULL;
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
   247
    // 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
   248
    // 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
   249
    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
   250
        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
   251
        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
   252
                                       @selector(operatingSystemVersion));
39765
c1aee33ef0c0 8161039: System.getProperty("os.version") returns incorrect version number on Mac
bchristi
parents: 39322
diff changeset
   253
        NSString *nsVerStr;
c1aee33ef0c0 8161039: System.getProperty("os.version") returns incorrect version number on Mac
bchristi
parents: 39322
diff changeset
   254
        if (osVer.patchVersion == 0) { // Omit trailing ".0"
c1aee33ef0c0 8161039: System.getProperty("os.version") returns incorrect version number on Mac
bchristi
parents: 39322
diff changeset
   255
            nsVerStr = [NSString stringWithFormat:@"%ld.%ld",
c1aee33ef0c0 8161039: System.getProperty("os.version") returns incorrect version number on Mac
bchristi
parents: 39322
diff changeset
   256
                    (long)osVer.majorVersion, (long)osVer.minorVersion];
c1aee33ef0c0 8161039: System.getProperty("os.version") returns incorrect version number on Mac
bchristi
parents: 39322
diff changeset
   257
        } else {
c1aee33ef0c0 8161039: System.getProperty("os.version") returns incorrect version number on Mac
bchristi
parents: 39322
diff changeset
   258
            nsVerStr = [NSString stringWithFormat:@"%ld.%ld.%ld",
c1aee33ef0c0 8161039: System.getProperty("os.version") returns incorrect version number on Mac
bchristi
parents: 39322
diff changeset
   259
                    (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
   260
        }
39144
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
   261
        // Copy out the char*
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
   262
        osVersionCStr = strdup([nsVerStr UTF8String]);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   263
    }
39322
66ecf193683a 8160370: System.getProperty("os.version") returns "Unknown" on Mac
bchristi
parents: 39144
diff changeset
   264
    // Fallback if running on pre-10.9 Mac OS
66ecf193683a 8160370: System.getProperty("os.version") returns "Unknown" on Mac
bchristi
parents: 39144
diff changeset
   265
    if (osVersionCStr == NULL) {
66ecf193683a 8160370: System.getProperty("os.version") returns "Unknown" on Mac
bchristi
parents: 39144
diff changeset
   266
        NSDictionary *version = [NSDictionary dictionaryWithContentsOfFile :
66ecf193683a 8160370: System.getProperty("os.version") returns "Unknown" on Mac
bchristi
parents: 39144
diff changeset
   267
                                 @"/System/Library/CoreServices/SystemVersion.plist"];
66ecf193683a 8160370: System.getProperty("os.version") returns "Unknown" on Mac
bchristi
parents: 39144
diff changeset
   268
        if (version != NULL) {
66ecf193683a 8160370: System.getProperty("os.version") returns "Unknown" on Mac
bchristi
parents: 39144
diff changeset
   269
            NSString *nsVerStr = [version objectForKey : @"ProductVersion"];
66ecf193683a 8160370: System.getProperty("os.version") returns "Unknown" on Mac
bchristi
parents: 39144
diff changeset
   270
            if (nsVerStr != NULL) {
66ecf193683a 8160370: System.getProperty("os.version") returns "Unknown" on Mac
bchristi
parents: 39144
diff changeset
   271
                osVersionCStr = strdup([nsVerStr UTF8String]);
66ecf193683a 8160370: System.getProperty("os.version") returns "Unknown" on Mac
bchristi
parents: 39144
diff changeset
   272
            }
66ecf193683a 8160370: System.getProperty("os.version") returns "Unknown" on Mac
bchristi
parents: 39144
diff changeset
   273
        }
66ecf193683a 8160370: System.getProperty("os.version") returns "Unknown" on Mac
bchristi
parents: 39144
diff changeset
   274
    }
39144
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
   275
    if (osVersionCStr == NULL) {
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
   276
        osVersionCStr = strdup("Unknown");
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
   277
    }
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
   278
    sprops->os_version = osVersionCStr;
12047
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
39322
66ecf193683a 8160370: System.getProperty("os.version") returns "Unknown" on Mac
bchristi
parents: 39144
diff changeset
   282
static Boolean getProxyInfoForProtocol(CFDictionaryRef inDict, CFStringRef inEnabledKey,
66ecf193683a 8160370: System.getProperty("os.version") returns "Unknown" on Mac
bchristi
parents: 39144
diff changeset
   283
                                       CFStringRef inHostKey, CFStringRef inPortKey,
66ecf193683a 8160370: System.getProperty("os.version") returns "Unknown" on Mac
bchristi
parents: 39144
diff changeset
   284
                                       CFStringRef *outProxyHost, int *ioProxyPort) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   285
    /* See if the proxy is enabled. */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   286
    CFNumberRef cf_enabled = CFDictionaryGetValue(inDict, inEnabledKey);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   287
    if (cf_enabled == NULL) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   288
        return false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   289
    }
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
    int isEnabled = false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   292
    if (!CFNumberGetValue(cf_enabled, kCFNumberIntType, &isEnabled)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   293
        return isEnabled;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   294
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   295
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   296
    if (!isEnabled) return false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   297
    *outProxyHost = CFDictionaryGetValue(inDict, inHostKey);
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
    // If cf_host is null, that means the checkbox is set,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   300
    //   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
   301
    // 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
   302
    //   no port number was entered. Treat this as ENABLED with the
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   303
    //   protocol's default port.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   304
    if (*outProxyHost == NULL) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   305
        return false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   306
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   307
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   308
    if (CFStringGetLength(*outProxyHost) == 0) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   309
        return false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   310
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   311
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   312
    int newPort = 0;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   313
    CFNumberRef cf_port = NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   314
    if ((cf_port = CFDictionaryGetValue(inDict, inPortKey)) != NULL &&
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   315
        CFNumberGetValue(cf_port, kCFNumberIntType, &newPort) &&
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   316
        newPort > 0) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   317
        *ioProxyPort = newPort;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   318
    } else {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   319
        // bad port or no port - leave *ioProxyPort unchanged
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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   322
    return true;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   323
}
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
static char *createUTF8CString(const CFStringRef theString) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   326
    if (theString == NULL) return NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   327
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   328
    const CFIndex stringLength = CFStringGetLength(theString);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   329
    const CFIndex bufSize = CFStringGetMaximumSizeForEncoding(stringLength, kCFStringEncodingUTF8) + 1;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   330
    char *returnVal = (char *)malloc(bufSize);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   331
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   332
    if (CFStringGetCString(theString, returnVal, bufSize, kCFStringEncodingUTF8)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   333
        return returnVal;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   334
    }
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
    free(returnVal);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   337
    return NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   338
}
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
// Return TRUE if str is a syntactically valid IP address.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   341
// Using inet_pton() instead of inet_aton() for IPv6 support.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   342
// len is only a hint; cstr must still be nul-terminated
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   343
static int looksLikeIPAddress(char *cstr, size_t len) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   344
    if (len == 0  ||  (len == 1 && cstr[0] == '.')) return FALSE;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   345
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   346
    char dst[16]; // big enough for INET6
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   347
    return (1 == inet_pton(AF_INET, cstr, dst)  ||
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   348
            1 == inet_pton(AF_INET6, cstr, dst));
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   349
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   350
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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   353
// Convert Mac OS X proxy exception entry to Java syntax.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   354
// See Radar #3441134 for details.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   355
// Returns NULL if this exception should be ignored by Java.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   356
// May generate a string with multiple exceptions separated by '|'.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   357
static char * createConvertedException(CFStringRef cf_original) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   358
    // This is done with char* instead of CFString because inet_pton()
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   359
    // needs a C string.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   360
    char *c_exception = createUTF8CString(cf_original);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   361
    if (!c_exception) return NULL;
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
    int c_len = strlen(c_exception);
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
    // 1. sanitize exception prefix
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   366
    if (c_len >= 1  &&  0 == strncmp(c_exception, ".", 1)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   367
        memmove(c_exception, c_exception+1, c_len);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   368
        c_len -= 1;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   369
    } else if (c_len >= 2  &&  0 == strncmp(c_exception, "*.", 2)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   370
        memmove(c_exception, c_exception+2, c_len-1);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   371
        c_len -= 2;
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
    // 2. pre-reject other exception wildcards
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   375
    if (strchr(c_exception, '*')) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   376
        free(c_exception);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   377
        return NULL;
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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   380
    // 3. no IP wildcarding
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   381
    if (looksLikeIPAddress(c_exception, c_len)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   382
        return c_exception;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   383
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   384
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   385
    // 4. allow domain suffixes
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   386
    // c_exception is now "str\0" - change to "str|*.str\0"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   387
    c_exception = reallocf(c_exception, c_len+3+c_len+1);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   388
    if (!c_exception) return NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   389
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   390
    strncpy(c_exception+c_len, "|*.", 3);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   391
    strncpy(c_exception+c_len+3, c_exception, c_len);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   392
    c_exception[c_len+3+c_len] = '\0';
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   393
    return 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
19857
d3a868255edb 7199674: (props) user.home property does not return an accessible location in sandboxed environment [macosx]
bchristi
parents: 14662
diff changeset
   396
/*
d3a868255edb 7199674: (props) user.home property does not return an accessible location in sandboxed environment [macosx]
bchristi
parents: 14662
diff changeset
   397
 * 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
   398
 * 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
   399
 * 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
   400
 */
d3a868255edb 7199674: (props) user.home property does not return an accessible location in sandboxed environment [macosx]
bchristi
parents: 14662
diff changeset
   401
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
   402
    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
   403
    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
   404
    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
   405
    [pool drain];
d3a868255edb 7199674: (props) user.home property does not return an accessible location in sandboxed environment [macosx]
bchristi
parents: 14662
diff changeset
   406
}
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   407
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   408
/*
19857
d3a868255edb 7199674: (props) user.home property does not return an accessible location in sandboxed environment [macosx]
bchristi
parents: 14662
diff changeset
   409
 * 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
   410
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   411
void setProxyProperties(java_props_t *sProps) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   412
    if (sProps == NULL) return;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   413
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   414
    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
   415
    CFStringRef
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   416
    cf_httpHost = NULL,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   417
    cf_httpsHost = NULL,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   418
    cf_ftpHost = NULL,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   419
    cf_socksHost = NULL,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   420
    cf_gopherHost = NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   421
    int
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   422
    httpPort = 80, // Default proxy port values
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   423
    httpsPort = 443,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   424
    ftpPort = 21,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   425
    socksPort = 1080,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   426
    gopherPort = 70;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   427
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   428
    CFDictionaryRef dict = SCDynamicStoreCopyProxies(NULL);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   429
    if (dict == NULL) return;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   430
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   431
    /* Read the proxy exceptions list */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   432
    CFArrayRef cf_list = CFDictionaryGetValue(dict, kSCPropNetProxiesExceptionsList);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   433
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   434
    CFMutableStringRef cf_exceptionList = NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   435
    if (cf_list != NULL) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   436
        CFIndex len = CFArrayGetCount(cf_list), idx;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   437
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   438
        cf_exceptionList = CFStringCreateMutable(NULL, 0);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   439
        for (idx = (CFIndex)0; idx < len; idx++) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   440
            CFStringRef cf_ehost;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   441
            if ((cf_ehost = CFArrayGetValueAtIndex(cf_list, idx))) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   442
                /* Convert this exception from Mac OS X syntax to Java syntax.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   443
                 See Radar #3441134 for details. This may generate a string
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   444
                 with multiple Java exceptions separated by '|'. */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   445
                char *c_exception = createConvertedException(cf_ehost);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   446
                if (c_exception) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   447
                    /* Append the host to the list of exclusions. */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   448
                    if (CFStringGetLength(cf_exceptionList) > 0) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   449
                        CFStringAppendCString(cf_exceptionList, "|", kCFStringEncodingMacRoman);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   450
                    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   451
                    CFStringAppendCString(cf_exceptionList, c_exception, kCFStringEncodingMacRoman);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   452
                    free(c_exception);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   453
                }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   454
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   455
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   456
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   457
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   458
    if (cf_exceptionList != NULL) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   459
        if (CFStringGetLength(cf_exceptionList) > 0) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   460
            sProps->exceptionList = createUTF8CString(cf_exceptionList);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   461
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   462
        CFRelease(cf_exceptionList);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   463
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   464
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   465
#define CHECK_PROXY(protocol, PROTOCOL)                                     \
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   466
    sProps->protocol##ProxyEnabled =                                        \
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   467
    getProxyInfoForProtocol(dict, kSCPropNetProxies##PROTOCOL##Enable,      \
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   468
    kSCPropNetProxies##PROTOCOL##Proxy,         \
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   469
    kSCPropNetProxies##PROTOCOL##Port,          \
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   470
    &cf_##protocol##Host, &protocol##Port);     \
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   471
    if (sProps->protocol##ProxyEnabled) {                                   \
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   472
        sProps->protocol##Host = createUTF8CString(cf_##protocol##Host);    \
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   473
        snprintf(buf, sizeof(buf), "%d", protocol##Port);                   \
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   474
        sProps->protocol##Port = malloc(strlen(buf) + 1);                   \
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   475
        strcpy(sProps->protocol##Port, buf);                                \
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   476
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   477
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   478
    CHECK_PROXY(http, HTTP);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   479
    CHECK_PROXY(https, HTTPS);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   480
    CHECK_PROXY(ftp, FTP);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   481
    CHECK_PROXY(socks, SOCKS);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   482
    CHECK_PROXY(gopher, Gopher);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   483
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   484
#undef CHECK_PROXY
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   485
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   486
    CFRelease(dict);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   487
}