src/darwin: fix crash while accessing http content while no proxy is set
[vlc/vlc-acra.git] / src / darwin / netconf.c
blob45abf9b6d27301544f73023cad231e3942985a16
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 #include <CoreFoundation/CoreFoundation.h>
32 #include <SystemConfiguration/SystemConfiguration.h>
34 /**
35 * Determines the network proxy server to use (if any).
36 * @param url absolute URL for which to get the proxy server (not used)
37 * @return proxy URL, NULL if no proxy or error
39 char *vlc_getProxyUrl(const char *url)
41 VLC_UNUSED(url);
42 CFDictionaryRef proxies = SCDynamicStoreCopyProxies(NULL);
43 char *proxy_url = NULL;
45 if (proxies) {
46 CFNumberRef cfn_httpProxyOn =
47 (CFNumberRef)CFDictionaryGetValue(proxies,
48 kSCPropNetProxiesHTTPEnable);
49 if (cfn_httpProxyOn) {
50 int i_httpProxyOn;
51 CFNumberGetValue(cfn_httpProxyOn, kCFNumberIntType, &i_httpProxyOn);
52 CFRelease(cfn_httpProxyOn);
54 if (i_httpProxyOn == 1) // http proxy is on
56 CFStringRef httpProxy =
57 (CFStringRef)CFDictionaryGetValue(proxies,
58 kSCPropNetProxiesHTTPProxy);
60 if (httpProxy) {
61 CFNumberRef cfn_httpProxyPort =
62 (CFNumberRef)CFDictionaryGetValue(proxies,
63 kSCPropNetProxiesHTTPPort);
64 int i_httpProxyPort;
65 CFNumberGetValue(cfn_httpProxyPort,
66 kCFNumberIntType,
67 &i_httpProxyPort);
68 CFRelease(cfn_httpProxyPort);
70 CFMutableStringRef outputURL =
71 CFStringCreateMutableCopy(kCFAllocatorDefault,
73 httpProxy);
74 if (i_httpProxyPort > 0)
75 CFStringAppendFormat(outputURL,
76 NULL,
77 CFSTR(":%i"),
78 i_httpProxyPort);
80 CFStringGetCString(outputURL,
81 proxy_url,
82 sizeof(proxy_url),
83 kCFStringEncodingASCII);
84 CFRelease(outputURL);
86 CFRelease(httpProxy);
89 CFRelease(proxies);
92 return proxy_url;