2008-10-31 Gonzalo Paniagua Javier <gonzalo@novell.com>
[mono.git] / mcs / class / System / System.Net / WebProxy.cs
index 6d49a01c00987556daf9a7de5a7f3cb8417ae5c6..38ff3eb650a150d9f25899177c8e57319c195d7b 100644 (file)
@@ -36,11 +36,15 @@ using System.Text.RegularExpressions;
 namespace System.Net 
 {
        [Serializable]
-       public class WebProxy : IWebProxy, ISerializable {
+       public class WebProxy : IWebProxy, ISerializable
+       {
                Uri address;
                bool bypassOnLocal;
                ArrayList bypassList;
                ICredentials credentials;
+#if NET_2_0
+               bool useDefaultCredentials;
+#endif
 
                // Constructors
 
@@ -77,18 +81,20 @@ namespace System.Net
                {
                        this.address = address;
                        this.bypassOnLocal = bypassOnLocal;
-                       if (bypassList == null)
-                               bypassList = new string [] {};
-                       this.bypassList = new ArrayList (bypassList);
+                       if (bypassList != null)
+                               this.bypassList = new ArrayList (bypassList);
                        this.credentials = credentials;
                        CheckBypassList ();
                }
 
                protected WebProxy (SerializationInfo serializationInfo, StreamingContext streamingContext) 
                {
-                       this.address = (Uri) serializationInfo.GetValue ("address", typeof (Uri));
-                       this.bypassOnLocal = serializationInfo.GetBoolean ("bypassOnLocal");
-                       this.bypassList = (ArrayList) serializationInfo.GetValue ("bypassList", typeof (ArrayList));
+                       this.address = (Uri) serializationInfo.GetValue ("_ProxyAddress", typeof (Uri));
+                       this.bypassOnLocal = serializationInfo.GetBoolean ("_BypassOnLocal");
+                       this.bypassList = (ArrayList) serializationInfo.GetValue ("_BypassList", typeof (ArrayList));
+#if NET_2_0
+                       this.useDefaultCredentials =  serializationInfo.GetBoolean ("_UseDefaultCredentials");
+#endif
                        this.credentials = null;
                        CheckBypassList ();
                }
@@ -100,11 +106,15 @@ namespace System.Net
                }
 
                public ArrayList BypassArrayList {
-                       get { return bypassList; }
+                       get {
+                               if (bypassList == null)
+                                       bypassList = new ArrayList ();
+                               return bypassList;
+                       }
                }
 
                public string [] BypassList {
-                       get { return (string []) bypassList.ToArray (typeof (string)); }
+                       get { return (string []) BypassArrayList.ToArray (typeof (string)); }
                        set { 
                                if (value == null)
                                        throw new ArgumentNullException ();
@@ -123,7 +133,18 @@ namespace System.Net
                        set { credentials = value; }
                }
 
+#if NET_2_0
+               [MonoTODO ("Does not affect Credentials, since CredentialCache.DefaultCredentials is not implemented.")]
+               public bool UseDefaultCredentials {
+                       get { return useDefaultCredentials; }
+                       set { useDefaultCredentials = value; }
+               }
+#endif
+
                // Methods
+#if NET_2_0
+               [Obsolete ("This method has been deprecated", false)]
+#endif
                [MonoTODO("Can we get this info under windows from the system?")]
                public static WebProxy GetDefaultProxy ()
                {
@@ -145,10 +166,15 @@ namespace System.Net
 
                public bool IsBypassed (Uri host)
                {
-                       if (address == null)
+#if NET_2_0
+                       if (host == null)
+                               throw new ArgumentNullException ("host");
+#endif
+
+                       if (host.IsLoopback && bypassOnLocal)
                                return true;
 
-                       if (bypassOnLocal && host.IsLoopback)
+                       if (address == null)
                                return true;
 
                        string server = host.Host;
@@ -169,8 +195,11 @@ namespace System.Net
                                } catch {}
                        }
 
-                       try {                           
-                               string hostStr = host.Scheme + "://" + host.Authority;                          
+                       if (bypassList == null)
+                               return false;
+
+                       try {
+                               string hostStr = host.Scheme + "://" + host.Authority;
                                int i = 0;
                                for (; i < bypassList.Count; i++) {
                                        Regex regex = new Regex ((string) bypassList [i], 
@@ -196,19 +225,32 @@ namespace System.Net
                        }
                }
 
+#if NET_2_0
+               protected virtual 
+#endif
+               void GetObjectData (SerializationInfo serializationInfo, StreamingContext streamingContext)
+               {
+                       serializationInfo.AddValue ("_BypassOnLocal", bypassOnLocal);
+                       serializationInfo.AddValue ("_ProxyAddress", address);
+                       serializationInfo.AddValue ("_BypassList", bypassList);
+#if NET_2_0
+                       serializationInfo.AddValue ("_UseDefaultCredentials", UseDefaultCredentials);
+#endif
+               }
+
                void ISerializable.GetObjectData (SerializationInfo serializationInfo,
                                                  StreamingContext streamingContext)
                {
-                       serializationInfo.AddValue ("bypassOnLocal", bypassOnLocal);
-                       serializationInfo.AddValue ("address", address);
-                       serializationInfo.AddValue ("bypassList", bypassList);
+                       GetObjectData (serializationInfo, streamingContext);
                }
 
                // Private Methods
                // this compiles the regular expressions, and will throw
                // an exception when an invalid one is found.
                void CheckBypassList ()
-               {                       
+               {
+                       if (bypassList == null)
+                               return;
                        for (int i = 0; i < bypassList.Count; i++)
                                new Regex ((string) bypassList [i]);
                }
@@ -225,4 +267,3 @@ namespace System.Net
                }
        }
 }
-