using System; using System.Collections; using System.Globalization; using System.Text; using System.Text.RegularExpressions; namespace System { /// Parses a new URI scheme. This is an abstract class. // 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); } /// Gets the components from a URI. /// A string that contains the components. /// The URI to parse. /// The to retrieve from . /// One of the values that controls how special characters are escaped. /// /// is invalid.- or - is not a combination of valid values. /// /// requires user-driven parsing- or - is not an absolute URI. Relative URIs cannot be used with this method. // 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; } } } /// Initialize the state of the parser and validate the URI. /// The T:System.Uri to validate. /// Validation errors, if any. // 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; } } /// Determines whether is a base URI for . /// true if is a base URI for ; otherwise, false. /// The base URI. /// The URI to test. // 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; } /// Indicates whether a URI is well-formed. /// true if is well-formed; otherwise, false. /// The URI to check. // Token: 0x06001BDF RID: 7135 RVA: 0x000686F4 File Offset: 0x000668F4 protected internal virtual bool IsWellFormedOriginalString(global::System.Uri uri) { return uri.IsWellFormedOriginalString(); } /// Invoked by a constructor to get a instance /// A for the constructed . // Token: 0x06001BE0 RID: 7136 RVA: 0x000686FC File Offset: 0x000668FC protected internal virtual global::System.UriParser OnNewUri() { return this; } /// Invoked by the Framework when a method is registered. /// The scheme that is associated with this . /// The port number of the scheme. // Token: 0x06001BE1 RID: 7137 RVA: 0x00068700 File Offset: 0x00066900 [global::System.MonoTODO] protected virtual void OnRegister(string schemeName, int defaultPort) { } /// Called by constructors and to resolve a relative URI. /// The string of the resolved relative . /// A base URI. /// A relative URI. /// Errors during the resolve process, if any. /// /// parameter is not an absolute - or - parameter requires user-driven parsing. // 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; } } } /// Indicates whether the parser for a scheme is registered. /// true if has been registered; otherwise, false. /// The scheme name to check. /// The parameter is null. /// The parameter is not valid. // 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); } /// Associates a scheme and port number with a . /// The URI parser to register. /// The name of the scheme that is associated with this parser. /// The default port number for the specified scheme. /// /// parameter is null- or - parameter is null. /// /// parameter is not valid- or - parameter is not valid. The parameter must be not be less than zero or greater than 65,534. // 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]+))?$"); } }