13 private bool m_noRestriction;
16 private bool m_UnrestrictedConnect;
19 private bool m_UnrestrictedAccept;
25 internal const string MatchAll =
".*";
27 private static volatile Regex s_MatchAllRegex;
29 internal static Regex MatchAllRegex
33 if (s_MatchAllRegex ==
null)
35 s_MatchAllRegex =
new Regex(
".*");
37 return s_MatchAllRegex;
47 if (m_UnrestrictedConnect)
55 for (
int i = 0; i < m_connectList.
Count; i++)
57 arrayList.
Add((m_connectList[i] is DelayedRegex) ? ((DelayedRegex)m_connectList[i]).AsRegex : ((m_connectList[i] is
Uri) ? ((
Uri)m_connectList[i]).GetComponents(
UriComponents.HttpRequestUrl,
UriFormat.UriEscaped) : m_connectList[i]));
69 if (m_UnrestrictedAccept)
77 for (
int i = 0; i < m_acceptList.
Count; i++)
79 arrayList.
Add((m_acceptList[i] is DelayedRegex) ? ((DelayedRegex)m_acceptList[i]).AsRegex : ((m_acceptList[i] is
Uri) ? ((
Uri)m_acceptList[i]).GetComponents(
UriComponents.HttpRequestUrl,
UriFormat.UriEscaped) : m_acceptList[i]));
94 m_noRestriction = unrestricted;
138 if (uriString ==
null)
152 if ((access &
NetworkAccess.Connect) != 0 && !m_UnrestrictedConnect)
154 arrayList.
Add(m_connectList);
156 if ((access &
NetworkAccess.Accept) != 0 && !m_UnrestrictedAccept)
158 arrayList.
Add(m_acceptList);
163 foreach (
object item2
in item)
165 string text = item2 as string;
166 if (text !=
null &&
string.Compare(text, uriString,
StringComparison.OrdinalIgnoreCase) == 0)
185 if (!m_noRestriction)
188 if ((access &
NetworkAccess.Connect) != 0 && !m_UnrestrictedConnect)
190 arrayList.
Add(m_connectList);
192 if ((access &
NetworkAccess.Accept) != 0 && !m_UnrestrictedAccept)
194 arrayList.
Add(m_acceptList);
199 foreach (
object item2
in item)
201 if (item2 is Uri && uri.
Equals(item2))
221 if (uriRegex ==
null)
231 if (!m_UnrestrictedConnect && (access &
NetworkAccess.Connect) != 0)
233 m_UnrestrictedConnect =
true;
234 m_connectList.
Clear();
236 if (!m_UnrestrictedAccept && (access &
NetworkAccess.Accept) != 0)
238 m_UnrestrictedAccept =
true;
239 m_acceptList.
Clear();
244 AddAsPattern(access,
new DelayedRegex(uriRegex));
248 internal void AddAsPattern(
NetworkAccess access, DelayedRegex uriRegexPattern)
251 if ((access &
NetworkAccess.Connect) != 0 && !m_UnrestrictedConnect)
253 arrayList.
Add(m_connectList);
255 if ((access &
NetworkAccess.Accept) != 0 && !m_UnrestrictedAccept)
257 arrayList.
Add(m_acceptList);
262 foreach (
object item2
in item)
264 if (item2 is DelayedRegex &&
string.Compare(uriRegexPattern.ToString(), item2.ToString(),
StringComparison.OrdinalIgnoreCase) == 0)
272 item.Add(uriRegexPattern);
282 return m_noRestriction;
296 return webPermission;
309 if (!m_noRestriction && !m_UnrestrictedConnect && !m_UnrestrictedAccept && m_connectList.
Count == 0)
311 return m_acceptList.
Count == 0;
316 if (webPermission ==
null)
320 if (webPermission.m_noRestriction)
328 DelayedRegex delayedRegex =
null;
329 if (!webPermission.m_UnrestrictedAccept)
331 if (m_UnrestrictedAccept)
335 if (m_acceptList.
Count != 0)
337 if (webPermission.m_acceptList.
Count == 0)
341 foreach (
object accept
in m_acceptList)
343 delayedRegex = (accept as DelayedRegex);
344 if (delayedRegex !=
null)
346 if (!isSpecialSubsetCase(accept.ToString(), webPermission.m_acceptList))
351 else if (!isMatchedURI(accept, webPermission.m_acceptList))
358 if (!webPermission.m_UnrestrictedConnect)
360 if (m_UnrestrictedConnect)
364 if (m_connectList.
Count != 0)
366 if (webPermission.m_connectList.
Count == 0)
370 foreach (
object connect
in m_connectList)
372 delayedRegex = (connect as DelayedRegex);
373 if (delayedRegex !=
null)
375 if (!isSpecialSubsetCase(connect.ToString(), webPermission.m_connectList))
380 else if (!isMatchedURI(connect, webPermission.m_connectList))
390 private static bool isSpecialSubsetCase(
string regexToCheck,
ArrayList permList)
392 foreach (
object perm
in permList)
394 DelayedRegex delayedRegex = perm as DelayedRegex;
396 if (delayedRegex !=
null)
398 if (
string.Compare(regexToCheck, delayedRegex.ToString(),
StringComparison.OrdinalIgnoreCase) == 0)
403 else if ((uri = (perm as Uri)) !=
null)
429 if (webPermission ==
null)
433 if (m_noRestriction || webPermission.m_noRestriction)
438 if (m_UnrestrictedConnect || webPermission.m_UnrestrictedConnect)
440 webPermission2.m_UnrestrictedConnect =
true;
444 webPermission2.m_connectList = (
ArrayList)webPermission.m_connectList.
Clone();
445 for (
int i = 0; i < m_connectList.
Count; i++)
447 DelayedRegex delayedRegex = m_connectList[i] as DelayedRegex;
448 if (delayedRegex ==
null)
450 if (m_connectList[i] is
string)
461 webPermission2.AddAsPattern(
NetworkAccess.Connect, delayedRegex);
465 if (m_UnrestrictedAccept || webPermission.m_UnrestrictedAccept)
467 webPermission2.m_UnrestrictedAccept =
true;
471 webPermission2.m_acceptList = (
ArrayList)webPermission.m_acceptList.
Clone();
472 for (
int j = 0; j < m_acceptList.
Count; j++)
474 DelayedRegex delayedRegex2 = m_acceptList[j] as DelayedRegex;
475 if (delayedRegex2 ==
null)
477 if (m_acceptList[j] is
string)
488 webPermission2.AddAsPattern(
NetworkAccess.Accept, delayedRegex2);
492 return webPermission2;
507 if (webPermission ==
null)
513 return webPermission.
Copy();
515 if (webPermission.m_noRestriction)
520 if (m_UnrestrictedConnect && webPermission.m_UnrestrictedConnect)
522 webPermission2.m_UnrestrictedConnect =
true;
524 else if (m_UnrestrictedConnect || webPermission.m_UnrestrictedConnect)
526 webPermission2.m_connectList = (
ArrayList)(m_UnrestrictedConnect ? webPermission :
this).m_connectList.
Clone();
530 intersectList(m_connectList, webPermission.m_connectList, webPermission2.m_connectList);
532 if (m_UnrestrictedAccept && webPermission.m_UnrestrictedAccept)
534 webPermission2.m_UnrestrictedAccept =
true;
536 else if (m_UnrestrictedAccept || webPermission.m_UnrestrictedAccept)
538 webPermission2.m_acceptList = (
ArrayList)(m_UnrestrictedAccept ? webPermission :
this).m_acceptList.
Clone();
542 intersectList(m_acceptList, webPermission.m_acceptList, webPermission2.m_acceptList);
544 if (!webPermission2.m_UnrestrictedConnect && !webPermission2.m_UnrestrictedAccept && webPermission2.m_connectList.
Count == 0 && webPermission2.m_acceptList.
Count == 0)
548 return webPermission2;
558 if (securityElement ==
null)
562 if (!securityElement.
Tag.Equals(
"IPermission"))
564 throw new ArgumentException(SR.GetString(
"net_not_ipermission"),
"securityElement");
566 string text = securityElement.Attribute(
"class");
569 throw new ArgumentException(SR.GetString(
"net_no_classname"),
"securityElement");
571 if (text.IndexOf(GetType().FullName) < 0)
575 string text2 = securityElement.Attribute(
"Unrestricted");
578 m_UnrestrictedAccept = (m_UnrestrictedConnect =
false);
579 if (text2 !=
null &&
string.Compare(text2,
"true",
StringComparison.OrdinalIgnoreCase) == 0)
581 m_noRestriction =
true;
584 m_noRestriction =
false;
586 if (securityElement2 !=
null)
590 if (child.
Tag.Equals(
"URI"))
595 text3 = child.Attribute(
"uri");
603 throw new ArgumentException(SR.GetString(
"net_perm_invalid_val_in_element"),
"ConnectAccess");
607 m_UnrestrictedConnect =
true;
611 AddAsPattern(
NetworkAccess.Connect,
new DelayedRegex(text3));
616 if (securityElement2 !=
null)
620 if (child2.
Tag.Equals(
"URI"))
625 text3 = child2.Attribute(
"uri");
633 throw new ArgumentException(SR.GetString(
"net_perm_invalid_val_in_element"),
"AcceptAccess");
637 m_UnrestrictedAccept =
true;
652 securityElement.
AddAttribute(
"class", GetType().FullName +
", " + GetType().
Module.Assembly.FullName.Replace(
'"',
'\''));
657 if (m_UnrestrictedConnect || m_connectList.
Count > 0)
660 if (m_UnrestrictedConnect)
664 securityElement2.
AddChild(securityElement3);
668 foreach (
object connect
in m_connectList)
672 if (connect is
string)
678 securityElement2.
AddChild(securityElement4);
681 securityElement.
AddChild(securityElement2);
683 if (m_UnrestrictedAccept || m_acceptList.
Count > 0)
686 if (m_UnrestrictedAccept)
690 securityElement5.
AddChild(securityElement6);
694 foreach (
object accept
in m_acceptList)
698 if (accept is
string)
704 securityElement5.
AddChild(securityElement7);
707 securityElement.
AddChild(securityElement5);
714 return securityElement;
717 private static bool isMatchedURI(
object uriToCheck,
ArrayList uriPatternList)
719 string text = uriToCheck as string;
720 foreach (
object uriPattern
in uriPatternList)
722 DelayedRegex delayedRegex = uriPattern as DelayedRegex;
723 if (delayedRegex ==
null)
725 if (uriToCheck.GetType() == uriPattern.GetType())
727 if (text !=
null &&
string.Compare(text, (
string)uriPattern,
StringComparison.OrdinalIgnoreCase) == 0)
731 if (text ==
null && uriToCheck.Equals(uriPattern))
739 string text2 = (text !=
null) ? text : ((Uri)uriToCheck).GetComponents(
UriComponents.HttpRequestUrl,
UriFormat.UriEscaped);
740 Match match = delayedRegex.AsRegex.Match(text2);
741 if (match !=
null && match.Index == 0 && match.Length == text2.Length)
748 match = delayedRegex.AsRegex.Match(text2);
749 if (match !=
null && match.Index == 0 && match.Length == text2.Length)
761 bool[] array =
new bool[
A.Count];
762 bool[] array2 =
new bool[
B.Count];
764 foreach (
object item
in A)
767 foreach (
object item2
in B)
769 if (!array2[num2] && item.GetType() == item2.GetType())
773 if (item.Equals(item2))
776 array[num] = (array2[num2] =
true);
780 else if (
string.Compare(item.ToString(), item2.ToString(),
StringComparison.OrdinalIgnoreCase) == 0)
783 array[num] = (array2[num2] =
true);
792 foreach (
object item3
in A)
797 foreach (
object item4
in B)
802 object obj = intersectPair(item3, item4, out isUri);
806 foreach (
object item5
in result)
808 if (isUri == item5 is Uri && (isUri ? obj.Equals(item5) : (
string.Compare(item5.ToString(), obj.ToString(),
StringComparison.OrdinalIgnoreCase) == 0)))
827 private static object intersectPair(
object L,
object R, out
bool isUri)
830 DelayedRegex delayedRegex =
L as DelayedRegex;
831 DelayedRegex delayedRegex2 =
R as DelayedRegex;
832 if (delayedRegex !=
null && delayedRegex2 !=
null)
834 return new DelayedRegex(
"(?=(" + delayedRegex.ToString() +
"))(" + delayedRegex2.ToString() +
")");
836 if (delayedRegex !=
null && delayedRegex2 ==
null)
839 string text = isUri ? ((Uri)R).GetComponents(
UriComponents.HttpRequestUrl,
UriFormat.UriEscaped) :
R.ToString();
840 Match match = delayedRegex.AsRegex.Match(text);
841 if (match !=
null && match.Index == 0 && match.Length == text.Length)
847 if (delayedRegex ==
null && delayedRegex2 !=
null)
850 string text2 = isUri ? ((Uri)L).GetComponents(
UriComponents.HttpRequestUrl,
UriFormat.UriEscaped) :
L.ToString();
851 Match match2 = delayedRegex2.AsRegex.Match(text2);
852 if (match2 !=
null && match2.
Index == 0 && match2.
Length == text2.Length)
867 if (
string.Compare(
L.ToString(),
R.ToString(),
StringComparison.OrdinalIgnoreCase) != 0)
UriKind
Defines the kinds of T:System.Uris for the M:System.Uri.IsWellFormedUriString(System....
Allows a permission to expose an unrestricted state.
override void FromXml(SecurityElement securityElement)
Reconstructs a T:System.Net.WebPermission from an XML encoding.
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
override IPermission Copy()
Creates a copy of a T:System.Net.WebPermission.
override string ToString()
Returns the regular expression pattern that was passed into the Regex constructor.
StringComparison
Specifies the culture, case, and sort rules to be used by certain overloads of the M:System....
NetworkAccess
Specifies network access permissions.
WebPermission(NetworkAccess access, Regex uriRegex)
Initializes a new instance of the T:System.Net.WebPermission class with the specified access rights f...
virtual int Count
Gets the number of elements actually contained in the T:System.Collections.ArrayList.
SecurityElement SearchForChildByTag(string tag)
Finds a child by its tag name.
WebPermission(NetworkAccess access, string uriString)
Initializes a new instance of the T:System.Net.WebPermission class with the specified access rights f...
virtual void Clear()
Removes all elements from the T:System.Collections.ArrayList.
virtual object Clone()
Creates a shallow copy of the T:System.Collections.ArrayList.
string Tag
Gets or sets the tag name of an XML element.
static bool TryCreate(string uriString, UriKind uriKind, out Uri result)
Creates a new T:System.Uri using the specified T:System.String instance and a T:System....
UriComponents
Specifies the parts of a T:System.Uri.
static string Escape(string str)
Replaces invalid XML characters in a string with their valid XML equivalent.
void AddChild(SecurityElement child)
Adds a child element to the XML element.
WebPermission(PermissionState state)
Creates a new instance of the T:System.Net.WebPermission class that passes all demands or fails all d...
WebPermission()
Creates a new instance of the T:System.Net.WebPermission class.
Represents the XML object model for encoding security objects. This class cannot be inherited.
int Index
The position in the original string where the first character of the captured substring is found.
Controls rights to access HTTP Internet resources.
unsafe override bool Equals(object comparand)
Compares two T:System.Uri instances for equality.
Defines the underlying structure of all code access permissions.
string GetComponents(UriComponents components, UriFormat format)
Gets the specified components of the current instance using the specified escaping for special charac...
Defines methods implemented by permission types.
virtual int Add(object value)
Adds an object to the end of the T:System.Collections.ArrayList.
override bool IsSubsetOf(IPermission target)
Determines whether the current T:System.Net.WebPermission is a subset of the specified object.
Represents the results from a single regular expression match.
void AddPermission(NetworkAccess access, string uriString)
Adds the specified URI string with the specified access rights to the current T:System....
The exception that is thrown when one of the arguments provided to a method is not valid.
static string Escape(string str)
Escapes a minimal set of characters (\, *, +, ?, |, {, [, (,), ^, $,., #, and white space) by replaci...
Attribute can be applied to a module.
UriFormat
Controls how URI information is escaped.
override SecurityElement ToXml()
Creates an XML encoding of a T:System.Net.WebPermission and its current state.
int Length
Gets the length of the captured substring.
PermissionState
Specifies whether a permission should have all or no access to resources at creation.
IEnumerator?? ConnectList
This property returns an enumeration of a single connect permissions held by this T:System....
void AddAttribute(string name, string value)
Adds a name/value attribute to an XML element.
Specifies that the class can be serialized.
override IPermission Union(IPermission target)
Returns the logical union between two instances of the T:System.Net.WebPermission class.
ArrayList Children
Gets or sets the array of child elements of the XML element.
virtual IEnumerator GetEnumerator()
Returns an enumerator for the entire T:System.Collections.ArrayList.
The exception that is thrown when an invoked method is not supported, or when there is an attempt to ...
override IPermission Intersect(IPermission target)
Returns the logical intersection of two T:System.Net.WebPermission instances.
Provides an object representation of a uniform resource identifier (URI) and easy access to the parts...
Represents an immutable regular expression.To browse the .NET Framework source code for this type,...
Supports a simple iteration over a non-generic collection.
void AddPermission(NetworkAccess access, Regex uriRegex)
Adds the specified URI with the specified access rights to the current T:System.Net....
IEnumerator?? AcceptList
This property returns an enumeration of a single accept permissions held by this T:System....
bool IsUnrestricted()
Checks the overall permission state of the T:System.Net.WebPermission.
Implements the T:System.Collections.IList interface using an array whose size is dynamically increase...