// // All BuiltIn parsers use that ctor. They are marked with "simple" and "built-in" flags // internal BuiltInUriParser(string lwrCaseScheme, int defaultPort, UriSyntaxFlags syntaxFlags) : base((syntaxFlags | UriSyntaxFlags.SimpleUserSyntax | UriSyntaxFlags.BuiltInSyntax)) { _scheme = lwrCaseScheme; _port = defaultPort; }
internal void CheckSetIsSimpleFlag() { Type type = base.GetType(); if ((((type == typeof(GenericUriParser)) || (type == typeof(HttpStyleUriParser))) || ((type == typeof(FtpStyleUriParser)) || (type == typeof(FileStyleUriParser)))) || (((type == typeof(NewsStyleUriParser)) || (type == typeof(GopherStyleUriParser))) || (((type == typeof(NetPipeStyleUriParser)) || (type == typeof(NetTcpStyleUriParser))) || (type == typeof(LdapStyleUriParser))))) { this.m_Flags |= UriSyntaxFlags.SimpleUserSyntax; } }
// private static UriSyntaxFlags MapGenericParserOptions(GenericUriParserOptions options) { // // Here we map public flags to internal ones // Note an instacne of this parser is always a "simple parser" since the class is sealed. // UriSyntaxFlags flags = DefaultGenericUriParserFlags; if ((options & GenericUriParserOptions.GenericAuthority) != 0) { // Disable some options that are not compatible with generic authority flags &= ~(UriSyntaxFlags.MayHaveUserInfo | UriSyntaxFlags.MayHavePort | UriSyntaxFlags.AllowUncHost | UriSyntaxFlags.AllowAnInternetHost); flags |= UriSyntaxFlags.AllowAnyOtherHost; } if ((options & GenericUriParserOptions.AllowEmptyAuthority) != 0) { flags |= UriSyntaxFlags.AllowEmptyHost; } if ((options & GenericUriParserOptions.NoUserInfo) != 0) { flags &= ~UriSyntaxFlags.MayHaveUserInfo; } if ((options & GenericUriParserOptions.NoPort) != 0) { flags &= ~UriSyntaxFlags.MayHavePort; } if ((options & GenericUriParserOptions.NoQuery) != 0) { flags &= ~UriSyntaxFlags.MayHaveQuery; } if ((options & GenericUriParserOptions.NoFragment) != 0) { flags &= ~UriSyntaxFlags.MayHaveFragment; } if ((options & GenericUriParserOptions.DontConvertPathBackslashes) != 0) { flags &= ~UriSyntaxFlags.ConvertPathSlashes; } if ((options & GenericUriParserOptions.DontCompressPath) != 0) { flags &= ~(UriSyntaxFlags.CompressPath | UriSyntaxFlags.CanonicalizeAsFilePath); } if ((options & GenericUriParserOptions.DontUnescapePathDotsAndSlashes) != 0) { flags &= ~UriSyntaxFlags.UnEscapeDotsAndSlashes; } return(flags); }
// // This method is used to update flags. The scenario where this is needed is when the user specifies // flags in the config file. The config file is read after UriParser instances were created. // internal void SetUpdatableFlags(UriSyntaxFlags flags) { Debug.Assert(!_updatableFlagsUsed, "SetUpdatableFlags() already called. It can only be called once per parser."); Debug.Assert((flags & (~c_UpdatableFlags)) == 0, "Only updatable flags can be set."); // No locks necessary. Reordering won't happen due to volatile. _updatableFlags = flags; _updatableFlagsUsed = true; }
private static UriSyntaxFlags MapGenericParserOptions(GenericUriParserOptions options) { UriSyntaxFlags flags = UriSyntaxFlags.UnEscapeDotsAndSlashes | UriSyntaxFlags.CanonicalizeAsFilePath | UriSyntaxFlags.CompressPath | UriSyntaxFlags.ConvertPathSlashes | UriSyntaxFlags.PathIsRooted | UriSyntaxFlags.AllowAnInternetHost | UriSyntaxFlags.AllowUncHost | UriSyntaxFlags.MayHaveFragment | UriSyntaxFlags.MayHaveQuery | UriSyntaxFlags.MayHavePath | UriSyntaxFlags.MayHavePort | UriSyntaxFlags.MayHaveUserInfo | UriSyntaxFlags.MustHaveAuthority; if ((options & GenericUriParserOptions.GenericAuthority) != GenericUriParserOptions.Default) { flags &= ~(UriSyntaxFlags.AllowAnInternetHost | UriSyntaxFlags.AllowUncHost | UriSyntaxFlags.MayHavePort | UriSyntaxFlags.MayHaveUserInfo); flags |= UriSyntaxFlags.AllowAnyOtherHost; } if ((options & GenericUriParserOptions.AllowEmptyAuthority) != GenericUriParserOptions.Default) { flags |= UriSyntaxFlags.AllowEmptyHost; } if ((options & GenericUriParserOptions.NoUserInfo) != GenericUriParserOptions.Default) { flags &= ~UriSyntaxFlags.MayHaveUserInfo; } if ((options & GenericUriParserOptions.NoPort) != GenericUriParserOptions.Default) { flags &= ~UriSyntaxFlags.MayHavePort; } if ((options & GenericUriParserOptions.NoQuery) != GenericUriParserOptions.Default) { flags &= ~UriSyntaxFlags.MayHaveQuery; } if ((options & GenericUriParserOptions.NoFragment) != GenericUriParserOptions.Default) { flags &= ~UriSyntaxFlags.MayHaveFragment; } if ((options & GenericUriParserOptions.DontConvertPathBackslashes) != GenericUriParserOptions.Default) { flags &= ~UriSyntaxFlags.ConvertPathSlashes; } if ((options & GenericUriParserOptions.DontCompressPath) != GenericUriParserOptions.Default) { flags &= ~(UriSyntaxFlags.CanonicalizeAsFilePath | UriSyntaxFlags.CompressPath); } if ((options & GenericUriParserOptions.DontUnescapePathDotsAndSlashes) != GenericUriParserOptions.Default) { flags &= ~UriSyntaxFlags.UnEscapeDotsAndSlashes; } if ((options & GenericUriParserOptions.Idn) != GenericUriParserOptions.Default) { flags |= UriSyntaxFlags.AllowIdn; } if ((options & GenericUriParserOptions.IriParsing) != GenericUriParserOptions.Default) { flags |= UriSyntaxFlags.AllowIriParsing; } return(flags); }
private bool IsFullMatch(UriSyntaxFlags flags, UriSyntaxFlags expected) { UriSyntaxFlags flags2; if (((flags & UriSyntaxFlags.UnEscapeDotsAndSlashes) == UriSyntaxFlags.None) || !this.m_UpdatableFlagsUsed) { flags2 = this.m_Flags; } else { flags2 = (this.m_Flags & ~UriSyntaxFlags.UnEscapeDotsAndSlashes) | ((UriSyntaxFlags)this.m_UpdatableFlags); } return((flags2 & flags) == expected); }
// Public members public static void SetCanonicalizeAsFilePath(bool enabled) { // .NET 4.0's Uri class implementation doesn't work correctly for URIs that contain trailing periods (fixed in .NET 4.5). // https://stackoverflow.com/questions/856885/httpwebrequest-to-url-with-dot-at-the-end // The solution below is the one given in the official bug report, as given here: https://stackoverflow.com/a/2285321 (Jon Davis) MethodInfo getSyntax = typeof(UriParser).GetMethod("GetSyntax", BindingFlags.Static | BindingFlags.NonPublic); FieldInfo flagsField = typeof(UriParser).GetField("m_Flags", BindingFlags.Instance | BindingFlags.NonPublic); if (getSyntax is object && flagsField is object) { foreach (string scheme in new[] { "http", "https" }) { UriParser parser = (UriParser)getSyntax.Invoke(null, new object[] { scheme }); if (parser is object) { UriSyntaxFlags flagsValue = (UriSyntaxFlags)flagsField.GetValue(parser); if (enabled) { // Set the CanonicalizeAsFilePath flag if (!flagsValue.HasFlag(UriSyntaxFlags.CanonicalizeAsFilePath)) { flagsField.SetValue(parser, flagsValue | UriSyntaxFlags.CanonicalizeAsFilePath); } } else { // Clear the CanonicalizeAsFilePath flag if (flagsValue.HasFlag(UriSyntaxFlags.CanonicalizeAsFilePath)) { flagsField.SetValue(parser, flagsValue & ~UriSyntaxFlags.CanonicalizeAsFilePath); } } } } } }
private bool IsFullMatch(UriSyntaxFlags flags, UriSyntaxFlags expected) { // Return true, if masking the current set of flags with 'flags' equals 'expected'. // Definition 'current set of flags': // a) if updatable flags were never set: m_Flags // b) if updatable flags were set: set union between all flags in m_Flags which are not updatable // (i.e. not part of c_UpdatableFlags) and all flags in m_UpdatableFlags UriSyntaxFlags mergedFlags; // if none of the flags in 'flags' is an updatable flag, we ignore m_UpdatableFlags if (((flags & c_UpdatableFlags) == 0) || !_updatableFlagsUsed) { mergedFlags = _flags; } else { // mask m_Flags to only use the flags not in c_UpdatableFlags mergedFlags = (_flags & (~c_UpdatableFlags)) | _updatableFlags; } return((mergedFlags & flags) == expected); }
internal bool NotAny(UriSyntaxFlags flags) { return(this.IsFullMatch(flags, UriSyntaxFlags.None)); }
internal bool NotAny(UriSyntaxFlags flags) { // Return true if none of the flags specified in 'flags' are set. return(IsFullMatch(flags, UriSyntaxFlags.None)); }
internal bool IsAllSet(UriSyntaxFlags flags) { // Return true if all flags in 'flags' are set. return(IsFullMatch(flags, flags)); }
// // Internal .ctor, any ctor eventually goes through this one // internal UriParser(UriSyntaxFlags flags) { _flags = flags; _scheme = string.Empty; }
internal bool InFact(UriSyntaxFlags flags) { return(!this.IsFullMatch(flags, UriSyntaxFlags.None)); }
internal bool NotAny(UriSyntaxFlags flags) { // Return true if none of the flags specified in 'flags' are set. return IsFullMatch(flags, UriSyntaxFlags.None); }
internal bool IsAllSet(UriSyntaxFlags flags) { // Return true if all flags in 'flags' are set. return IsFullMatch(flags, flags); }
internal void SetUpdatableFlags(UriSyntaxFlags flags) { this.m_UpdatableFlags = flags; this.m_UpdatableFlagsUsed = true; }
// internal bool NotAny(UriSyntaxFlags flags) { return (m_Flags & flags) == 0; }
private bool IsFullMatch(UriSyntaxFlags flags, UriSyntaxFlags expected) { UriSyntaxFlags flags2; if (((flags & UriSyntaxFlags.UnEscapeDotsAndSlashes) == UriSyntaxFlags.None) || !this.m_UpdatableFlagsUsed) { flags2 = this.m_Flags; } else { flags2 = (this.m_Flags & ~UriSyntaxFlags.UnEscapeDotsAndSlashes) | ((UriSyntaxFlags) this.m_UpdatableFlags); } return ((flags2 & flags) == expected); }
internal bool NotAny(UriSyntaxFlags flags) { return this.IsFullMatch(flags, UriSyntaxFlags.None); }
internal bool IsAllSet(UriSyntaxFlags flags) { return this.IsFullMatch(flags, flags); }
internal bool InFact(UriSyntaxFlags flags) { return !this.IsFullMatch(flags, UriSyntaxFlags.None); }
private bool IsFullMatch(UriSyntaxFlags flags, UriSyntaxFlags expected) { return((_flags & flags) == expected); }
// internal bool InFact(UriSyntaxFlags flags) { return (m_Flags & flags) != 0; }
// internal bool InFact(UriSyntaxFlags flags) { return((m_Flags & flags) != 0); }
// internal bool IsAllSet(UriSyntaxFlags flags) { return (m_Flags & flags) == flags; }
internal bool InFact(UriSyntaxFlags flags) { // Return true if at least one of the flags in 'flags' is set. return !IsFullMatch(flags, UriSyntaxFlags.None); }
// // Internal .ctor, any ctor eventually goes through this one // internal UriParser(UriSyntaxFlags flags) { m_Flags = flags; m_Scheme = string.Empty; }
private bool IsFullMatch(UriSyntaxFlags flags, UriSyntaxFlags expected) { // Return true, if masking the current set of flags with 'flags' equals 'expected'. // Definition 'current set of flags': // a) if updatable flags were never set: m_Flags // b) if updatable flags were set: set union between all flags in m_Flags which are not updatable // (i.e. not part of c_UpdatableFlags) and all flags in m_UpdatableFlags UriSyntaxFlags mergedFlags; // if none of the flags in 'flags' is an updatable flag, we ignore m_UpdatableFlags if (((flags & c_UpdatableFlags) == 0) || !_updatableFlagsUsed) { mergedFlags = _flags; } else { // mask m_Flags to only use the flags not in c_UpdatableFlags mergedFlags = (_flags & (~c_UpdatableFlags)) | _updatableFlags; } return (mergedFlags & flags) == expected; }
// internal bool NotAny(UriSyntaxFlags flags) { return((m_Flags & flags) == 0); }
// internal bool IsAllSet(UriSyntaxFlags flags) { return((m_Flags & flags) == flags); }
internal bool InFact(UriSyntaxFlags flags) { // Return true if at least one of the flags in 'flags' is set. return(!IsFullMatch(flags, UriSyntaxFlags.None)); }
} // Dummy constructor internal BuiltInUriParser(string lwrCaseScheme, int defaultPort, UriSyntaxFlags syntaxFlags) { } // 0x0000000180AF5E90-0x0000000180AF5F30
internal bool IsAllSet(UriSyntaxFlags flags) { return(this.IsFullMatch(flags, flags)); }
// internal void CheckSetIsSimpleFlag() { Type type = this.GetType(); if ( type == typeof(GenericUriParser) || type == typeof(HttpStyleUriParser) || type == typeof(FtpStyleUriParser) || type == typeof(FileStyleUriParser) || type == typeof(NewsStyleUriParser) || type == typeof(GopherStyleUriParser) || type == typeof(NetPipeStyleUriParser) || type == typeof(NetTcpStyleUriParser) || type == typeof(LdapStyleUriParser) ) { m_Flags |= UriSyntaxFlags.SimpleUserSyntax; } }
} // 0x00000001809CC780-0x00000001809CD240 internal UriParser(UriSyntaxFlags flags) { } // 0x00000001809CD240-0x00000001809CD2A0