dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dotgnu-pnet-commits] CVS: pnetlib/System/Net CookieCollection.cs, NONE,


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnetlib/System/Net CookieCollection.cs, NONE, 1.1 CookieContainer.cs, NONE, 1.1 CookieException.cs, NONE, 1.1 EndpointPermission.cs, NONE, 1.1 ProtocolViolationException.cs, NONE, 1.1 ServicePointManager.cs, NONE, 1.1 WebPermission.cs, NONE, 1.1 WebPermissionAttribute.cs, NONE, 1.1 Cookie.cs, 1.2, 1.3 Dns.cs, 1.4, 1.5 SocketPermission.cs, 1.3, 1.4
Date: Wed, 17 Sep 2003 21:43:55 -0400

Update of /cvsroot/dotgnu-pnet/pnetlib/System/Net
In directory subversions:/tmp/cvs-serv30662/System/Net

Modified Files:
        Cookie.cs Dns.cs SocketPermission.cs 
Added Files:
        CookieCollection.cs CookieContainer.cs CookieException.cs 
        EndpointPermission.cs ProtocolViolationException.cs 
        ServicePointManager.cs WebPermission.cs 
        WebPermissionAttribute.cs 
Log Message:


Missing functionality in the "System.Net" namespace.


--- NEW FILE ---
/*
 * CookieCollection.cs - Implementation of the
 *                      "System.Net.CookieCollection" class.
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

namespace System.Net
{

#if !ECMA_COMPAT

using System.Collections;
using System.Globalization;

[Serializable]
public class CookieCollection : ICollection, IEnumerable
{
        // Internal state.
        private ArrayList list;

        // Constructor.
        public CookieCollection()
                        {
                                list = new ArrayList();
                        }

        // Determine if this collection is read-only.
        public bool IsReadOnly
                        {
                                get
                                {
                                        return true;
                                }
                        }

        // Get a specific item from this cookie collection.
        public Cookie this[int index]
                        {
                                get
                                {
                                        return (Cookie)(list[index]);
                                }
                        }
        public Cookie this[String name]
                        {
                                get
                                {
                                        if(name == null)
                                        {
                                                throw new 
ArgumentNullException("name");
                                        }
                                        foreach(Cookie cookie in list)
                                        {
                                                if(String.Compare(cookie.Name, 
name, true,
                                                                                
  CultureInfo.InvariantCulture) == 0)
                                                {
                                                        return cookie;
                                                }
                                        }
                                        return null;
                                }
                        }

        // Implement the ICollection interface.
        public void CopyTo(Array array, int index)
                        {
                                list.CopyTo(array, index);
                        }
        public int Count
                        {
                                get
                                {
                                        return list.Count;
                                }
                        }
        public bool IsSynchronized
                        {
                                get
                                {
                                        return false;
                                }
                        }
        public Object SyncRoot
                        {
                                get
                                {
                                        return this;
                                }
                        }

        // Implement the IEnumerable interface.
        public IEnumerator GetEnumerator()
                        {
                                return list.GetEnumerator();
                        }

        // Add a cookie to this collection.
        public void Add(Cookie cookie)
                        {
                                if(cookie == null)
                                {
                                        throw new 
ArgumentNullException("cookie");
                                }
                                int index = list.IndexOf(cookie);
                                if(index != -1)
                                {
                                        // Replace an the existing cookie with 
the same
                                        // name with a new cookie.
                                        list[index] = cookie;
                                }
                                else
                                {
                                        list.Add(cookie);
                                }
                        }

        // Add the contents of another cookie collection to this one.
        public void Add(CookieCollection cookies)
                        {
                                if(cookies == null)
                                {
                                        throw new 
ArgumentNullException("cookies");
                                }
                                foreach(Cookie cookie in cookies)
                                {
                                        Add(cookie);
                                }
                        }

}; // class CookieCollection

#endif // !ECMA_COMPAT

}; // namespace System.Net

--- NEW FILE ---
/*
 * CookieContainer.cs - Implementation of the
 *                      "System.Net.CookieContainer" class.
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

namespace System.Net
{

#if !ECMA_COMPAT

using System.Collections;
using System.Globalization;

[Serializable]
public class CookieContainer
{
        // Internal state.
        private int capacity;
        private int perDomainCapacity;
        private int maxCookieSize;
        private int count;

        // Default values.
        public const int DefaultCookieLengthLimit               = 4096;
        public const int DefaultCookieLimit                             = 300;
        public const int DefaultPerDomainCookieLimit    = 20;

        // Constructors.
        public CookieContainer()
                        : this(DefaultCookieLimit, DefaultPerDomainCookieLimit,
                                   DefaultCookieLengthLimit) {}
        public CookieContainer(int capacity)
                        : this(capacity, DefaultPerDomainCookieLimit,
                                   DefaultCookieLengthLimit) {}
        public CookieContainer(int capacity, int perDomainCapacity,
                                                   int maxCookieSize)
                        {
                                if(capacity <= 0 ||
                                   (perDomainCapacity != Int32.MaxValue &&
                                    capacity < perDomainCapacity))
                                {
                                        throw new ArgumentException
                                                (S._("Arg_CookieCapacity"), 
"capacity");
                                }
                                if(perDomainCapacity <= 0)
                                {
                                        throw new ArgumentException
                                                
(S._("ArgRange_PositiveNonZero"),
                                                 "perDomainCapacity");
                                }
                                if(maxCookieSize <= 0)
                                {
                                        throw new ArgumentException
                                                
(S._("ArgRange_PositiveNonZero"),
                                                 "maxCookieSize");
                                }
                                this.capacity = capacity;
                                this.perDomainCapacity = perDomainCapacity;
                                this.maxCookieSize = maxCookieSize;
                                this.count = 0;
                        }

        // Get or set this object's properties.
        public int Capacity
                        {
                                get
                                {
                                        return capacity;
                                }
                                set
                                {
                                        if(value <= 0 ||
                                           (perDomainCapacity != Int32.MaxValue 
&&
                                            value < perDomainCapacity))
                                        {
                                                throw new 
ArgumentOutOfRangeException
                                                        
(S._("Arg_CookieCapacity"));
                                        }
                                        capacity = value;
                                }
                        }
        public int Count
                        {
                                get
                                {
                                        return count;
                                }
                        }
        public int MaxCookieSize
                        {
                                get
                                {
                                        return maxCookieSize;
                                }
                                set
                                {
                                        if(value <= 0)
                                        {
                                                throw new ArgumentException
                                                        ("value", 
S._("ArgRange_PositiveNonZero"));
                                        }
                                        maxCookieSize = value;
                                }
                        }
        public int PerDomainCapacity
                        {
                                get
                                {
                                        return perDomainCapacity;
                                }
                                set
                                {
                                        if(value <= 0 ||
                                           (value != Int32.MaxValue && capacity 
< value))
                                        {
                                                throw new 
ArgumentOutOfRangeException
                                                        
(S._("Arg_CookieCapacity"));
                                        }
                                        perDomainCapacity = value;
                                }
                        }

        // Add a cookie to this container.
        [TODO]
        public void Add(Cookie cookie)
                        {
                                if(cookie == null)
                                {
                                        throw new 
ArgumentNullException("cookie");
                                }
                                // TODO
                        }
        [TODO]
        public void Add(Uri uri, Cookie cookie)
                        {
                                if(uri == null)
                                {
                                        throw new ArgumentNullException("uri");
                                }
                                if(cookie == null)
                                {
                                        throw new 
ArgumentNullException("cookie");
                                }
                                // TODO
                        }

        // Add a collection of cookies to this container.
        public void Add(CookieCollection cookies)
                        {
                                if(cookies == null)
                                {
                                        throw new 
ArgumentNullException("cookies");
                                }
                                foreach(Cookie cookie in cookies)
                                {
                                        Add(cookie);
                                }
                        }
        public void Add(Uri uri, CookieCollection cookies)
                        {
                                if(uri == null)
                                {
                                        throw new ArgumentNullException("uri");
                                }
                                if(cookies == null)
                                {
                                        throw new 
ArgumentNullException("cookies");
                                }
                                foreach(Cookie cookie in cookies)
                                {
                                        Add(uri, cookie);
                                }
                        }

        // Get a HTTP cookie header for a particular URI.
        [TODO]
        public String GetCookieHeader(Uri uri)
                        {
                                if(uri == null)
                                {
                                        throw new ArgumentNullException("uri");
                                }
                                // TODO
                                return null;
                        }

        // Get the cookies for a specific URI.
        [TODO]
        public CookieCollection GetCookies(Uri uri)
                        {
                                if(uri == null)
                                {
                                        throw new ArgumentNullException("uri");
                                }
                                // TODO
                                return null;
                        }

        // Set the cookies for a specific URI.
        [TODO]
        public void SetCookies(Uri uri, String cookieHeader)
                        {
                                if(uri == null)
                                {
                                        throw new ArgumentNullException("uri");
                                }
                                if(cookieHeader == null)
                                {
                                        throw new 
ArgumentNullException("cookieHeader");
                                }
                                // TODO
                        }

}; // class CookieContainer

#endif // !ECMA_COMPAT

}; // namespace System.Net

--- NEW FILE ---
/*
 * CookieException.cs - Implementation of the
 *                      "System.Net.CookieException" class.
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

namespace System.Net
{

#if !ECMA_COMPAT

using System.Runtime.Serialization;

[Serializable]
public class CookieException : FormatException
{
        // Constructors.
        public CookieException()
                : base(S._("Exception_Cookie")) {}
        internal CookieException(String msg)
                : base(msg) {}
        internal CookieException(String msg, Exception inner)
                : base(msg, inner) {}
#if CONFIG_SERIALIZATION
        protected CookieException(SerializationInfo info, StreamingContext 
context)
                : base(info, context) {}
#endif

}; // class CookieException

#endif // !ECMA_COMPAT

}; // namespace System.Net

--- NEW FILE ---
/*
 * EndpointPermission.cs - Implementation of the
 *                      "System.Net.EndpointPermission" class.
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

namespace System.Net
{

#if CONFIG_PERMISSIONS

using System.Globalization;

#if ECMA_COMPAT
internal
#else
public
#endif
class EndpointPermission
{
        // Accessible internal state.
        internal NetworkAccess access;
        internal TransportType transport;
        internal String hostName;
        internal int portNumber;

        // Constructor.
        internal EndpointPermission(NetworkAccess access,
                                                                TransportType 
transport,
                                                                String hostName,
                                                                int portNumber)
                        {
                                this.access = access;
                                this.transport = transport;
                                this.hostName = hostName;
                                this.portNumber = portNumber;
                        }

        // Get the endpoint information.
        public TransportType Transport
                        {
                                get
                                {
                                        return transport;
                                }
                        }
        public String Hostname
                        {
                                get
                                {
                                        return hostName;
                                }
                        }
        public int Port
                        {
                                get
                                {
                                        return portNumber;
                                }
                        }

        // Determine if two endpoints are equal (ignoring access).
        public override bool Equals(Object obj)
                        {
                                EndpointPermission info = (obj as 
EndpointPermission);
                                if(info != null)
                                {
                                        if(transport != info.transport)
                                        {
                                                return false;
                                        }
                                        if(portNumber != info.portNumber)
                                        {
                                                return false;
                                        }
                                        return (String.Compare(hostName, 
info.hostName, true,
                                                                                
   CultureInfo.InvariantCulture) == 0);
                                }
                                else
                                {
                                        return false;
                                }
                        }

        // Get the hash code for this object.
        public override int GetHashCode()
                        {
                                return ToString().GetHashCode();
                        }

        // Convert this object into a string.
        public override String ToString()
                        {
                                return hostName + "#" + portNumber.ToString() + 
"#" +
                                           ((int)transport).ToString();
                        }

}; // class EndpointPermission

#endif // CONFIG_PERMISSIONS

}; // namespace System.Net

--- NEW FILE ---
/*
 * ProtocolViolationException.cs - Implementation of the
 *                      "System.Net.ProtocolViolationException" class.
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

namespace System.Net
{

#if !ECMA_COMPAT

using System.Runtime.Serialization;

[Serializable]
public class ProtocolViolationException : InvalidOperationException
#if CONFIG_SERIALIZATION
        , ISerializable
#endif
{
        // Constructors.
        public ProtocolViolationException()
                : base(S._("Exception_Protocol")) {}
        public ProtocolViolationException(String msg)
                : base(msg) {}
        internal ProtocolViolationException(String msg, Exception inner)
                : base(msg, inner) {}
#if CONFIG_SERIALIZATION
        protected ProtocolViolationException
                        (SerializationInfo info, StreamingContext context)
                : base(info, context) {}

        // Get the serializable data for this object.
        void ISerializable.GetObjectData
                        (SerializationInfo info, StreamingContext context)
                {
                        GetObjectData(info, context);
                }
#endif

}; // class ProtocolViolationException

#endif // !ECMA_COMPAT

}; // namespace System.Net

--- NEW FILE ---
/*
 * ServicePointManager.cs - Implementation of the
 *                      "System.Net.ServicePointManager" class.
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
 
namespace System.Net
{

public class ServicePointManager
{
        // Default values.
        public const int DefaultNonPersistentConnectionLimit = 4;
        public const int DefaultPersistentConnectionLimit        = 2;

        // Internal state.
        private static ICertificatePolicy certificatePolicy;
        private static bool checkCertificateRevocationList;
        private static int defaultConnectionLimit =
                                DefaultPersistentConnectionLimit;
        private static int maxServicePointIdleTime = 900000;    // 900 seconds.
        private static int maxServicePoints;
        private static SecurityProtocolType securityProtocol =
                                SecurityProtocolType.Ssl3;

        // Cannot instantiate this class.
        private ServicePointManager() {}

#if CONFIG_X509_CERTIFICATES

        // Get or set the certificate policy.
        public static ICertificatePolicy CertificatePolicy
                        {
                                get
                                {
                                        return certificatePolicy;
                                }
                                set
                                {
                                        certificatePolicy = value;
                                }
                        }

        // Get or set the revocation list check flag.
        public static bool CheckCertificateRevocationList
                        {
                                get
                                {
                                        return checkCertificateRevocationList;
                                }
                                set
                                {
                                        checkCertificateRevocationList = value;
                                }
                        }

#endif // CONFIG_X509_CERTIFICATES

        // Get or set the default connection limit.
        public static int DefaultConnectionLimit
                        {
                                get
                                {
                                        return defaultConnectionLimit;
                                }
                                set
                                {
                                        if(value <= 0)
                                        {
                                                throw new 
ArgumentOutOfRangeException
                                                        ("value", 
S._("ArgRange_PositiveNonZero"));
                                        }
                                        defaultConnectionLimit = value;
                                }
                        }

        // Get or set the maximum service point idle time.
        public static int MaxServicePointIdleTime
                        {
                                get
                                {
                                        return maxServicePointIdleTime;
                                }
                                set
                                {
                                        if(value < -1)
                                        {
                                                throw new 
ArgumentOutOfRangeException
                                                        ("value", 
S._("ArgRange_NonNegOrNegOne"));
                                        }
                                        maxServicePointIdleTime = value;
                                }
                        }

        // Get or set the maximum number of service points.
        public static int MaxServicePoints
                        {
                                get
                                {
                                        return maxServicePoints;
                                }
                                set
                                {
                                        if(value < 0)
                                        {
                                                throw new 
ArgumentOutOfRangeException
                                                        ("value", 
S._("ArgRange_NonNegative"));
                                        }
                                        maxServicePoints = value;
                                }
                        }

        // Get or set the security protocol to use.
        public static SecurityProtocolType SecurityProtocol
                        {
                                get
                                {
                                        return securityProtocol;
                                }
                                set
                                {
                                        securityProtocol = value;
                                }
                        }

        // Find an existing service point.
        public static ServicePoint FindServicePoint(Uri address)
                        {
                                return FindServicePoint
                                        (address, 
GlobalProxySelection.GetEmptyWebProxy());
                        }
        public static ServicePoint FindServicePoint
                                (String uriString, IWebProxy proxy)
                        {
                                return FindServicePoint(new Uri(uriString), 
proxy);
                        }
        [TODO]
        public static ServicePoint FindServicePoint(Uri address, IWebProxy 
proxy)
                        {
                                if(address == null)
                                {
                                        throw new 
ArgumentNullException("address");
                                }
                                // TODO
                                return null;
                        }

}; // class ServicePointManager

}; // namespace System.Net

--- NEW FILE ---
/*
 * WebPermission.cs - Implementation of the
 *              "System.Security.Permissions.WebPermission" class.
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

namespace System.Net
{

#if CONFIG_PERMISSIONS

using System;
using System.Collections;
using System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
using System.Text;

public sealed class WebPermission : CodeAccessPermission
#if !ECMA_COMPAT
        , IUnrestrictedPermission
#endif
{
        // Internal state.
        private PermissionState state;
        private ArrayList acceptList;
        private ArrayList connectList;

        // Constructors.
        public WebPermission()
                        {
                                this.state = PermissionState.None;
                                this.acceptList = new ArrayList();
                                this.connectList = new ArrayList();
                        }
        public WebPermission(PermissionState state)
                        {
                                this.state = state;
                                this.acceptList = new ArrayList();
                                this.connectList = new ArrayList();
                        }
#if !ECMA_COMPAT
        public WebPermission(NetworkAccess access, Regex uriRegex) : this()
                        {
                                AddPermission(access, uriRegex);
                        }
#endif
        public WebPermission(NetworkAccess access, String uriString) : this()
                        {
                                AddPermission(access, uriString);
                        }
        private WebPermission(WebPermission copyFrom)
                        {
                                this.state = copyFrom.state;
                                this.acceptList = 
(ArrayList)(copyFrom.acceptList.Clone());
                                this.connectList = 
(ArrayList)(copyFrom.connectList.Clone());
                        }

        // Convert an XML value into a permissions value.
        public override void FromXml(SecurityElement esd)
                        {
                                String value;
                                if(esd == null)
                                {
                                        throw new ArgumentNullException("esd");
                                }
                                if(esd.Attribute("version") != "1")
                                {
                                        throw new 
ArgumentException(S._("Arg_PermissionVersion"));
                                }
                                value = esd.Attribute("Unrestricted");
                                if(value != null && Boolean.Parse(value))
                                {
                                        state = PermissionState.Unrestricted;
                                }
                                else
                                {
                                        state = PermissionState.None;
                                }
                                acceptList.Clear();
                                connectList.Clear();
                                if(state != PermissionState.Unrestricted)
                                {
                                        SecurityElement child;
                                        String str;
                                        child = 
esd.SearchForChildByTag("ConnectAccess");
                                        if(child != null && child.Children != 
null)
                                        {
                                                foreach(SecurityElement uri1 in 
child.Children)
                                                {
                                                        if(uri1.Tag != "URI")
                                                        {
                                                                continue;
                                                        }
                                                        str = 
uri1.Attribute("uri");
                                                        if(!IsRegex(str))
                                                        {
                                                                
connectList.Add(RegexUnescape(str));
                                                        }
                                                #if !ECMA_COMPAT
                                                        else
                                                        {
                                                                
connectList.Add(new Regex(str));
                                                        }
                                                #endif
                                                }
                                        }
                                        child = 
esd.SearchForChildByTag("AcceptAccess");
                                        if(child != null && child.Children != 
null)
                                        {
                                                foreach(SecurityElement uri1 in 
child.Children)
                                                {
                                                        if(uri1.Tag != "URI")
                                                        {
                                                                continue;
                                                        }
                                                        str = 
uri1.Attribute("uri");
                                                        if(!IsRegex(str))
                                                        {
                                                                
acceptList.Add(RegexUnescape(str));
                                                        }
                                                #if !ECMA_COMPAT
                                                        else
                                                        {
                                                                
acceptList.Add(new Regex(str));
                                                        }
                                                #endif
                                                }
                                        }
                                }
                        }

        // Convert this permissions object into an XML value.
        public override SecurityElement ToXml()
                        {
                                SecurityElement element;
                                SecurityElement child;
                                SecurityElement uri;
                                element = new SecurityElement("IPermission");
                                element.AddAttribute
                                        ("class",
                                         
SecurityElement.Escape(typeof(WebPermission).
                                                                                
        AssemblyQualifiedName));
                                element.AddAttribute("version", "1");
                                if(state == PermissionState.Unrestricted)
                                {
                                        element.AddAttribute("Unrestricted", 
"true");
                                }
                                else
                                {
                                        if(connectList.Count > 0)
                                        {
                                                child = new 
SecurityElement("ConnectAccess");
                                                element.AddChild(child);
                                                foreach(Object p1 in 
connectList)
                                                {
                                                        uri = new 
SecurityElement("URI");
                                                        child.AddChild(uri);
                                                #if !ECMA_COMPAT
                                                        if(p1 is Regex)
                                                        {
                                                                uri.AddAttribute
                                                                        ("uri",
                                                                         
SecurityElement.Escape(p1.ToString()));
                                                        }
                                                        else
                                                #endif
                                                        {
                                                                uri.AddAttribute
                                                                        ("uri",
                                                                         
SecurityElement.Escape
                                                                                
(RegexEscape(p1.ToString())));
                                                        }
                                                }
                                        }
                                        if(acceptList.Count > 0)
                                        {
                                                child = new 
SecurityElement("AcceptAccess");
                                                element.AddChild(child);
                                                foreach(Object p2 in acceptList)
                                                {
                                                        uri = new 
SecurityElement("URI");
                                                        child.AddChild(uri);
                                                #if !ECMA_COMPAT
                                                        if(p2 is Regex)
                                                        {
                                                                uri.AddAttribute
                                                                        ("uri",
                                                                         
SecurityElement.Escape(p2.ToString()));
                                                        }
                                                        else
                                                #endif
                                                        {
                                                                uri.AddAttribute
                                                                        ("uri",
                                                                         
SecurityElement.Escape
                                                                                
(RegexEscape(p2.ToString())));
                                                        }
                                                }
                                        }
                                }
                                return element;
                        }

        // Implement the IPermission interface.
        public override IPermission Copy()
                        {
                                return new WebPermission(this);
                        }
        public override IPermission Intersect(IPermission target)
                        {
                                if(target == null)
                                {
                                        return target;
                                }
                                else if(!(target is WebPermission))
                                {
                                        throw new 
ArgumentException(S._("Arg_PermissionMismatch"));
                                }
                                else 
if(((WebPermission)target).IsUnrestricted())
                                {
                                        return Copy();
                                }
                                else if(IsUnrestricted())
                                {
                                        return target.Copy();
                                }
                                else
                                {
                                        WebPermission perm = new 
WebPermission();
                                        WebPermission other = 
(WebPermission)target;
                                        foreach(Object p1 in acceptList)
                                        {
                                                
if(!other.acceptList.Contains(p1))
                                                {
                                                        perm.acceptList.Add(p1);
                                                }
                                        }
                                        foreach(Object p2 in connectList)
                                        {
                                                
if(!other.connectList.Contains(p2))
                                                {
                                                        
perm.connectList.Add(p2);
                                                }
                                        }
                                        return perm;
                                }
                        }
        public override bool IsSubsetOf(IPermission target)
                        {
                                if(target == null)
                                {
                                        return (state == PermissionState.None &&
                                                        acceptList.Count == 0 &&
                                                        connectList.Count == 0);
                                }
                                else if(!(target is WebPermission))
                                {
                                        throw new 
ArgumentException(S._("Arg_PermissionMismatch"));
                                }
                                else 
if(((SocketPermission)target).IsUnrestricted())
                                {
                                        return true;
                                }
                                else if(IsUnrestricted())
                                {
                                        return false;
                                }
                                else
                                {
                                        WebPermission other = 
(WebPermission)target;
                                        foreach(Object p1 in acceptList)
                                        {
                                                
if(!other.acceptList.Contains(p1))
                                                {
                                                        return false;
                                                }
                                        }
                                        foreach(Object p2 in connectList)
                                        {
                                                
if(!other.connectList.Contains(p2))
                                                {
                                                        return false;
                                                }
                                        }
                                        return true;
                                }
                        }
        public override IPermission Union(IPermission target)
                        {
                                if(target == null)
                                {
                                        return Copy();
                                }
                                else if(!(target is WebPermission))
                                {
                                        throw new 
ArgumentException(S._("Arg_PermissionMismatch"));
                                }
                                else if(IsUnrestricted() ||
                                        
((SocketPermission)target).IsUnrestricted())
                                {
                                        return new WebPermission
                                                (PermissionState.Unrestricted);
                                }
                                else
                                {
                                        WebPermission perm = new WebPermission
                                                        ((WebPermission)target);
                                        foreach(Object p1 in acceptList)
                                        {
                                                
if(!perm.acceptList.Contains(p1))
                                                {
                                                        perm.acceptList.Add(p1);
                                                }
                                        }
                                        foreach(Object p2 in connectList)
                                        {
                                                
if(!perm.connectList.Contains(p2))
                                                {
                                                        
perm.connectList.Add(p2);
                                                }
                                        }
                                        return perm;
                                }
                        }

        // Determine if this object has unrestricted permissions.
#if ECMA_COMPAT
        private bool IsUnrestricted()
#else
        public bool IsUnrestricted()
#endif
                        {
                                return (state == PermissionState.Unrestricted);
                        }

        // Add permission information to this permissions object.
#if !ECMA_COMPAT
        public void AddPermission(NetworkAccess access, Regex uriRegex)
                        {
                                if(state == PermissionState.Unrestricted)
                                {
                                        // No need to add permissions to an 
unrestricted set.
                                        return;
                                }
                                if(uriRegex == null)
                                {
                                        throw new 
ArgumentNullException("uriRegex");
                                }
                                if(access == NetworkAccess.Connect)
                                {
                                        connectList.Add(uriRegex);
                                }
                                else if(access == NetworkAccess.Accept)
                                {
                                        acceptList.Add(uriRegex);
                                }
                        }
#endif // !ECMA_COMPAT
        public void AddPermission(NetworkAccess access, String uriString)
                        {
                                if(state == PermissionState.Unrestricted)
                                {
                                        // No need to add permissions to an 
unrestricted set.
                                        return;
                                }
                                if(uriString == null)
                                {
                                        throw new 
ArgumentNullException("uriString");
                                }
                                if(access == NetworkAccess.Connect)
                                {
                                        connectList.Add(uriString);
                                }
                                else if(access == NetworkAccess.Accept)
                                {
                                        acceptList.Add(uriString);
                                }
                        }
        internal void AddPermission(NetworkAccess access, Object uri)
                        {
                                if(state == PermissionState.Unrestricted)
                                {
                                        // No need to add permissions to an 
unrestricted set.
                                        return;
                                }
                                if(uri == null)
                                {
                                        throw new ArgumentNullException("uri");
                                }
                                if(access == NetworkAccess.Connect)
                                {
                                        connectList.Add(uri);
                                }
                                else if(access == NetworkAccess.Accept)
                                {
                                        acceptList.Add(uri);
                                }
                        }

        // Iterate over the list of accept permissions.
        public IEnumerator AcceptList
                        {
                                get
                                {
                                        return acceptList.GetEnumerator();
                                }
                        }

        // Iterate over the list of connection permissions.
        public IEnumerator ConnectList
                        {
                                get
                                {
                                        return connectList.GetEnumerator();
                                }
                        }

        // Special characters for regular expressions.
        private const String regexChars = "\\+?.*()|{[^$#";

        // Escape a non-regex string.
        private static String RegexEscape(String str)
                        {
                                if(str == null)
                                {
                                        return null;
                                }
                                StringBuilder builder = new StringBuilder();
                                foreach(char ch in str)
                                {
                                        if(regexChars.IndexOf(ch) != -1)
                                        {
                                                builder.Append('\\');
                                                builder.Append(ch);
                                        }
                                        else if(ch == '\t')
                                        {
                                                builder.Append("\\t");
                                        }
                                        else if(ch == '\r')
                                        {
                                                builder.Append("\\r");
                                        }
                                        else if(ch == '\n')
                                        {
                                                builder.Append("\\n");
                                        }
                                        else if(ch == '\f')
                                        {
                                                builder.Append("\\f");
                                        }
                                        else
                                        {
                                                builder.Append(ch);
                                        }
                                }
                                return builder.ToString();
                        }

        // Determine if a string looks like a regex.
        private static bool IsRegex(String str)
                        {
                                if(str == null)
                                {
                                        return false;
                                }
                                int index;
                                char ch;
                                for(index = 0; index < str.Length; ++index)
                                {
                                        ch = str[index];
                                        if(ch == '\\')
                                        {
                                                ++index;
                                                if(index >= str.Length)
                                                {
                                                        return true;
                                                }
                                        }
                                        else if(regexChars.IndexOf(ch) != -1)
                                        {
                                                return true;
                                        }
                                }
                                return false;
                        }

        // Unescape a regex string to turn it into a normal string.
        private static String RegexUnescape(String str)
                        {
                                if(str == null)
                                {
                                        return null;
                                }
                                StringBuilder builder = new StringBuilder();
                                int index;
                                char ch;
                                for(index = 0; index < str.Length; ++index)
                                {
                                        ch = str[index];
                                        if(ch == '\\')
                                        {
                                                ++index;
                                                if(index >= str.Length)
                                                {
                                                        break;
                                                }
                                                ch = str[index];
                                                if(ch == 't')
                                                {
                                                        builder.Append('\t');
                                                }
                                                else if(ch == 'r')
                                                {
                                                        builder.Append('\r');
                                                }
                                                else if(ch == 'n')
                                                {
                                                        builder.Append('\n');
                                                }
                                                else if(ch == 'f')
                                                {
                                                        builder.Append('\f');
                                                }
                                                else
                                                {
                                                        builder.Append(ch);
                                                }
                                        }
                                        else
                                        {
                                                builder.Append(ch);
                                        }
                                }
                                return builder.ToString();
                        }

}; // class WebPermission

#endif // CONFIG_PERMISSIONS

}; // namespace System.Net

--- NEW FILE ---
/*
 * WebPermissionAttribute.cs - Implementation of the
 *                      "System.Security.Permissions.WebPermissionAttribute" 
class.
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

namespace System.Net
{

#if CONFIG_PERMISSIONS

using System;
using System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;

[AttributeUsage(AttributeTargets.Assembly |
                                AttributeTargets.Class |
                                AttributeTargets.Struct |
                                AttributeTargets.Constructor |
                                AttributeTargets.Method,
                                AllowMultiple=true, Inherited=false)]
public sealed class WebPermissionAttribute : CodeAccessSecurityAttribute
{
        // Internal state.
        private Object accept;
        private Object connect;

        // Constructors.
        public WebPermissionAttribute(SecurityAction action)
                        : base(action)
                        {
                                // Nothing to do here.
                        }

        // Get or set the properties.
        public String Accept
                        {
                                get
                                {
                                        return accept.ToString();
                                }
                                set
                                {
                                        if(accept != null)
                                        {
                                                throw new ArgumentException
                                                        
(S._("Arg_WebAcceptAlreadySet"));
                                        }
                                        accept = value;
                                }
                        }
#if !ECMA_COMPAT
        public String AcceptPattern
                        {
                                get
                                {
                                        return accept.ToString();
                                }
                                set
                                {
                                        if(accept != null)
                                        {
                                                throw new ArgumentException
                                                        
(S._("Arg_WebAcceptAlreadySet"));
                                        }
                                        accept = new Regex(value);
                                }
                        }
#endif
        public String Connect
                        {
                                get
                                {
                                        return connect.ToString();
                                }
                                set
                                {
                                        if(connect != null)
                                        {
                                                throw new ArgumentException
                                                        
(S._("Arg_WebConnectAlreadySet"));
                                        }
                                        connect = value;
                                }
                        }
#if !ECMA_COMPAT
        public String ConnectPattern
                        {
                                get
                                {
                                        return connect.ToString();
                                }
                                set
                                {
                                        if(connect != null)
                                        {
                                                throw new ArgumentException
                                                        
(S._("Arg_WebConnectAlreadySet"));
                                        }
                                        connect = new Regex(value);
                                }
                        }
#endif

        // Create a permission object that corresponds to this attribute.
        public override IPermission CreatePermission()
                        {
                                if(Unrestricted)
                                {
                                        return new WebPermission
                                                (PermissionState.Unrestricted);
                                }
                                else
                                {
                                        WebPermission perm = new 
WebPermission();
                                        if(accept != null)
                                        {
                                                
perm.AddPermission(NetworkAccess.Accept, accept);
                                        }
                                        if(connect != null)
                                        {
                                                
perm.AddPermission(NetworkAccess.Connect, connect);
                                        }
                                        return perm;
                                }
                        }

}; // class WebPermissionAttribute

#endif // CONFIG_PERMISSIONS

}; // namespace System.Net

Index: Cookie.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System/Net/Cookie.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** Cookie.cs   1 Sep 2003 04:17:28 -0000       1.2
--- Cookie.cs   18 Sep 2003 01:43:52 -0000      1.3
***************
*** 22,31 ****
  {
  
  using System.Globalization;
  using System.Text;
  
- #if !ECMA_COMPAT
  [Serializable]
- #endif
  public sealed class Cookie
  {
--- 22,31 ----
  {
  
+ #if !ECMA_COMPAT
+ 
  using System.Globalization;
  using System.Text;
  
  [Serializable]
  public sealed class Cookie
  {
***************
*** 405,408 ****
--- 405,410 ----
  
  }; // class Cookie
+ 
+ #endif // !ECMA_COMPAT
  
  }; // namespace System.Net

Index: Dns.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System/Net/Dns.cs,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** Dns.cs      14 May 2003 06:09:37 -0000      1.4
--- Dns.cs      18 Sep 2003 01:43:52 -0000      1.5
***************
*** 151,154 ****
--- 151,157 ----
        }; // class DnsAsyncResult
  
+       // Cannot instantiate this class.
+       private Dns () {}
+ 
        // Begin an asynchronous "get host by name" operation.
        [TODO]

Index: SocketPermission.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System/Net/SocketPermission.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** SocketPermission.cs 29 May 2003 03:12:57 -0000      1.3
--- SocketPermission.cs 18 Sep 2003 01:43:52 -0000      1.4
***************
*** 35,125 ****
  #endif
  {
-       // Storage for permission information.
- #if ECMA_COMPAT
-       internal
- #else
-       public
- #endif
-       class EndpointPermission
-       {
-               // Accessible internal state.
-               internal NetworkAccess access;
-               internal TransportType transport;
-               internal String hostName;
-               internal int portNumber;
- 
-               // Constructor.
-               internal EndpointPermission(NetworkAccess access,
-                                                                       
TransportType transport,
-                                                                       String 
hostName,
-                                                                       int 
portNumber)
-                               {
-                                       this.access = access;
-                                       this.transport = transport;
-                                       this.hostName = hostName;
-                                       this.portNumber = portNumber;
-                               }
- 
-               // Get the endpoint information.
-               public TransportType Transport
-                               {
-                                       get
-                                       {
-                                               return transport;
-                                       }
-                               }
-               public String Hostname
-                               {
-                                       get
-                                       {
-                                               return hostName;
-                                       }
-                               }
-               public int Port
-                               {
-                                       get
-                                       {
-                                               return portNumber;
-                                       }
-                               }
- 
-               // Determine if two endpoints are equal (ignoring access).
-               public override bool Equals(Object obj)
-                               {
-                                       EndpointPermission info = (obj as 
EndpointPermission);
-                                       if(info != null)
-                                       {
-                                               if(transport != info.transport)
-                                               {
-                                                       return false;
-                                               }
-                                               if(portNumber != 
info.portNumber)
-                                               {
-                                                       return false;
-                                               }
-                                               return 
(String.Compare(hostName, info.hostName,
-                                                                               
           true) == 0);
-                                       }
-                                       else
-                                       {
-                                               return false;
-                                       }
-                               }
- 
-               // Get the hash code for this object.
-               public override int GetHashCode()
-                               {
-                                       return ToString().GetHashCode();
-                               }
- 
-               // Convert this object into a string.
-               public override String ToString()
-                               {
-                                       return hostName + "#" + 
portNumber.ToString() + "#" +
-                                                  ((int)transport).ToString();
-                               }
- 
-       }; // class EndpointPermission
- 
        // Internal state.
        private PermissionState state;
--- 35,38 ----





reply via email to

[Prev in Thread] Current Thread [Next in Thread]