Files
2026-06-04 11:42:34 +02:00

404 lines
17 KiB
C#

using System;
using System.Collections;
using System.Globalization;
using System.Text;
using System.Text.RegularExpressions;
namespace System
{
/// <summary>Parses a new URI scheme. This is an abstract class.</summary>
// Token: 0x02000304 RID: 772
public abstract class UriParser
{
// Token: 0x06001BDB RID: 7131 RVA: 0x0006826C File Offset: 0x0006646C
private static global::System.Text.RegularExpressions.Match ParseAuthority(global::System.Text.RegularExpressions.Group g)
{
return global::System.UriParser.auth_regex.Match(g.Value);
}
/// <summary>Gets the components from a URI.</summary>
/// <returns>A string that contains the components.</returns>
/// <param name="uri">The URI to parse.</param>
/// <param name="components">The <see cref="T:System.UriComponents" /> to retrieve from <paramref name="uri" />.</param>
/// <param name="format">One of the <see cref="T:System.UriFormat" /> values that controls how special characters are escaped.</param>
/// <exception cref="T:System.ArgumentOutOfRangeException">
/// <paramref name="uriFormat" /> is invalid.- or -<paramref name="uriComponents" /> is not a combination of valid <see cref="T:System.UriComponents" /> values. </exception>
/// <exception cref="T:System.InvalidOperationException">
/// <paramref name="uri" /> requires user-driven parsing- or -<paramref name="uri" /> is not an absolute URI. Relative URIs cannot be used with this method.</exception>
// Token: 0x06001BDC RID: 7132 RVA: 0x00068280 File Offset: 0x00066480
protected internal virtual string GetComponents(global::System.Uri uri, global::System.UriComponents components, global::System.UriFormat format)
{
if (format < global::System.UriFormat.UriEscaped || format > global::System.UriFormat.SafeUnescaped)
{
throw new ArgumentOutOfRangeException("format");
}
global::System.Text.RegularExpressions.Match match = global::System.UriParser.uri_regex.Match(uri.OriginalString);
string value = this.scheme_name;
int defaultPort = this.default_port;
if (value == null || value == "*")
{
value = match.Groups[2].Value;
defaultPort = global::System.Uri.GetDefaultPort(value);
}
else if (string.Compare(value, match.Groups[2].Value, true) != 0)
{
throw new SystemException("URI Parser: scheme mismatch: " + value + " vs. " + match.Groups[2].Value);
}
global::System.UriComponents uriComponents = components;
switch (uriComponents)
{
case global::System.UriComponents.Scheme:
return value;
case global::System.UriComponents.UserInfo:
return global::System.UriParser.ParseAuthority(match.Groups[4]).Groups[2].Value;
default:
{
if (uriComponents == global::System.UriComponents.Path)
{
return this.Format(this.IgnoreFirstCharIf(match.Groups[5].Value, '/'), format);
}
if (uriComponents == global::System.UriComponents.Query)
{
return this.Format(match.Groups[7].Value, format);
}
if (uriComponents == global::System.UriComponents.Fragment)
{
return this.Format(match.Groups[9].Value, format);
}
if (uriComponents != global::System.UriComponents.StrongPort)
{
if (uriComponents == global::System.UriComponents.SerializationInfoString)
{
components = global::System.UriComponents.AbsoluteUri;
}
global::System.Text.RegularExpressions.Match match2 = global::System.UriParser.ParseAuthority(match.Groups[4]);
StringBuilder stringBuilder = new StringBuilder();
if ((components & global::System.UriComponents.Scheme) != (global::System.UriComponents)0)
{
stringBuilder.Append(value);
stringBuilder.Append(global::System.Uri.GetSchemeDelimiter(value));
}
if ((components & global::System.UriComponents.UserInfo) != (global::System.UriComponents)0)
{
stringBuilder.Append(match2.Groups[1].Value);
}
if ((components & global::System.UriComponents.Host) != (global::System.UriComponents)0)
{
stringBuilder.Append(match2.Groups[3].Value);
}
if ((components & global::System.UriComponents.StrongPort) != (global::System.UriComponents)0)
{
global::System.Text.RegularExpressions.Group group = match2.Groups[4];
stringBuilder.Append((!group.Success) ? (":" + defaultPort) : group.Value);
}
if ((components & global::System.UriComponents.Port) != (global::System.UriComponents)0)
{
string value2 = match2.Groups[5].Value;
if (value2 != null && value2 != string.Empty && value2 != defaultPort.ToString())
{
stringBuilder.Append(match2.Groups[4].Value);
}
}
if ((components & global::System.UriComponents.Path) != (global::System.UriComponents)0)
{
stringBuilder.Append(match.Groups[5]);
}
if ((components & global::System.UriComponents.Query) != (global::System.UriComponents)0)
{
stringBuilder.Append(match.Groups[6]);
}
if ((components & global::System.UriComponents.Fragment) != (global::System.UriComponents)0)
{
stringBuilder.Append(match.Groups[8]);
}
return this.Format(stringBuilder.ToString(), format);
}
global::System.Text.RegularExpressions.Group group2 = global::System.UriParser.ParseAuthority(match.Groups[4]).Groups[5];
return (!group2.Success) ? defaultPort.ToString() : group2.Value;
}
case global::System.UriComponents.Host:
return global::System.UriParser.ParseAuthority(match.Groups[4]).Groups[3].Value;
case global::System.UriComponents.Port:
{
string value3 = global::System.UriParser.ParseAuthority(match.Groups[4]).Groups[5].Value;
if (value3 != null && value3 != string.Empty && value3 != defaultPort.ToString())
{
return value3;
}
return string.Empty;
}
}
}
/// <summary>Initialize the state of the parser and validate the URI.</summary>
/// <param name="uri">The T:System.Uri to validate.</param>
/// <param name="parsingError">Validation errors, if any.</param>
// Token: 0x06001BDD RID: 7133 RVA: 0x00068664 File Offset: 0x00066864
protected internal virtual void InitializeAndValidate(global::System.Uri uri, out global::System.UriFormatException parsingError)
{
if (uri.Scheme != this.scheme_name && this.scheme_name != "*")
{
parsingError = new global::System.UriFormatException("The argument Uri's scheme does not match");
}
else
{
parsingError = null;
}
}
/// <summary>Determines whether <paramref name="baseUri" /> is a base URI for <paramref name="relativeUri" />.</summary>
/// <returns>true if <paramref name="baseUri" /> is a base URI for <paramref name="relativeUri" />; otherwise, false.</returns>
/// <param name="baseUri">The base URI.</param>
/// <param name="relativeUri">The URI to test.</param>
// Token: 0x06001BDE RID: 7134 RVA: 0x000686B0 File Offset: 0x000668B0
protected internal virtual bool IsBaseOf(global::System.Uri baseUri, global::System.Uri relativeUri)
{
if (global::System.Uri.Compare(baseUri, relativeUri, global::System.UriComponents.Scheme | global::System.UriComponents.UserInfo | global::System.UriComponents.Host | global::System.UriComponents.Port, global::System.UriFormat.Unescaped, StringComparison.InvariantCultureIgnoreCase) != 0)
{
return false;
}
string localPath = baseUri.LocalPath;
int num = localPath.LastIndexOf('/') + 1;
return string.Compare(localPath, 0, relativeUri.LocalPath, 0, num, StringComparison.InvariantCultureIgnoreCase) == 0;
}
/// <summary>Indicates whether a URI is well-formed.</summary>
/// <returns>true if <paramref name="uri" /> is well-formed; otherwise, false.</returns>
/// <param name="uri">The URI to check.</param>
// Token: 0x06001BDF RID: 7135 RVA: 0x000686F4 File Offset: 0x000668F4
protected internal virtual bool IsWellFormedOriginalString(global::System.Uri uri)
{
return uri.IsWellFormedOriginalString();
}
/// <summary>Invoked by a <see cref="T:System.Uri" /> constructor to get a <see cref="T:System.UriParser" /> instance</summary>
/// <returns>A <see cref="T:System.UriParser" /> for the constructed <see cref="T:System.Uri" />.</returns>
// Token: 0x06001BE0 RID: 7136 RVA: 0x000686FC File Offset: 0x000668FC
protected internal virtual global::System.UriParser OnNewUri()
{
return this;
}
/// <summary>Invoked by the Framework when a <see cref="T:System.UriParser" /> method is registered.</summary>
/// <param name="schemeName">The scheme that is associated with this <see cref="T:System.UriParser" />.</param>
/// <param name="defaultPort">The port number of the scheme.</param>
// Token: 0x06001BE1 RID: 7137 RVA: 0x00068700 File Offset: 0x00066900
[global::System.MonoTODO]
protected virtual void OnRegister(string schemeName, int defaultPort)
{
}
/// <summary>Called by <see cref="T:System.Uri" /> constructors and <see cref="Overload:System.Uri.TryCreate" /> to resolve a relative URI.</summary>
/// <returns>The string of the resolved relative <see cref="T:System.Uri" />.</returns>
/// <param name="baseUri">A base URI.</param>
/// <param name="relativeUri">A relative URI.</param>
/// <param name="parsingError">Errors during the resolve process, if any.</param>
/// <exception cref="T:System.ArgumentOutOfRangeException">
/// <paramref name="baseUri" /> parameter is not an absolute <see cref="T:System.Uri" />- or -<paramref name="baseUri" /> parameter requires user-driven parsing.</exception>
// Token: 0x06001BE2 RID: 7138 RVA: 0x00068704 File Offset: 0x00066904
[global::System.MonoTODO]
protected internal virtual string Resolve(global::System.Uri baseUri, global::System.Uri relativeUri, out global::System.UriFormatException parsingError)
{
throw new NotImplementedException();
}
// Token: 0x17000872 RID: 2162
// (get) Token: 0x06001BE3 RID: 7139 RVA: 0x0006870C File Offset: 0x0006690C
// (set) Token: 0x06001BE4 RID: 7140 RVA: 0x00068714 File Offset: 0x00066914
internal string SchemeName
{
get
{
return this.scheme_name;
}
set
{
this.scheme_name = value;
}
}
// Token: 0x17000873 RID: 2163
// (get) Token: 0x06001BE5 RID: 7141 RVA: 0x00068720 File Offset: 0x00066920
// (set) Token: 0x06001BE6 RID: 7142 RVA: 0x00068728 File Offset: 0x00066928
internal int DefaultPort
{
get
{
return this.default_port;
}
set
{
this.default_port = value;
}
}
// Token: 0x06001BE7 RID: 7143 RVA: 0x00068734 File Offset: 0x00066934
private string IgnoreFirstCharIf(string s, char c)
{
if (s.Length == 0)
{
return string.Empty;
}
if (s[0] == c)
{
return s.Substring(1);
}
return s;
}
// Token: 0x06001BE8 RID: 7144 RVA: 0x00068768 File Offset: 0x00066968
private string Format(string s, global::System.UriFormat format)
{
if (s.Length == 0)
{
return string.Empty;
}
switch (format)
{
case global::System.UriFormat.UriEscaped:
return global::System.Uri.EscapeString(s, false, true, true);
case global::System.UriFormat.Unescaped:
return global::System.Uri.Unescape(s, false);
case global::System.UriFormat.SafeUnescaped:
s = global::System.Uri.Unescape(s, false);
return s;
default:
throw new ArgumentOutOfRangeException("format");
}
}
// Token: 0x06001BE9 RID: 7145 RVA: 0x000687C8 File Offset: 0x000669C8
private static void CreateDefaults()
{
if (global::System.UriParser.table != null)
{
return;
}
Hashtable hashtable = new Hashtable();
global::System.UriParser.InternalRegister(hashtable, new global::System.DefaultUriParser(), global::System.Uri.UriSchemeFile, -1);
global::System.UriParser.InternalRegister(hashtable, new global::System.DefaultUriParser(), global::System.Uri.UriSchemeFtp, 21);
global::System.UriParser.InternalRegister(hashtable, new global::System.DefaultUriParser(), global::System.Uri.UriSchemeGopher, 70);
global::System.UriParser.InternalRegister(hashtable, new global::System.DefaultUriParser(), global::System.Uri.UriSchemeHttp, 80);
global::System.UriParser.InternalRegister(hashtable, new global::System.DefaultUriParser(), global::System.Uri.UriSchemeHttps, 443);
global::System.UriParser.InternalRegister(hashtable, new global::System.DefaultUriParser(), global::System.Uri.UriSchemeMailto, 25);
global::System.UriParser.InternalRegister(hashtable, new global::System.DefaultUriParser(), global::System.Uri.UriSchemeNetPipe, -1);
global::System.UriParser.InternalRegister(hashtable, new global::System.DefaultUriParser(), global::System.Uri.UriSchemeNetTcp, -1);
global::System.UriParser.InternalRegister(hashtable, new global::System.DefaultUriParser(), global::System.Uri.UriSchemeNews, 119);
global::System.UriParser.InternalRegister(hashtable, new global::System.DefaultUriParser(), global::System.Uri.UriSchemeNntp, 119);
global::System.UriParser.InternalRegister(hashtable, new global::System.DefaultUriParser(), "ldap", 389);
object obj = global::System.UriParser.lock_object;
lock (obj)
{
if (global::System.UriParser.table == null)
{
global::System.UriParser.table = hashtable;
}
}
}
/// <summary>Indicates whether the parser for a scheme is registered.</summary>
/// <returns>true if <paramref name="schemeName" /> has been registered; otherwise, false.</returns>
/// <param name="schemeName">The scheme name to check.</param>
/// <exception cref="T:System.ArgumentNullException">The <paramref name="schemeName" /> parameter is null.</exception>
/// <exception cref="T:System.ArgumentOutOfRangeException">The <paramref name="schemeName" /> parameter is not valid. </exception>
// Token: 0x06001BEA RID: 7146 RVA: 0x000688FC File Offset: 0x00066AFC
public static bool IsKnownScheme(string schemeName)
{
if (schemeName == null)
{
throw new ArgumentNullException("schemeName");
}
if (schemeName.Length == 0)
{
throw new ArgumentOutOfRangeException("schemeName");
}
global::System.UriParser.CreateDefaults();
string text = schemeName.ToLower(CultureInfo.InvariantCulture);
return global::System.UriParser.table[text] != null;
}
// Token: 0x06001BEB RID: 7147 RVA: 0x00068954 File Offset: 0x00066B54
private static void InternalRegister(Hashtable table, global::System.UriParser uriParser, string schemeName, int defaultPort)
{
uriParser.SchemeName = schemeName;
uriParser.DefaultPort = defaultPort;
if (uriParser is global::System.GenericUriParser)
{
table.Add(schemeName, uriParser);
}
else
{
table.Add(schemeName, new global::System.DefaultUriParser
{
SchemeName = schemeName,
DefaultPort = defaultPort
});
}
uriParser.OnRegister(schemeName, defaultPort);
}
/// <summary>Associates a scheme and port number with a <see cref="T:System.UriParser" />.</summary>
/// <param name="uriParser">The URI parser to register.</param>
/// <param name="schemeName">The name of the scheme that is associated with this parser.</param>
/// <param name="defaultPort">The default port number for the specified scheme.</param>
/// <exception cref="T:System.ArgumentNullException">
/// <paramref name="uriParser" /> parameter is null- or -<paramref name="schemeName" /> parameter is null.</exception>
/// <exception cref="T:System.ArgumentOutOfRangeException">
/// <paramref name="schemeName" /> parameter is not valid- or -<paramref name="defaultPort" /> parameter is not valid. The <paramref name="defaultPort" /> parameter must be not be less than zero or greater than 65,534.</exception>
// Token: 0x06001BEC RID: 7148 RVA: 0x000689AC File Offset: 0x00066BAC
public static void Register(global::System.UriParser uriParser, string schemeName, int defaultPort)
{
if (uriParser == null)
{
throw new ArgumentNullException("uriParser");
}
if (schemeName == null)
{
throw new ArgumentNullException("schemeName");
}
if (defaultPort < -1 || defaultPort >= 65535)
{
throw new ArgumentOutOfRangeException("defaultPort");
}
global::System.UriParser.CreateDefaults();
string text = schemeName.ToLower(CultureInfo.InvariantCulture);
if (global::System.UriParser.table[text] != null)
{
string text2 = global::Locale.GetText("Scheme '{0}' is already registred.");
throw new InvalidOperationException(text2);
}
global::System.UriParser.InternalRegister(global::System.UriParser.table, uriParser, text, defaultPort);
}
// Token: 0x06001BED RID: 7149 RVA: 0x00068A38 File Offset: 0x00066C38
internal static global::System.UriParser GetParser(string schemeName)
{
if (schemeName == null)
{
return null;
}
global::System.UriParser.CreateDefaults();
string text = schemeName.ToLower(CultureInfo.InvariantCulture);
return (global::System.UriParser)global::System.UriParser.table[text];
}
// Token: 0x0400163D RID: 5693
private static object lock_object = new object();
// Token: 0x0400163E RID: 5694
private static Hashtable table;
// Token: 0x0400163F RID: 5695
internal string scheme_name;
// Token: 0x04001640 RID: 5696
private int default_port;
// Token: 0x04001641 RID: 5697
private static readonly global::System.Text.RegularExpressions.Regex uri_regex = new global::System.Text.RegularExpressions.Regex("^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?");
// Token: 0x04001642 RID: 5698
private static readonly global::System.Text.RegularExpressions.Regex auth_regex = new global::System.Text.RegularExpressions.Regex("^(([^@]+)@)?(.*?)(:([0-9]+))?$");
}
}