Commit bed03b5d authored by Felix Paul Kühne's avatar Felix Paul Kühne

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

parent cbe42e44
......@@ -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:
......
......@@ -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
......
/*****************************************************************************
* netconf.c : Network configuration
* netconf.m : Network configuration
*****************************************************************************
* Copyright (C) 2013 VLC authors and VideoLAN
* Copyright (C) 2013-2018 VLC authors and VideoLAN
* $Id$
*
* Authors: Felix Paul Kühne <fkuehne # videolan org>
......@@ -28,7 +28,7 @@
#include <vlc_common.h>
#include <vlc_network.h>
#include <CoreFoundation/CoreFoundation.h>
#import <Foundation/Foundation.h>
#import <TargetConditionals.h>
#if TARGET_OS_IPHONE
......@@ -39,35 +39,41 @@
/**
* Determines the network proxy server to use (if any).
* @param url absolute URL for which to get the proxy server (not used)
* @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)
{
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;
}
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;
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);
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;
}
CFRelease(dicRef);
NSString *returnValue = [[NSString alloc] initWithFormat:@"%@://%@:%i", scheme, proxyHost, proxyPort.intValue];
return strdup([returnValue UTF8String]);
}
return proxy_url;
return NULL;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment