[vlc-commits] src: implement proxy URL support for Darwin

Felix Paul Kühne git at videolan.org
Sun Apr 14 11:40:53 CEST 2013


vlc | branch: master | Felix Paul Kühne <fkuehne at videolan.org> | Sun Apr 14 11:40:32 2013 +0200| [b3efcf715fbd06bf981deb183e6b30e755ab5e7c] | committer: Felix Paul Kühne

src: implement proxy URL support for Darwin

Needs some more testing, especially on embedded platforms

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=b3efcf715fbd06bf981deb183e6b30e755ab5e7c
---

 configure.ac         |    2 +-
 src/Makefile.am      |    1 +
 src/darwin/netconf.c |   73 ++++++++++++++++++++++++++++++++++++++++++++++++++
 src/win32/netconf.c  |    2 +-
 4 files changed, 76 insertions(+), 2 deletions(-)

diff --git a/configure.ac b/configure.ac
index 34c0a12..8d053cf 100644
--- a/configure.ac
+++ b/configure.ac
@@ -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,
diff --git a/src/Makefile.am b/src/Makefile.am
index 24b73e2..af4c10b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -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
index 0000000..ebda7da
--- /dev/null
+++ b/src/darwin/netconf.c
@@ -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;
+}
diff --git a/src/win32/netconf.c b/src/win32/netconf.c
index f1e0707..accdddf 100644
--- a/src/win32/netconf.c
+++ b/src/win32/netconf.c
@@ -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 );



More information about the vlc-commits mailing list