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

Felix Paul Kühne fkuehne at videolan.org
Wed Sep 12 00:22:34 CEST 2018


From: Felix Paul Kühne <felix at feepk.net>

---
 NEWS                 |  2 ++
 src/Makefile.am      | 11 ++++--
 src/darwin/netconf.c | 73 ----------------------------------------
 src/darwin/netconf.m | 79 ++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 90 insertions(+), 75 deletions(-)
 delete mode 100644 src/darwin/netconf.c
 create mode 100644 src/darwin/netconf.m

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..c81339f961 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -420,9 +420,12 @@ if HAVE_DARWIN
 libvlccore_la_SOURCES += \
 	darwin/dirs.c \
 	darwin/error.c \
-	darwin/netconf.c \
 	darwin/specific.c \
 	darwin/thread.c
+
+libvlccore_objc_la_SOURCES = \
+	darwin/netconf.m
+noinst_LTLIBRARIES = libvlccore_objc.la
 else
 libvlccore_la_SOURCES += \
 	posix/dirs.c \
@@ -486,7 +489,11 @@ if HAVE_DBUS
 libvlccore_la_LIBADD += $(DBUS_LIBS)
 endif
 if HAVE_DARWIN
-libvlccore_la_LDFLAGS += -Xlinker -install_name -Xlinker @rpath/libvlccore.dylib
+$(libvlccore_la_OBJECTS): libvlccore_objc.la
+libvlccore_objc_la_OBJCFLAGS = $(AM_OBJCFLAGS) -fobjc-arc
+libvlccore_objc_la_LDFLAGS = -static
+libvlccore_la_LIBADD += libvlccore_objc.la
+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;
+}
-- 
2.18.0



More information about the vlc-devel mailing list