// (C) 2003 Andreas Nahr
//
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
using System;
using System.Collections;
using System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
-namespace System.Net
-{
+namespace System.Net {
+
+ internal enum WebPermissionInfoType {
+ InfoString,
+ InfoUnexecutedRegex,
+ InfoRegex,
+ }
+
+ internal class WebPermissionInfo {
+ WebPermissionInfoType _type;
+ object _info;
+
+ public WebPermissionInfo (WebPermissionInfoType type, string info)
+ {
+ _type = type;
+ _info = (string) info;
+ }
+
+ public WebPermissionInfo (Regex regex)
+ {
+ _type = WebPermissionInfoType.InfoRegex;
+ _info = (object) regex;
+ }
+
+ public string Info {
+ get {
+ if (_type == WebPermissionInfoType.InfoRegex)
+ return null;
+ return (string) _info;
+ }
+ }
+ }
+
// (based on SocketPermission.cs - Please look there to implement missing members!)
[MonoTODO ("Most private members that include functionallity are not implemented!")]
[Serializable]
// Methods
- [MonoTODO]
public void AddPermission (NetworkAccess access, string uriString)
{
- throw new NotImplementedException ();
+ WebPermissionInfo info = new WebPermissionInfo (WebPermissionInfoType.InfoString, uriString);
+ AddPermission (access, info);
}
- [MonoTODO]
+
public void AddPermission (NetworkAccess access, Regex uriRegex)
{
- throw new NotImplementedException ();
+ WebPermissionInfo info = new WebPermissionInfo (uriRegex);
+ AddPermission (access, info);
+ }
+
+ internal void AddPermission (NetworkAccess access, WebPermissionInfo info)
+ {
+ switch (access) {
+ case NetworkAccess.Accept:
+ m_acceptList.Add (info);
+ break;
+ case NetworkAccess.Connect:
+ m_connectList.Add (info);
+ break;
+ default:
+ string msg = Locale.GetText ("Unknown NetworkAccess value {0}.");
+ throw new ArgumentException (String.Format (msg, access), "access");
+ }
}
public override IPermission Copy ()
// LAMESPEC: it says to throw an ArgumentNullException in this case
if (securityElement.Tag != "IPermission")
throw new ArgumentException ("securityElement");
- string classStr = securityElement.Attribute ("class");
- if (classStr == null || !classStr.StartsWith (this.GetType ().FullName + ","))
- throw new ArgumentException ("securityElement");
+
string unrestricted = securityElement.Attribute ("Unrestricted");
if (unrestricted != null) {
this.m_noRestriction = (String.Compare (unrestricted, "true", true) == 0);
}
}
}
-