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 #include <CoreFoundation/CoreFoundation.h>
33 #import <TargetConditionals.h>
35 #include <CFNetwork/CFProxySupport.h>
37 #include <CoreServices/CoreServices.h>
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
)
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 sprintf(buffer
, "%s:%d", host_buffer
, port
);
68 proxy_url
= strdup(buffer
);