1 /*****************************************************************************
2 * netconf.c : Network configuration
3 *****************************************************************************
4 * Copyright (C) 2013 VLC authors and VideoLAN
7 * Authors: Felix Paul Kühne <fkuehne # videolan org>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2.1 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
28 #include <vlc_common.h>
29 #include <vlc_network.h>
31 #import <TargetConditionals.h>
32 #include <CoreFoundation/CoreFoundation.h>
34 #include <CFNetwork/CFProxySupport.h>
36 #include <SystemConfiguration/SystemConfiguration.h>
40 * Determines the network proxy server to use (if any).
41 * @param url absolute URL for which to get the proxy server (not used)
42 * @return proxy URL, NULL if no proxy or error
44 char *vlc_getProxyUrl(const char *url)
48 char *proxy_url = NULL;
49 CFDictionaryRef dicRef = CFNetworkCopySystemProxySettings();
51 const CFStringRef proxyCFstr = (const CFStringRef)CFDictionaryGetValue(
52 dicRef, (const void*)kCFNetworkProxiesHTTPProxy);
53 const CFNumberRef portCFnum = (const CFNumberRef)CFDictionaryGetValue(
54 dicRef, (const void*)kCFNetworkProxiesHTTPPort);
55 if (NULL != proxyCFstr && NULL != portCFnum) {
57 if (!CFNumberGetValue(portCFnum, kCFNumberIntType, &port)) {
62 char host_buffer[4096];
63 memset(host_buffer, 0, sizeof(host_buffer));
64 if (CFStringGetCString(proxyCFstr, host_buffer, sizeof(host_buffer)
65 - 1, kCFStringEncodingUTF8)) {
67 memset(host_buffer, 0, sizeof(host_buffer));
68 sprintf(buffer, "%s:%d", host_buffer, port);
69 proxy_url = strdup(buffer);
78 CFDictionaryRef proxies = SCDynamicStoreCopyProxies(NULL);
79 char *proxy_url = NULL;
82 CFNumberRef cfn_httpProxyOn =
83 (CFNumberRef)CFDictionaryGetValue(proxies,
84 kSCPropNetProxiesHTTPEnable);
85 if (cfn_httpProxyOn) {
87 CFNumberGetValue(cfn_httpProxyOn, kCFNumberIntType, &i_httpProxyOn);
88 CFRelease(cfn_httpProxyOn);
90 if (i_httpProxyOn == 1) // http proxy is on
92 CFStringRef httpProxy =
93 (CFStringRef)CFDictionaryGetValue(proxies,
94 kSCPropNetProxiesHTTPProxy);
97 CFNumberRef cfn_httpProxyPort =
98 (CFNumberRef)CFDictionaryGetValue(proxies,
99 kSCPropNetProxiesHTTPPort);
101 CFNumberGetValue(cfn_httpProxyPort,
104 CFRelease(cfn_httpProxyPort);
106 CFMutableStringRef outputURL =
107 CFStringCreateMutableCopy(kCFAllocatorDefault,
110 if (i_httpProxyPort > 0)
111 CFStringAppendFormat(outputURL,
117 if (CFStringGetCString(outputURL, buffer, sizeof(buffer),
118 kCFStringEncodingUTF8))
119 proxy_url = strdup(buffer);
121 CFRelease(outputURL);
123 CFRelease(httpProxy);