]> git.sesse.net Git - vlc/commitdiff
src: implement proxy URL support for Darwin
authorFelix Paul Kühne <fkuehne@videolan.org>
Sun, 14 Apr 2013 09:40:32 +0000 (11:40 +0200)
committerFelix Paul Kühne <fkuehne@videolan.org>
Sun, 14 Apr 2013 09:40:32 +0000 (11:40 +0200)
Needs some more testing, especially on embedded platforms

configure.ac
src/Makefile.am
src/darwin/netconf.c [new file with mode: 0644]
src/win32/netconf.c

index 34c0a12b83cf3bbaf5f09686fab2f0ace11611e1..8d053cfb564793d9be36a1926bdc98e21367b90d 100644 (file)
@@ -158,7 +158,7 @@ case "${host_os}" in
     VLC_ADD_LIBS([libvlc vlc],[-Wl,-undefined,dynamic_lookup,-framework,AppKit])
     VLC_ADD_LIBS([avcodec access_avio swscale postproc i420_rgb_mmx x264 x26410b],[-Wl,-read_only_relocs,suppress])
     VLC_ADD_CFLAGS([motion rotate],[-fconstant-cfstrings])
-    VLC_ADD_LIBS([libvlccore],[-Wl,-framework,CoreFoundation])
+    VLC_ADD_LIBS([libvlccore],[-Wl,-framework,CoreFoundation,-framework,SystemConfiguration])
 
     dnl Allow binaries created on Lion to run on earlier releases
     AC_EGREP_CPP(yes,
index 24b73e21d91a9b0b7bc3e4705cd9dbeea5b5c3b4..af4c10b0bf83ec2a9cb6c9e3d3b8cdbb3ec60b1c 100644 (file)
@@ -252,6 +252,7 @@ SOURCES_libvlc_darwin = \
        posix/timer.c \
        darwin/specific.c \
        posix/rand.c \
+       darwin/netconf.c \
        $(NULL)
 
 SOURCES_libvlc_android = \
diff --git a/src/darwin/netconf.c b/src/darwin/netconf.c
new file mode 100644 (file)
index 0000000..ebda7da
--- /dev/null
@@ -0,0 +1,73 @@
+/*****************************************************************************
+ * netconf.c : Network configuration
+ *****************************************************************************
+ * Copyright (C) 2013 VLC authors and VideoLAN
+ * $Id$
+ *
+ * Authors: Felix Paul Kühne <fkuehne # videolan org>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_network.h>
+
+#include <CoreFoundation/CoreFoundation.h>
+#include <SystemConfiguration/SystemConfiguration.h>
+
+/**
+ * Determines the network proxy server to use (if any).
+ * @param url absolute URL for which to get the proxy server (not used)
+ * @return proxy URL, NULL if no proxy or error
+ */
+char *vlc_getProxyUrl(const char *url)
+{
+    VLC_UNUSED(url);
+    CFDictionaryRef proxies = SCDynamicStoreCopyProxies(NULL);
+    char *proxy_url = NULL;
+
+    if (proxies) {
+        CFNumberRef cfn_httpProxyOn = (CFNumberRef)CFDictionaryGetValue(proxies, kSCPropNetProxiesHTTPEnable);
+        int i_httpProxyOn;
+        CFNumberGetValue(cfn_httpProxyOn, kCFNumberIntType, &i_httpProxyOn);
+        CFRelease(cfn_httpProxyOn);
+        if (i_httpProxyOn == 1) // http proxy is on
+        {
+            CFStringRef httpProxy = (CFStringRef)CFDictionaryGetValue(proxies, kSCPropNetProxiesHTTPProxy);
+
+            if (httpProxy) {
+                CFNumberRef cfn_httpProxyPort = (CFNumberRef)CFDictionaryGetValue(proxies, kSCPropNetProxiesHTTPPort);
+                int i_httpProxyPort;
+                CFNumberGetValue(cfn_httpProxyPort, kCFNumberIntType, &i_httpProxyPort);
+                CFRelease(cfn_httpProxyPort);
+
+                CFMutableStringRef outputURL = CFStringCreateMutableCopy(kCFAllocatorDefault, 0, httpProxy);
+                if (i_httpProxyPort > 0)
+                    CFStringAppendFormat(outputURL,NULL,CFSTR(":%i"),i_httpProxyPort);
+
+                CFStringGetCString(outputURL, proxy_url, sizeof(proxy_url), kCFStringEncodingASCII);
+                CFRelease(outputURL);
+            }
+            CFRelease(httpProxy);
+        }
+        CFRelease(proxies);
+    }
+
+    return proxy_url;
+}
index f1e07072cd50568c0a58415f68b72a5320ecbddd..accdddf2ce2ab35d6b89268f9b5d171959711f23 100644 (file)
@@ -54,7 +54,7 @@ char *vlc_getProxyUrl(const char *url)
     /* Get the proxy URL :
        Proxy server value in the registry can be something like "address:port"
        or "ftp=address1:port1;http=address2:port2 ..."
-       depending of the confirguration. */
+       depending of the configuration. */
     unsigned char key[256];
 
     len = sizeof( key );