fix error in getting proxy setting on darwin.
authorKuang Rufan <master@a1983.com.cn>
Sat, 20 Apr 2013 08:37:50 +0000 (16:37 +0800)
committerFelix Paul Kühne <fkuehne@videolan.org>
Sat, 20 Apr 2013 14:01:49 +0000 (16:01 +0200)
1. fix build error for ios.
2. fix vlc_getProxyUrl always return NULL on osx.

Signed-off-by: Felix Paul Kühne <fkuehne@videolan.org>
src/darwin/netconf.c

index 45abf9b..0d9ca43 100644 (file)
 #include <vlc_common.h>
 #include <vlc_network.h>
 
+#import <TargetConditionals.h>
 #include <CoreFoundation/CoreFoundation.h>
+#if TARGET_OS_IPHONE
+#include <CFNetwork/CFProxySupport.h>
+#else
 #include <SystemConfiguration/SystemConfiguration.h>
+#endif
 
 /**
  * Determines the network proxy server to use (if any).
 char *vlc_getProxyUrl(const char *url)
 {
     VLC_UNUSED(url);
+#if TARGET_OS_IPHONE
+    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)) {
+                char buffer[4096];
+                memset(host_buffer, 0, sizeof(host_buffer));
+                sprintf(buffer, "%s:%d", host_buffer, port);
+                proxy_url = strdup(buffer);
+            }
+        }
+
+        CFRelease(dicRef);
+    }
+
+    return proxy_url;
+#else
     CFDictionaryRef proxies = SCDynamicStoreCopyProxies(NULL);
     char *proxy_url = NULL;
 
@@ -77,10 +113,11 @@ char *vlc_getProxyUrl(const char *url)
                                              CFSTR(":%i"),
                                              i_httpProxyPort);
 
-                    CFStringGetCString(outputURL,
-                                       proxy_url,
-                                       sizeof(proxy_url),
-                                       kCFStringEncodingASCII);
+                    char buffer[4096];
+                    if (CFStringGetCString(outputURL, buffer, sizeof(buffer),
+                        kCFStringEncodingUTF8))
+                        proxy_url = strdup(buffer);
+
                     CFRelease(outputURL);
                 }
                 CFRelease(httpProxy);
@@ -90,4 +127,5 @@ char *vlc_getProxyUrl(const char *url)
     }
 
     return proxy_url;
+#endif
 }