access: http: only warn on deflate errors
[vlc.git] / src / darwin / netconf.c
blob0d9ca432bdcc89da6a920c895df8b0565422805c
1 /*****************************************************************************
2 * netconf.c : Network configuration
3 *****************************************************************************
4 * Copyright (C) 2013 VLC authors and VideoLAN
5 * $Id$
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 *****************************************************************************/
24 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
28 #include <vlc_common.h>
29 #include <vlc_network.h>
31 #import <TargetConditionals.h>
32 #include <CoreFoundation/CoreFoundation.h>
33 #if TARGET_OS_IPHONE
34 #include <CFNetwork/CFProxySupport.h>
35 #else
36 #include <SystemConfiguration/SystemConfiguration.h>
37 #endif
39 /**
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)
46 VLC_UNUSED(url);
47 #if TARGET_OS_IPHONE
48 char *proxy_url = NULL;
49 CFDictionaryRef dicRef = CFNetworkCopySystemProxySettings();
50 if (NULL != dicRef) {
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) {
56 int port = 0;
57 if (!CFNumberGetValue(portCFnum, kCFNumberIntType, &port)) {
58 CFRelease(dicRef);
59 return NULL;
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)) {
66 char buffer[4096];
67 memset(host_buffer, 0, sizeof(host_buffer));
68 sprintf(buffer, "%s:%d", host_buffer, port);
69 proxy_url = strdup(buffer);
73 CFRelease(dicRef);
76 return proxy_url;
77 #else
78 CFDictionaryRef proxies = SCDynamicStoreCopyProxies(NULL);
79 char *proxy_url = NULL;
81 if (proxies) {
82 CFNumberRef cfn_httpProxyOn =
83 (CFNumberRef)CFDictionaryGetValue(proxies,
84 kSCPropNetProxiesHTTPEnable);
85 if (cfn_httpProxyOn) {
86 int i_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);
96 if (httpProxy) {
97 CFNumberRef cfn_httpProxyPort =
98 (CFNumberRef)CFDictionaryGetValue(proxies,
99 kSCPropNetProxiesHTTPPort);
100 int i_httpProxyPort;
101 CFNumberGetValue(cfn_httpProxyPort,
102 kCFNumberIntType,
103 &i_httpProxyPort);
104 CFRelease(cfn_httpProxyPort);
106 CFMutableStringRef outputURL =
107 CFStringCreateMutableCopy(kCFAllocatorDefault,
109 httpProxy);
110 if (i_httpProxyPort > 0)
111 CFStringAppendFormat(outputURL,
112 NULL,
113 CFSTR(":%i"),
114 i_httpProxyPort);
116 char buffer[4096];
117 if (CFStringGetCString(outputURL, buffer, sizeof(buffer),
118 kCFStringEncodingUTF8))
119 proxy_url = strdup(buffer);
121 CFRelease(outputURL);
123 CFRelease(httpProxy);
126 CFRelease(proxies);
129 return proxy_url;
130 #endif