Esempio n. 1
0
        public static CFUrl Create(string absolute)
        {
            if (string.IsNullOrEmpty(absolute))
            {
                return(null);
            }

            CFString str    = CFString.Create(absolute);
            IntPtr   handle = CFURLCreateWithString(IntPtr.Zero, str.Handle, IntPtr.Zero);

            str.Dispose();

            if (handle == IntPtr.Zero)
            {
                return(null);
            }

            return(new CFUrl(handle, true));
        }
Esempio n. 2
0
        public static CFProxy[] ExecuteProxyAutoConfigurationURL(IntPtr proxyAutoConfigURL, Uri targetURL)
        {
            CFUrl url = CFUrl.Create(targetURL.AbsoluteUri);

            if (url == null)
            {
                return(null);
            }

            CFProxy[] proxies = null;

            var runLoop = CFRunLoop.CurrentRunLoop;

            // Callback that will be called after executing the configuration script
            CFProxyAutoConfigurationResultCallback cb = delegate(IntPtr client, IntPtr proxyList, IntPtr error) {
                if (proxyList != IntPtr.Zero)
                {
                    var array = new CFArray(proxyList, false);
                    proxies = new CFProxy [array.Count];
                    for (int i = 0; i < proxies.Length; i++)
                    {
                        CFDictionary dict = new CFDictionary(array[i], false);
                        proxies[i] = new CFProxy(dict);
                    }
                    array.Dispose();
                }
                runLoop.Stop();
            };

            var clientContext = new CFStreamClientContext();
            var loopSource    = CFNetworkExecuteProxyAutoConfigurationURL(proxyAutoConfigURL, url.Handle, cb, ref clientContext);

            // Create a private mode
            var mode = CFString.Create("Mono.MacProxy");

            runLoop.AddSource(loopSource, mode);
            runLoop.RunInMode(mode, double.MaxValue, false);
            runLoop.RemoveSource(loopSource, mode);

            return(proxies);
        }
Esempio n. 3
0
 public int RunInMode(CFString mode, double seconds, bool returnAfterSourceHandled)
 {
     return(CFRunLoopRunInMode(mode.Handle, seconds, returnAfterSourceHandled));
 }
Esempio n. 4
0
 public void RemoveSource(IntPtr source, CFString mode)
 {
     CFRunLoopRemoveSource(Handle, source, mode.Handle);
 }
Esempio n. 5
0
 public void AddSource(IntPtr source, CFString mode)
 {
     CFRunLoopAddSource(Handle, source, mode.Handle);
 }
Esempio n. 6
0
        static CFProxyType CFProxyTypeToEnum(IntPtr type)
        {
            if (type == kCFProxyTypeAutoConfigurationJavaScript)
            {
                return(CFProxyType.AutoConfigurationJavaScript);
            }

            if (type == kCFProxyTypeAutoConfigurationURL)
            {
                return(CFProxyType.AutoConfigurationUrl);
            }

            if (type == kCFProxyTypeFTP)
            {
                return(CFProxyType.FTP);
            }

            if (type == kCFProxyTypeHTTP)
            {
                return(CFProxyType.HTTP);
            }

            if (type == kCFProxyTypeHTTPS)
            {
                return(CFProxyType.HTTPS);
            }

            if (type == kCFProxyTypeSOCKS)
            {
                return(CFProxyType.SOCKS);
            }

            //in OSX 10.13 pointer comparison didn't work for kCFProxyTypeAutoConfigurationURL
            if (CFString.Compare(type, kCFProxyTypeAutoConfigurationJavaScript) == 0)
            {
                return(CFProxyType.AutoConfigurationJavaScript);
            }

            if (CFString.Compare(type, kCFProxyTypeAutoConfigurationURL) == 0)
            {
                return(CFProxyType.AutoConfigurationUrl);
            }

            if (CFString.Compare(type, kCFProxyTypeFTP) == 0)
            {
                return(CFProxyType.FTP);
            }

            if (CFString.Compare(type, kCFProxyTypeHTTP) == 0)
            {
                return(CFProxyType.HTTP);
            }

            if (CFString.Compare(type, kCFProxyTypeHTTPS) == 0)
            {
                return(CFProxyType.HTTPS);
            }

            if (CFString.Compare(type, kCFProxyTypeSOCKS) == 0)
            {
                return(CFProxyType.SOCKS);
            }

            return(CFProxyType.None);
        }