Exemple #1
0
        public static CFProxy[] GetProxiesForURL(CFUrl url, CFProxySettings proxySettings)
        {
            if (url == null || url.Handle == IntPtr.Zero)
            {
                throw new ArgumentNullException("url");
            }

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

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

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

            CFProxy[] 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();

            return(proxies);
        }
Exemple #2
0
        public static CFProxy[] GetProxiesForAutoConfigurationScript(IntPtr proxyAutoConfigurationScript, CFUrl targetURL)
        {
            if (proxyAutoConfigurationScript == IntPtr.Zero)
            {
                throw new ArgumentNullException("proxyAutoConfigurationScript");
            }

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

            CFArray array = CopyProxiesForAutoConfigurationScript(proxyAutoConfigurationScript, targetURL);

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

            CFProxy[] 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();

            return(proxies);
        }
Exemple #3
0
		static CFArray CopyProxiesForURL (CFUrl url, CFDictionary proxySettings)
		{
			IntPtr native = CFNetworkCopyProxiesForURL (url.Handle, proxySettings != null ? proxySettings.Handle : IntPtr.Zero);
			
			if (native == IntPtr.Zero)
				return null;
			
			return new CFArray (native, true);
		}
Exemple #4
0
		public static CFProxySettings GetSystemProxySettings ()
		{
			IntPtr native = CFNetworkCopySystemProxySettings ();
			
			if (native == IntPtr.Zero)
				return null;
			
			var dict = new CFDictionary (native, true);

			return new CFProxySettings (dict);
		}
Exemple #5
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);
        }
Exemple #6
0
		public static CFProxySettings GetSystemProxySettings ()
		{
			IntPtr native = CFNetworkCopySystemProxySettings ();
			
			if (native == IntPtr.Zero)
				return null;
			
			var dict = new CFDictionary (native, true);

			return new CFProxySettings (dict);
		}
Exemple #7
0
		public static CFProxy[] GetProxiesForURL (CFUrl url, CFProxySettings proxySettings)
		{
			if (url == null || url.Handle == IntPtr.Zero)
				throw new ArgumentNullException ("url");
			
			if (proxySettings == null)
				proxySettings = GetSystemProxySettings ();
			
			CFArray array = CopyProxiesForURL (url, proxySettings.Dictionary);
			
			if (array == null)
				return null;

			CFProxy[] 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 ();
			
			return proxies;
		}
Exemple #8
0
		static CFArray CopyProxiesForURL (CFUrl url, CFDictionary proxySettings)
		{
			IntPtr native = CFNetworkCopyProxiesForURL (url.Handle, proxySettings != null ? proxySettings.Handle : IntPtr.Zero);
			
			if (native == IntPtr.Zero)
				return null;
			
			return new CFArray (native, true);
		}
Exemple #9
0
		public static CFProxy[] GetProxiesForAutoConfigurationScript (IntPtr proxyAutoConfigurationScript, CFUrl targetURL)
		{
			if (proxyAutoConfigurationScript == IntPtr.Zero)
				throw new ArgumentNullException ("proxyAutoConfigurationScript");
			
			if (targetURL == null)
				throw new ArgumentNullException ("targetURL");
			
			CFArray array = CopyProxiesForAutoConfigurationScript (proxyAutoConfigurationScript, targetURL);
			
			if (array == null)
				return null;
			
			CFProxy[] 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 ();
			
			return proxies;
		}
Exemple #10
0
		public CFProxySettings (CFDictionary settings)
		{
			this.settings = settings;
		}
Exemple #11
0
		internal CFProxy (CFDictionary settings)
		{
			this.settings = settings;
		}
Exemple #12
0
 public CFProxySettings(CFDictionary settings)
 {
     this.settings = settings;
 }
Exemple #13
0
 internal CFProxy(CFDictionary settings)
 {
     this.settings = settings;
 }
Exemple #14
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;
		}