]> git.sesse.net Git - vlc/blobdiff - src/darwin/netconf.c
clock: use msg_Err()
[vlc] / src / darwin / netconf.c
index ebda7da50e5eb177857cc4d588a8efd3c10e5324..d5f66664a49eda91640cdf2c829739bd493e8d83 100644 (file)
 #include <vlc_network.h>
 
 #include <CoreFoundation/CoreFoundation.h>
-#include <SystemConfiguration/SystemConfiguration.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).
 char *vlc_getProxyUrl(const char *url)
 {
     VLC_UNUSED(url);
-    CFDictionaryRef proxies = SCDynamicStoreCopyProxies(NULL);
     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 (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);
+            char host_buffer[4096];
+            memset(host_buffer, 0, sizeof(host_buffer));
+            if (CFStringGetCString(proxyCFstr, host_buffer, sizeof(host_buffer)
+                                   - 1, kCFStringEncodingUTF8)) {
+                char buffer[4096];
+                sprintf(buffer, "%s:%d", host_buffer, port);
+                proxy_url = strdup(buffer);
             }
-            CFRelease(httpProxy);
         }
-        CFRelease(proxies);
+
+        CFRelease(dicRef);
     }
 
     return proxy_url;