packetizer: hxxx: fix DirectTV extraction
[vlc.git] / src / darwin / netconf.c
blobd5f66664a49eda91640cdf2c829739bd493e8d83
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>
33 #import <TargetConditionals.h>
34 #if TARGET_OS_IPHONE
35 #include <CFNetwork/CFProxySupport.h>
36 #else
37 #include <CoreServices/CoreServices.h>
38 #endif
40 /**
41 * Determines the network proxy server to use (if any).
42 * @param url absolute URL for which to get the proxy server (not used)
43 * @return proxy URL, NULL if no proxy or error
45 char *vlc_getProxyUrl(const char *url)
47 VLC_UNUSED(url);
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 sprintf(buffer, "%s:%d", host_buffer, port);
68 proxy_url = strdup(buffer);
72 CFRelease(dicRef);
75 return proxy_url;