src/java.base/macosx/native/libjava/java_props_macosx.c
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 57534 de62b363bbe6
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
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
/*
57534
de62b363bbe6 8228501: java_props_macosx.c - provide missing CFRelease for CFLocaleCopyCurrent
mbaesken
parents: 55169
diff changeset
     2
 * Copyright (c) 1998, 2019, 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 <CoreFoundation/CoreFoundation.h>
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    32
#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
    33
#include <Foundation/Foundation.h>
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    34
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    35
#include "java_props_macosx.h"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    36
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12047
diff changeset
    37
char *getPosixLocale(int cat) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    38
    char *lc = setlocale(cat, NULL);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    39
    if ((lc == NULL) || (strcmp(lc, "C") == 0)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    40
        lc = getenv("LANG");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    41
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    42
    if (lc == NULL) return NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    43
    return strdup(lc);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    44
}
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
#define LOCALEIDLENGTH  128
51169
0058ffa0a922 8206886: Java does not set the default format locale correctly on mac10.13
naoto
parents: 50410
diff changeset
    47
#ifndef kCFCoreFoundationVersionNumber10_11_Max
0058ffa0a922 8206886: Java does not set the default format locale correctly on mac10.13
naoto
parents: 50410
diff changeset
    48
#define kCFCoreFoundationVersionNumber10_11_Max 1299
0058ffa0a922 8206886: Java does not set the default format locale correctly on mac10.13
naoto
parents: 50410
diff changeset
    49
#endif
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12047
diff changeset
    50
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
    51
    const char* retVal = NULL;
50410
01e4ddc3c23f 8203324: Use out of scope in getMacOSXLocale of java_props_macosx.c:120
naoto
parents: 47352
diff changeset
    52
    char languageString[LOCALEIDLENGTH];
45829
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
    53
    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
    54
51169
0058ffa0a922 8206886: Java does not set the default format locale correctly on mac10.13
naoto
parents: 50410
diff changeset
    55
    // 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
    56
    // "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
    57
    // for all LC_* categories.
0058ffa0a922 8206886: Java does not set the default format locale correctly on mac10.13
naoto
parents: 50410
diff changeset
    58
    if (kCFCoreFoundationVersionNumber >
0058ffa0a922 8206886: Java does not set the default format locale correctly on mac10.13
naoto
parents: 50410
diff changeset
    59
        kCFCoreFoundationVersionNumber10_11_Max) {
0058ffa0a922 8206886: Java does not set the default format locale correctly on mac10.13
naoto
parents: 50410
diff changeset
    60
        cat = LC_MESSAGES;
0058ffa0a922 8206886: Java does not set the default format locale correctly on mac10.13
naoto
parents: 50410
diff changeset
    61
    }
0058ffa0a922 8206886: Java does not set the default format locale correctly on mac10.13
naoto
parents: 50410
diff changeset
    62
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    63
    switch (cat) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    64
    case LC_MESSAGES:
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    65
        {
39144
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    66
            // get preferred language code
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    67
            CFArrayRef languages = CFLocaleCopyPreferredLanguages();
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    68
            if (languages == NULL) {
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    69
                return NULL;
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    70
            }
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    71
            if (CFArrayGetCount(languages) <= 0) {
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    72
                CFRelease(languages);
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    73
                return NULL;
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    74
            }
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    75
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    76
            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
    77
            if (primaryLanguage == NULL) {
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    78
                CFRelease(languages);
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    79
                return NULL;
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    80
            }
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    81
            if (CFStringGetCString(primaryLanguage, languageString,
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    82
                                   LOCALEIDLENGTH, CFStringGetSystemEncoding()) == false) {
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    83
                CFRelease(languages);
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    84
                return NULL;
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    85
            }
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
    86
            CFRelease(languages);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    87
45829
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
    88
            // 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
    89
            char *hyphenPos = strchr(languageString, '-');
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
    90
            int langStrLen = strlen(languageString);
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
    91
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
    92
            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
    93
                languageString + langStrLen - hyphenPos == 5) { // ISO639-ScriptCode, e.g., "en-Latn"
57534
de62b363bbe6 8228501: java_props_macosx.c - provide missing CFRelease for CFLocaleCopyCurrent
mbaesken
parents: 55169
diff changeset
    94
                CFLocaleRef cflocale = CFLocaleCopyCurrent();
de62b363bbe6 8228501: java_props_macosx.c - provide missing CFRelease for CFLocaleCopyCurrent
mbaesken
parents: 55169
diff changeset
    95
                if (cflocale != NULL) {
de62b363bbe6 8228501: java_props_macosx.c - provide missing CFRelease for CFLocaleCopyCurrent
mbaesken
parents: 55169
diff changeset
    96
                    CFStringGetCString(CFLocaleGetIdentifier(cflocale),
de62b363bbe6 8228501: java_props_macosx.c - provide missing CFRelease for CFLocaleCopyCurrent
mbaesken
parents: 55169
diff changeset
    97
                                   localeString, LOCALEIDLENGTH, CFStringGetSystemEncoding());
de62b363bbe6 8228501: java_props_macosx.c - provide missing CFRelease for CFLocaleCopyCurrent
mbaesken
parents: 55169
diff changeset
    98
                    char *underscorePos = strrchr(localeString, '_');
de62b363bbe6 8228501: java_props_macosx.c - provide missing CFRelease for CFLocaleCopyCurrent
mbaesken
parents: 55169
diff changeset
    99
                    char *region = NULL;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   100
57534
de62b363bbe6 8228501: java_props_macosx.c - provide missing CFRelease for CFLocaleCopyCurrent
mbaesken
parents: 55169
diff changeset
   101
                    if (underscorePos != NULL) {
de62b363bbe6 8228501: java_props_macosx.c - provide missing CFRelease for CFLocaleCopyCurrent
mbaesken
parents: 55169
diff changeset
   102
                        region = underscorePos + 1;
de62b363bbe6 8228501: java_props_macosx.c - provide missing CFRelease for CFLocaleCopyCurrent
mbaesken
parents: 55169
diff changeset
   103
                    }
45829
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   104
57534
de62b363bbe6 8228501: java_props_macosx.c - provide missing CFRelease for CFLocaleCopyCurrent
mbaesken
parents: 55169
diff changeset
   105
                    if (region != NULL) {
de62b363bbe6 8228501: java_props_macosx.c - provide missing CFRelease for CFLocaleCopyCurrent
mbaesken
parents: 55169
diff changeset
   106
                        strcat(languageString, "-");
de62b363bbe6 8228501: java_props_macosx.c - provide missing CFRelease for CFLocaleCopyCurrent
mbaesken
parents: 55169
diff changeset
   107
                        strcat(languageString, region);
de62b363bbe6 8228501: java_props_macosx.c - provide missing CFRelease for CFLocaleCopyCurrent
mbaesken
parents: 55169
diff changeset
   108
                    }
de62b363bbe6 8228501: java_props_macosx.c - provide missing CFRelease for CFLocaleCopyCurrent
mbaesken
parents: 55169
diff changeset
   109
                    CFRelease(cflocale);
45829
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   110
                }
39144
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
   111
            }
45829
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   112
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   113
            retVal = languageString;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   114
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   115
        break;
45829
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   116
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   117
    default:
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   118
        {
57534
de62b363bbe6 8228501: java_props_macosx.c - provide missing CFRelease for CFLocaleCopyCurrent
mbaesken
parents: 55169
diff changeset
   119
            CFLocaleRef cflocale = CFLocaleCopyCurrent();
de62b363bbe6 8228501: java_props_macosx.c - provide missing CFRelease for CFLocaleCopyCurrent
mbaesken
parents: 55169
diff changeset
   120
            if (cflocale != NULL) {
de62b363bbe6 8228501: java_props_macosx.c - provide missing CFRelease for CFLocaleCopyCurrent
mbaesken
parents: 55169
diff changeset
   121
                if (!CFStringGetCString(CFLocaleGetIdentifier(cflocale),
de62b363bbe6 8228501: java_props_macosx.c - provide missing CFRelease for CFLocaleCopyCurrent
mbaesken
parents: 55169
diff changeset
   122
                                        localeString, LOCALEIDLENGTH, CFStringGetSystemEncoding())) {
de62b363bbe6 8228501: java_props_macosx.c - provide missing CFRelease for CFLocaleCopyCurrent
mbaesken
parents: 55169
diff changeset
   123
                    CFRelease(cflocale);
de62b363bbe6 8228501: java_props_macosx.c - provide missing CFRelease for CFLocaleCopyCurrent
mbaesken
parents: 55169
diff changeset
   124
                    return NULL;
de62b363bbe6 8228501: java_props_macosx.c - provide missing CFRelease for CFLocaleCopyCurrent
mbaesken
parents: 55169
diff changeset
   125
                }
de62b363bbe6 8228501: java_props_macosx.c - provide missing CFRelease for CFLocaleCopyCurrent
mbaesken
parents: 55169
diff changeset
   126
de62b363bbe6 8228501: java_props_macosx.c - provide missing CFRelease for CFLocaleCopyCurrent
mbaesken
parents: 55169
diff changeset
   127
                retVal = localeString;
de62b363bbe6 8228501: java_props_macosx.c - provide missing CFRelease for CFLocaleCopyCurrent
mbaesken
parents: 55169
diff changeset
   128
                CFRelease(cflocale);
de62b363bbe6 8228501: java_props_macosx.c - provide missing CFRelease for CFLocaleCopyCurrent
mbaesken
parents: 55169
diff changeset
   129
            } else {
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
   130
                return NULL;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   131
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   132
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   133
        break;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   134
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   135
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
   136
    if (retVal != NULL) {
47352
33ac30e17843 8187772: JVM crash when currency set on MacOS 10.10 and earlier
bchristi
parents: 47216
diff changeset
   137
        // 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
   138
        // '@' and anything following, if present.
33ac30e17843 8187772: JVM crash when currency set on MacOS 10.10 and earlier
bchristi
parents: 47216
diff changeset
   139
        char* rmAt = strchr(retVal, '@');
33ac30e17843 8187772: JVM crash when currency set on MacOS 10.10 and earlier
bchristi
parents: 47216
diff changeset
   140
        if (rmAt != NULL) {
33ac30e17843 8187772: JVM crash when currency set on MacOS 10.10 and earlier
bchristi
parents: 47216
diff changeset
   141
            *rmAt = '\0';
33ac30e17843 8187772: JVM crash when currency set on MacOS 10.10 and earlier
bchristi
parents: 47216
diff changeset
   142
        }
45829
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   143
        return strdup(convertToPOSIXLocale(retVal));
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   144
    }
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   145
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   146
    return NULL;
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   147
}
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
   148
45829
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   149
/* 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
   150
 * 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
   151
 *
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   152
 * "en"         (language designator only)
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   153
 * "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
   154
 * "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
   155
 * "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
   156
 * "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
   157
 * "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
   158
 * "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
   159
 *
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   160
 * 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
   161
 * 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
   162
 */
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   163
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
   164
    char* scriptRegion = strchr(src, '-');
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   165
    if (scriptRegion != NULL) {
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   166
        int length = strlen(scriptRegion);
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   167
        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
   168
        char* atMark = NULL;
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   169
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   170
        if (region == NULL) {
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   171
            // CFLocaleGetIdentifier() returns '_' before region
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   172
            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
   173
        }
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
   174
45829
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   175
        *scriptRegion = '_';
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   176
        if (length > 5) {
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   177
            // 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
   178
            char tmpScript[4];
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   179
            int regionLength = length - 6;
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   180
            atMark = scriptRegion + 1 + regionLength;
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   181
            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
   182
            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
   183
            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
   184
        } else if (length == 5) {
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   185
            // script only
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   186
            atMark = scriptRegion;
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
        if (atMark != NULL) {
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   190
            *atMark = '@';
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   191
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   192
            // assert script code
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   193
            assert(isalpha(atMark[1]) &&
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   194
                   isalpha(atMark[2]) &&
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   195
                   isalpha(atMark[3]) &&
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   196
                   isalpha(atMark[4]));
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   197
        }
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   198
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   199
        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
   200
            // '_' 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
   201
                isalpha(scriptRegion[1]) &&
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   202
                isalpha(scriptRegion[2])) ||
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   203
                ((length == 4 || length == 9) &&
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   204
            // '_' 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
   205
                isdigit(scriptRegion[1]) &&
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   206
                isdigit(scriptRegion[2]) &&
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   207
                isdigit(scriptRegion[3])) ||
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   208
            // '@' 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
   209
                (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
   210
    }
45829
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   211
991121499947 8160199: Language's script should be reflected in user.script on Mac OS X
naoto
parents: 44044
diff changeset
   212
    return src;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   213
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   214
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12047
diff changeset
   215
char *setupMacOSXLocale(int cat) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12047
diff changeset
   216
    char * ret = getMacOSXLocale(cat);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12047
diff changeset
   217
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12047
diff changeset
   218
    if (ret == NULL) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12047
diff changeset
   219
        return getPosixLocale(cat);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12047
diff changeset
   220
    } else {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12047
diff changeset
   221
        return ret;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12047
diff changeset
   222
    }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12047
