Esempio n. 1
0
        public static CFProxy[] GetProxiesForURL(NSUrl url, CFProxySettings proxySettings)
        {
            if (url == null)
            {
                throw new ArgumentNullException("url");
            }

            if (proxySettings == null)
            {
                proxySettings = GetSystemProxySettings();
            }

            NSArray array = CopyProxiesForURL(url, proxySettings.Dictionary);

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

            NSDictionary[] dictionaries = NSArray.ArrayFromHandle <NSDictionary> (array.Handle);
            array.Dispose();

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

            CFProxy[] proxies = new CFProxy [dictionaries.Length];
            for (int i = 0; i < dictionaries.Length; i++)
            {
                proxies[i] = new CFProxy(dictionaries[i]);
            }

            return(proxies);
        }
            public Uri GetProxy(Uri targetUri)
            {
                if (targetUri == null)
                {
                    throw new ArgumentNullException("targetUri");
                }

                try
                {
                    CFProxySettings settings = CFNetwork.GetSystemProxySettings();
                    CFProxy[]       proxies  = CFNetwork.GetProxiesForUri(targetUri, settings);
                    Uri             uri;

                    if (proxies == null)
                    {
                        return(targetUri);
                    }

                    for (int i = 0; i < proxies.Length; i++)
                    {
                        switch (proxies[i].ProxyType)
                        {
                        case CFProxyType.AutoConfigurationJavaScript:
                            if ((uri = GetProxyUriFromScript(proxies[i].AutoConfigurationJavaScript, targetUri)) != null)
                            {
                                return(uri);
                            }
                            break;

                        case CFProxyType.AutoConfigurationUrl:
                            // unsupported proxy type (requires fetching script from remote url)
                            break;

                        case CFProxyType.HTTPS:
                        case CFProxyType.HTTP:
                        case CFProxyType.FTP:
                            // create a Uri based on the hostname/port/etc info
                            return(GetProxyUri(proxies[i]));

                        case CFProxyType.SOCKS:
                            // unsupported proxy type, try the next one
                            break;

                        case CFProxyType.None:
                            // no proxy should be used
                            return(targetUri);
                        }
                    }
                }
                catch
                {
                    // ignore errors while retrieving proxy data
                }
                // no supported proxies for this Uri, fall back to trying to connect to targetUri directly.
                return(targetUri);
            }
Esempio n. 3
0
        public static CFProxy[] GetProxiesForUri(Uri uri, CFProxySettings proxySettings)
        {
            if (uri == null)
            {
                throw new ArgumentNullException("uri");
            }

            NSUrl url = new NSUrl(uri.AbsoluteUri);

            CFProxy[] proxies = GetProxiesForURL(url, proxySettings);
            url.Dispose();

            return(proxies);
        }
Esempio n. 4
0
            public Uri GetProxy(Uri targetUri)
            {
                NetworkCredential credentials = null;
                Uri proxy = null;

                if (targetUri == null)
                {
                    throw new ArgumentNullException("targetUri");
                }

                try {
                    CFProxySettings settings = CFNetwork.GetSystemProxySettings();
                    CFProxy[]       proxies  = CFNetwork.GetProxiesForUri(targetUri, settings);

                    if (proxies != null)
                    {
                        for (int i = 0; i < proxies.Length && proxy == null; i++)
                        {
                            switch (proxies[i].ProxyType)
                            {
                            case CFProxyType.AutoConfigurationJavaScript:
                                proxy = GetProxyUriFromScript(proxies[i].AutoConfigurationJavaScript, targetUri, out credentials);
                                break;

                            case CFProxyType.AutoConfigurationUrl:
                                // unsupported proxy type (requires fetching script from remote url)
                                break;

                            case CFProxyType.HTTPS:
                            case CFProxyType.HTTP:
                            case CFProxyType.FTP:
                                // create a Uri based on the hostname/port/etc info
                                proxy = GetProxyUri(proxies[i], out credentials);
                                break;

                            case CFProxyType.SOCKS:
                                // unsupported proxy type, try the next one
                                break;

                            case CFProxyType.None:
                                // no proxy should be used
                                proxy = targetUri;
                                break;
                            }
                        }

                        if (proxy == null)
                        {
                            // no supported proxies for this Uri, fall back to trying to connect to targetUri directly
                            proxy = targetUri;
                        }
                    }
                    else
                    {
                        proxy = targetUri;
                    }
                } catch {
                    // ignore errors while retrieving proxy data
                    proxy = targetUri;
                }

                if (!userSpecified)
                {
                    this.credentials = credentials;
                }

                return(proxy);
            }