2008-11-04 Gonzalo Paniagua Javier <gonzalo@novell.com>
[mono.git] / mcs / class / System / System.Net / ServicePointManager.cs
index 7db019a9a76351d264df94b1ebe696f27df44efc..bea42e48cc30dfc838ff743830182e460c2e373c 100644 (file)
@@ -33,6 +33,10 @@ using System.Configuration;
 using System.Net.Configuration;
 using System.Security.Cryptography.X509Certificates;
 
+#if NET_2_0
+using System.Net.Security;
+#endif
+
 //
 // notes:
 // A service point manager manages service points (duh!).
@@ -55,6 +59,37 @@ namespace System.Net
 {
        public class ServicePointManager
        {
+               class SPKey {
+                       Uri uri; // schema/host/port
+                       bool use_connect;
+
+                       public SPKey (Uri uri, bool use_connect) {
+                               this.uri = uri;
+                               this.use_connect = use_connect;
+                       }
+
+                       public Uri Uri {
+                               get { return uri; }
+                       }
+
+                       public bool UseConnect {
+                               get { return use_connect; }
+                       }
+
+                       public override int GetHashCode () {
+                               return uri.GetHashCode () + ((use_connect) ? 1 : 0);
+                       }
+
+                       public override bool Equals (object obj) {
+                               SPKey other = obj as SPKey;
+                               if (obj == null) {
+                                       return false;
+                               }
+
+                               return (uri.Equals (other.uri) && other.use_connect == use_connect);
+                       }
+               }
+
                private static HybridDictionary servicePoints = new HybridDictionary ();
                
                // Static properties
@@ -64,13 +99,14 @@ namespace System.Net
                private static int maxServicePointIdleTime = 900000; // 15 minutes
                private static int maxServicePoints = 0;
                private static bool _checkCRL = false;
-#if (NET_1_0 || NET_1_1)
-               private static SecurityProtocolType _securityProtocol = SecurityProtocolType.Ssl3;
-#else
-               private static SecurityProtocolType _securityProtocol = SecurityProtocolType.Default;
-#endif
+               private static SecurityProtocolType _securityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls;
+
 #if NET_1_1
+#if TARGET_JVM
+               static bool expectContinue = false;
+#else
                static bool expectContinue = true;
+#endif
                static bool useNagle;
 #endif
 
@@ -92,10 +128,14 @@ namespace System.Net
                                foreach (ConnectionManagementElement e in s.ConnectionManagement)
                                        manager.Add (e.Address, e.MaxConnection);
 
+                               defaultConnectionLimit = (int) manager.GetMaxConnections ("*");                         
                                return;
                        }
 #endif
                        manager = (ConnectionManagementData) ConfigurationSettings.GetConfig (configKey);
+                       if (manager != null) {
+                               defaultConnectionLimit = (int) manager.GetMaxConnections ("*");                         
+                       }
                }
 
                // Constructors
@@ -105,6 +145,10 @@ namespace System.Net
                
                // Properties
                
+#if NET_2_0
+               [Obsolete ("Use ServerCertificateValidationCallback instead",
+                          false)]
+#endif
                public static ICertificatePolicy CertificatePolicy {
                        get { return policy; }
                        set { policy = value; }
@@ -131,6 +175,35 @@ namespace System.Net
                                defaultConnectionLimit = value; 
                        }
                }
+
+#if NET_2_0
+               static Exception GetMustImplement ()
+               {
+                       return new NotImplementedException ();
+               }
+               
+               [MonoTODO]
+               public static int DnsRefreshTimeout
+               {
+                       get {
+                               throw GetMustImplement ();
+                       }
+                       set {
+                               throw GetMustImplement ();
+                       }
+               }
+               
+               [MonoTODO]
+               public static bool EnableDnsRoundRobin
+               {
+                       get {
+                               throw GetMustImplement ();
+                       }
+                       set {
+                               throw GetMustImplement ();
+                       }
+               }
+#endif
                
                public static int MaxServicePointIdleTime {
                        get { 
@@ -167,6 +240,19 @@ namespace System.Net
                        set { _securityProtocol = value; }
                }
 
+#if NET_2_0 && SECURITY_DEP
+               [MonoTODO]
+               public static RemoteCertificateValidationCallback ServerCertificateValidationCallback
+               {
+                       get {
+                               throw GetMustImplement ();
+                       }
+                       set {
+                               throw GetMustImplement ();
+                       }
+               }
+#endif
+
 #if NET_1_1
                public static bool Expect100Continue {
                        get { return expectContinue; }
@@ -189,7 +275,7 @@ namespace System.Net
                {
                        return FindServicePoint (new Uri(uriString), proxy);
                }
-               
+
                public static ServicePoint FindServicePoint (Uri address, IWebProxy proxy)
                {
                        if (address == null)
@@ -214,7 +300,7 @@ namespace System.Net
                        
                        ServicePoint sp = null;
                        lock (servicePoints) {
-                               int key = address.GetHashCode () + (int) ((useConnect) ? 1 : 0);
+                               SPKey key = new SPKey (address, useConnect);
                                sp = servicePoints [key] as ServicePoint;
                                if (sp != null)
                                        return sp;
@@ -264,7 +350,7 @@ namespace System.Net
                                        ServicePoint sp = (ServicePoint) e.Value;
                                        if (sp.CurrentConnections == 0) {
                                                while (list.ContainsKey (sp.IdleSince))
-                                                       sp.IdleSince.AddMilliseconds (1);
+                                                       sp.IdleSince = sp.IdleSince.AddMilliseconds (1);
                                                list.Add (sp.IdleSince, sp.Address);
                                        }
                                }