diff changeset
   223
}
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12047
diff changeset
   224
39144
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
   225
// 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
   226
// 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
   227
typedef struct {
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
   228
        NSInteger majorVersion;
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
   229
        NSInteger minorVersion;
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
   230
        NSInteger patchVersion;
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
   231
} OSVerStruct;
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
   232
14513
f6dc8c52e275 7178922: (props) re-visit how os.name is determined on Mac
bchristi
parents: 14342
diff changeset
   233
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
   234
    // 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
   235
    sprops->os_name = strdup("Mac OS X");
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   236
39144
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
   237
    char* osVersionCStr = NULL;
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
   238
    // 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
   239
    // 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
   240
    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
   241
        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
   242
        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
   243
                                       @selector(operatingSystemVersion));
39765
c1aee33ef0c0 8161039: System.getProperty("os.version") returns incorrect version number on Mac
bchristi
parents: 39322
diff changeset
   244
        NSString *nsVerStr;
c1aee33ef0c0 8161039: System.getProperty("os.version") returns incorrect version number on Mac
bchristi
parents: 39322
diff changeset
   245
        if (osVer.patchVersion == 0) { // Omit trailing ".0"
c1aee33ef0c0 8161039: System.getProperty("os.version") returns incorrect version number on Mac
bchristi
parents: 39322
diff changeset
   246
            nsVerStr = [NSString stringWithFormat:@"%ld.%ld",
c1aee33ef0c0 8161039: System.getProperty("os.version") returns incorrect version number on Mac
bchristi
parents: 39322
diff changeset
   247
                    (long)osVer.majorVersion, (long)osVer.minorVersion];
c1aee33ef0c0 8161039: System.getProperty("os.version") returns incorrect version number on Mac
bchristi
parents: 39322
diff changeset
   248
        } else {
c1aee33ef0c0 8161039: System.getProperty("os.version") returns incorrect version number on Mac
bchristi
parents: 39322
diff changeset
   249
            nsVerStr = [NSString stringWithFormat:@"%ld.%ld.%ld",
c1aee33ef0c0 8161039: System.getProperty("os.version") returns incorrect version number on Mac
bchristi
parents: 39322
diff changeset
   250
                    (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
   251
        }
39144
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
   252
        // Copy out the char*
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
   253
        osVersionCStr = strdup([nsVerStr UTF8String]);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   254
    }
39322
66ecf193683a 8160370: System.getProperty("os.version") returns "Unknown" on Mac
bchristi
parents: 39144
diff changeset
   255
    // Fallback if running on pre-10.9 Mac OS
66ecf193683a 8160370: System.getProperty("os.version") returns "Unknown" on Mac
bchristi
parents: 39144
diff changeset
   256
    if (osVersionCStr == NULL) {
66ecf193683a 8160370: System.getProperty("os.version") returns "Unknown" on Mac
bchristi
parents: 39144
diff changeset
   257
        NSDictionary *version = [NSDictionary dictionaryWithContentsOfFile :
66ecf193683a 8160370: System.getProperty("os.version") returns "Unknown" on Mac
bchristi
parents: 39144
diff changeset
   258
                                 @"/System/Library/CoreServices/SystemVersion.plist"];
66ecf193683a 8160370: System.getProperty("os.version") returns "Unknown" on Mac
bchristi
parents: 39144
diff changeset
   259
        if (version != NULL) {
66ecf193683a 8160370: System.getProperty("os.version") returns "Unknown" on Mac
bchristi
parents: 39144
diff changeset
   260
            NSString *nsVerStr = [version objectForKey : @"ProductVersion"];
66ecf193683a 8160370: System.getProperty("os.version") returns "Unknown" on Mac
bchristi
parents: 39144
diff changeset
   261
            if (nsVerStr != NULL) {
66ecf193683a 8160370: System.getProperty("os.version") returns "Unknown" on Mac
bchristi
parents: 39144
diff changeset
   262
                osVersionCStr = strdup([nsVerStr UTF8String]);
66ecf193683a 8160370: System.getProperty("os.version") returns "Unknown" on Mac
bchristi
parents: 39144
diff changeset
   263
            }
66ecf193683a 8160370: System.getProperty("os.version") returns "Unknown" on Mac
bchristi
parents: 39144
diff changeset
   264
        }
66ecf193683a 8160370: System.getProperty("os.version") returns "Unknown" on Mac
bchristi
parents: 39144
diff changeset
   265
    }
39144
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
   266
    if (osVersionCStr == NULL) {
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
   267
        osVersionCStr = strdup("Unknown");
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
   268
    }
50f8aee9012d 7131356: (props) "No Java runtime present, requesting install" when creating VM from JNI [macosx]
bchristi
parents: 33653
diff changeset
   269
    sprops->os_version = osVersionCStr;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   270
}
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
39322
66ecf193683a 8160370: System.getProperty("os.version") returns "Unknown" on Mac
bchristi
parents: 39144
diff changeset
   273
