[vlc-commits] src/darwin: re-write netconf to return specific proxies for requested schemes (closes #21150)

Felix Paul Kühne git at videolan.org
Tue Sep 11 16:27:23 CEST 2018


vlc | branch: master | Felix Paul Kühne <felix at feepk.net> | Tue Sep 11 16:24:14 2018 +0200| [4543dbc51161527d96ccee94451d32443eca5010] | committer: Felix Paul Kühne

src/darwin: re-write netconf to return specific proxies for requested schemes (closes #21150)

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

 NEWS                 |  2 ++
 src/Makefile.am      |  5 ++--
 src/darwin/netconf.c | 73 ------------------------------------------------
 src/darwin/netconf.m | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 84 insertions(+), 75 deletions(-)

diff --git a/NEWS b/NEWS
index b4fac69e9b..7a4388d5f2 100644
--- a/NEWS
+++ b/NEWS
@@ -44,6 +44,8 @@ Stream output:
 macOS:
  * Remove Growl notification support
 
+appleOS:
+ * Improved proxy configuration handling
 
 
 Changes between 3.0.2 and 3.0.3:
diff --git a/src/Makefile.am b/src/Makefile.am
index 83e2e3b152..daf85d733d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -420,7 +420,7 @@ if HAVE_DARWIN
 libvlccore_la_SOURCES += \
 	darwin/dirs.c \
 	darwin/error.c \
-	darwin/netconf.c \
+	darwin/netconf.m \
 	darwin/specific.c \
 	darwin/thread.c
 else
@@ -486,7 +486,8 @@ if HAVE_DBUS
 libvlccore_la_LIBADD += $(DBUS_LIBS)
 endif
 if HAVE_DARWIN
-libvlccore_la_LDFLAGS += -Xlinker -install_name -Xlinker @rpath/libvlccore.dylib
+libvlccore_la_OBJCFLAGS = $(AM_OBJCFLAGS) -fobjc-arc
+libvlccore_la_LDFLAGS += -Wl,-framework,Foundation -Xlinker -install_name -Xlinker @rpath/libvlccore.dylib
 endif
 
 libvlc_win32_rc.$(OBJEXT): libvlc_win32_rc.rc $(top_srcdir)/extras/package/win32/libvlc.dll.manifest
diff --git a/src/darwin/netconf.c b/src/darwin/netconf.c
deleted file mode 100644
index 6ab9044319..0000000000
--- a/src/darwin/netconf.c
+++ /dev/null
@@ -1,73 +0,0 @@
-/*****************************************************************************
- * 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>
-
-#import <TargetConditionals.h>
-#if TARGET_OS_IPHONE
-#include <CFNetwork/CFProxySupport.h>
-#else
-#include <CoreServices/CoreServices.h>
-#endif
-
-/**
- * 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);
-    char *proxy_url = NULL;
-    CFDictionaryRef dicRef = CFNetworkCopySystemProxySettings();
-    if (NULL != dicRef) {
-        const CFStringRef proxyCFstr = (const CFStringRef)CFDictionaryGetValue(
-            dicRef, (const void*)kCFNetworkProxiesHTTPProxy);
-        const CFNumberRef portCFnum = (const CFNumberRef)CFDictionaryGetValue(
-            dicRef, (const void*)kCFNetworkProxiesHTTPPort);
-        if (NULL != proxyCFstr && NULL != portCFnum) {
-            int port = 0;
-            if (!CFNumberGetValue(portCFnum, kCFNumberIntType, &port)) {
-                CFRelease(dicRef);
-                return NULL;
-            }
-
-            char host_buffer[4096];
-            memset(host_buffer, 0, sizeof(host_buffer));
-            if (CFStringGetCString(proxyCFstr, host_buffer, sizeof(host_buffer)
-                                   - 1, kCFStringEncodingUTF8))
-                asprintf(&proxy_url, "http://%s:%d", host_buffer, port);
-        }
-
-        CFRelease(dicRef);
-    }
-
-    return proxy_url;
-}
diff --git a/src/darwin/netconf.m b/src/darwin/netconf.m
new file mode 100644
index 0000000000..eee34cc1b1
--- /dev/null
+++ b/src/darwin/netconf.m
@@ -0,0 +1,79 @@
+/*****************************************************************************
+ * netconf.m : Network configuration
+ *****************************************************************************
+ * Copyright (C) 2013-2018 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>
+
+#import <Foundation/Foundation.h>
+
+#import <TargetConditionals.h>
+#if TARGET_OS_IPHONE
+#include <CFNetwork/CFProxySupport.h>
+#else
+#include <CoreServices/CoreServices.h>
+#endif
+
+/**
+ * Determines the network proxy server to use (if any).
+ * @param url absolute URL for which to get the proxy server
+ * @return proxy URL, NULL if no proxy or error
+ */
+char *vlc_getProxyUrl(const char *url)
+{
+    if (url == NULL) {
+        return NULL;
+    }
+
+    NSDictionary *proxySettings = CFBridgingRelease(CFNetworkCopySystemProxySettings());
+    if (NULL != proxySettings) {
+        NSURL *requestedURL = [[NSURL alloc] initWithString:[NSString stringWithUTF8String:url]];
+        NSString *scheme = requestedURL.scheme;
+        NSString *proxyHost;
+        NSNumber *proxyPort;
+
+        if ([scheme caseInsensitiveCompare:@"http"] == NSOrderedSame) {
+            proxyHost = proxySettings[(NSString *)kCFNetworkProxiesHTTPProxy];
+            proxyPort = proxySettings[(NSString *)kCFNetworkProxiesHTTPPort];
+        } else if ([scheme caseInsensitiveCompare:@"https"] == NSOrderedSame) {
+            proxyHost = proxySettings[(NSString *)kCFNetworkProxiesHTTPSProxy];
+            proxyPort = proxySettings[(NSString *)kCFNetworkProxiesHTTPSPort];
+        } else if ([scheme caseInsensitiveCompare:@"rtsp"] == NSOrderedSame) {
+            proxyHost = proxySettings[(NSString *)kCFNetworkProxiesRTSPProxy];
+            proxyPort = proxySettings[(NSString *)kCFNetworkProxiesRTSPPort];
+        } else if ([scheme caseInsensitiveCompare:@"ftp"] == NSOrderedSame) {
+            proxyHost = proxySettings[(NSString *)kCFNetworkProxiesFTPProxy];
+            proxyPort = proxySettings[(NSString *)kCFNetworkProxiesFTPPort];
+        } else {
+            return NULL;
+        }
+
+        NSString *returnValue = [[NSString alloc] initWithFormat:@"%@://%@:%i", scheme, proxyHost, proxyPort.intValue];
+        return strdup([returnValue UTF8String]);
+    }
+
+    return NULL;
+}



More information about the vlc-commits mailing list