static Boolean getProxyInfoForProtocol(CFDictionaryRef inDict, CFStringRef inEnabledKey,
66ecf193683a 8160370: System.getProperty("os.version") returns "Unknown" on Mac
bchristi
parents: 39144
diff changeset
   274
                                       CFStringRef inHostKey, CFStringRef inPortKey,
66ecf193683a 8160370: System.getProperty("os.version") returns "Unknown" on Mac
bchristi
parents: 39144
diff changeset
   275
                                       CFStringRef *outProxyHost, int *ioProxyPort) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   276
    /* See if the proxy is enabled. */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   277
    CFNumberRef cf_enabled = CFDictionaryGetValue(inDict, inEnabledKey);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   278
    if (cf_enabled == NULL) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   279
        return false;
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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   282
    int isEnabled = false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   283
    if (!CFNumberGetValue(cf_enabled, kCFNumberIntType, &isEnabled)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   284
        return isEnabled;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   285
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   286
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   287
    if (!isEnabled) return false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   288
    *outProxyHost = CFDictionaryGetValue(inDict, inHostKey);
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
    // If cf_host is null, that means the checkbox is set,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   291
    //   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
   292
    // 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
   293
    //   no port number was entered. Treat this as ENABLED with the
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   294
    //   protocol's default port.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   295
    if (*outProxyHost == NULL) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   296
        return false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   297
    }
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 (CFStringGetLength(*outProxyHost) == 0) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   300
        return false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   301
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   302
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   303
    int newPort = 0;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   304
    CFNumberRef cf_port = NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   305
    if ((cf_port = CFDictionaryGetValue(inDict, inPortKey)) != NULL &&
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   306
        CFNumberGetValue(cf_port, kCFNumberIntType, &newPort) &&
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   307
        newPort > 0) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   308
        *ioProxyPort = newPort;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   309
    } else {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   310
        // bad port or no port - leave *ioProxyPort unchanged
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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   313
    return true;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   314
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   315
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   316
static char *createUTF8CString(const CFStringRef theString) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   317
    if (theString == NULL) return NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   318
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   319
    const CFIndex stringLength = CFStringGetLength(theString);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   320
    const CFIndex bufSize = CFStringGetMaximumSizeForEncoding(stringLength, kCFStringEncodingUTF8) + 1;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   321
    char *returnVal = (char *)malloc(bufSize);
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
    if (CFStringGetCString(theString, returnVal, bufSize, kCFStringEncodingUTF8)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   324
        return returnVal;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   325
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   326
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   327
    free(returnVal);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   328
    return NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   329
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   330
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   331
// Return TRUE if str is a syntactically valid IP address.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   332
// Using inet_pton() instead of inet_aton() for IPv6 support.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   333
// len is only a hint; cstr must still be nul-terminated
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   334
static int looksLikeIPAddress(char *cstr, size_t len) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   335
    if (len == 0  ||  (len == 1 && cstr[0] == '.')) return FALSE;
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
    char dst[16]; // big enough for INET6
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   338
    return (1 == inet_pton(AF_INET, cstr, dst)  ||
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   339
            1 == inet_pton(AF_INET6, cstr, dst));
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   340
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   341
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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   344
// Convert Mac OS X proxy exception entry to Java syntax.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   345
// See Radar #3441134 for details.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   346
// Returns NULL if this exception should be ignored by Java.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   347
// May generate a string with multiple exceptions separated by '|'.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   348
static char * createConvertedException(CFStringRef cf_original) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   349
    // This is done with char* instead of CFString because inet_pton()
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   350
    // needs a C string.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   351
    char *c_exception = createUTF8CString(cf_original);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   352
    if (!c_exception) return NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   353
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   354
    int c_len = strlen(c_exception);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   355
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   356
    // 1. sanitize exception prefix
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   357
    if (c_len >= 1  &&  0 == strncmp(c_exception, ".", 1)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   358
        memmove(c_exception, c_exception+1, c_len);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   359
        c_len -= 1;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   360
    } else if (c_len >= 2  &&  0 == strncmp(c_exception, "*.", 2)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   361
        memmove(c_exception, c_exception+2, c_len-1);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   362
        c_len -= 2;
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
    // 2. pre-reject other exception wildcards
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   366
    if (strchr(c_exception, '*')) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   367
        free(c_exception);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   368
        return NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   369
    }
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
    // 3. no IP wildcarding
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   372
    if (looksLikeIPAddress(c_exception, c_len)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   373
        return c_exception;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   374
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   375
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   376
    // 4. allow domain suffixes
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   377
    // c_exception is now "str\0" - change to "str|*.str\0"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   378
    c_exception = reallocf(c_exception, c_len+3+c_len+1);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   379
    if (!c_exception) return NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   380
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   381
    strncpy(c_exception+c_len, "|*.", 3);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   382
    strncpy(c_exception+c_len+3, c_exception, c_len);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   383
    c_exception[c_len+3+c_len] = '\0';
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   384
    return c_exception;
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
19857
d3a868255edb 7199674: (props) user.home property does not return an accessible location in sandboxed environment [macosx]
bchristi
parents: 14662
diff changeset
   387
/*
d3a868255edb 7199674: (props) user.home property does not return an accessible location in sandboxed environment [macosx]
bchristi
parents: 14662
diff changeset
   388
 * 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
   389
 * 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
   390
 * 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
   391
 */
d3a868255edb 7199674: (props) user.home property does not return an accessible location in sandboxed environment [macosx]
bchristi
parents: 14662
diff changeset
   392
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
   393
    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
   394
    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
   395
    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
   396
    [pool drain];
d3a868255edb 7199674: (props) user.home property does not return an accessible location in sandboxed environment [macosx]
bchristi
parents: 14662
diff changeset
   397
}
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   398
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   399
/*
19857
d3a868255edb 7199674: (props) user.home property does not return an accessible location in sandboxed environment [macosx]
bchristi
parents: 14662
diff changeset
   400
 * 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
   401
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   402
void setProxyProperties(java_props_t *sProps) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   403
    if (sProps == NULL) return;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   404
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   405
    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
   406
    CFStringRef
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   407
    cf_httpHost = NULL,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   408
    cf_httpsHost = NULL,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   409
    cf_ftpHost = NULL,
52733
1d520c376105 8214460: MacosX build is broken because of JDK-8214014
smarks
parents: 52725
diff changeset
   410
    cf_socksHost = NULL;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   411
    int
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   412
    httpPort = 80, // Default proxy port values
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   413
    httpsPort = 443,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   414
    ftpPort = 21,
52733
1d520c376105 8214460: MacosX build is broken because of JDK-8214014
smarks
parents: 52725
diff changeset
   415
    socksPort = 1080;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   416
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   417
    CFDictionaryRef dict = SCDynamicStoreCopyProxies(NULL);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   418
    if (dict == NULL) return;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   419
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   420
    /* Read the proxy exceptions list */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   421
    CFArrayRef cf_list = CFDictionaryGetValue(dict, kSCPropNetProxiesExceptionsList);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   422
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   423
    CFMutableStringRef cf_exceptionList = NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   424
    if (cf_list != NULL) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   425
        CFIndex len = CFArrayGetCount(cf_list), idx;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   426
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   427
        cf_exceptionList = CFStringCreateMutable(NULL, 0);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   428
        for (idx = (CFIndex)0; idx < len; idx++) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   429
            CFStringRef cf_ehost;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   430
            if ((cf_ehost = CFArrayGetValueAtIndex(cf_list, idx))) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   431
                /* Convert this exception from Mac OS X syntax to Java syntax.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   432
                 See Radar #3441134 for details. This may generate a string
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   433
                 with multiple Java exceptions separated by '|'. */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   434
                char *c_exception = createConvertedException(cf_ehost);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   435
                if (c_exception) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   436
                    /* Append the host to the list of exclusions. */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   437
                    if (CFStringGetLength(cf_exceptionList) > 0) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   438
                        CFStringAppendCString(cf_exceptionList, "|", kCFStringEncodingMacRoman);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   439
                    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   440
                    CFStringAppendCString(cf_exceptionList, c_exception, kCFStringEncodingMacRoman);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   441
                    free(c_exception);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   442
                }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   443
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   444
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   445
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   446
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   447
    if (cf_exceptionList != NULL) {
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
            sProps->exceptionList = createUTF8CString(cf_exceptionList);
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
        CFRelease(cf_exceptionList);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   452
    }
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
#define CHECK_PROXY(protocol, PROTOCOL)                                     \
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   455
    sProps->protocol##ProxyEnabled =                                        \
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   456
    getProxyInfoForProtocol(dict, kSCPropNetProxies##PROTOCOL##Enable,      \
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   457
    kSCPropNetProxies##PROTOCOL##Proxy,         \
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   458
    kSCPropNetProxies##PROTOCOL##Port,          \
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   459
    &cf_##protocol##Host, &protocol##Port);     \
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   460
    if (sProps->protocol##ProxyEnabled) {                                   \
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   461
        sProps->protocol##Host = createUTF8CString(cf_##protocol##Host);    \
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   462
        snprintf(buf, sizeof(buf), "%d", protocol##Port);                   \
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   463
        sProps->protocol##Port = malloc(strlen(buf) + 1);                   \
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   464
        strcpy(sProps->protocol##Port, buf);                                \
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   465
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   466
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   467
    CHECK_PROXY(http, HTTP);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   468
    CHECK_PROXY(https, HTTPS);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   469
    CHECK_PROXY(ftp, FTP);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   470
    CHECK_PROXY(socks, SOCKS);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   471
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   472
#undef CHECK_PROXY
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   473
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   474
    CFRelease(dict);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   475
}