public Selector(string str) { string[] parts = str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); Source = new HostPredicate(parts[0]); Destination = new HostPredicate(parts[1]); Type = parts[2] == "*" ? TypePredicate.All : (TypePredicate)Enum.Parse(typeof(TypePredicate), parts[2], true); }
private bool IsSubDomainCore(HostPredicate other) { if (other.HostType == UriHostNameType.Basic) { return(false); } if (IsIP) { return(Value == other.Value); } if (IsDomain) { //可能一个主机谓词是com,另一个是google.com,则后者被会判断为前者的子域名。 //如果要严谨一点,需要调用DomainParser,这个调用很慢。 var longSubDomainSegments = Value.Split('.'); var shortSubDomainSegments = other.Value.Split('.'); for (int i = longSubDomainSegments.Length - 1, j = shortSubDomainSegments.Length - 1; i >= 0 && j >= 0; i--, j--) { if (longSubDomainSegments[i] != shortSubDomainSegments[j]) { return(false); } } return(true); } throw new NotSupportedException($"不能对{Value}调用{nameof(IsSubDomain)}()。"); }
/// <summary> /// 返回null表示部分包含。*和1st-party是这种情况。 /// </summary> /// <param name="other"></param> /// <returns></returns> public bool?Covers(HostPredicate other) { if (Value == "1st-party" || other.Value == "1st-party") { return(null); } return(Value == "*" || other.Value.EndsWith(Value)); }
public UMatrixRule(string line) { string[] parts = line.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); var source = new HostPredicate(parts[0]); var destination = new HostPredicate(parts[1]); var type = parts[2] == "*" ? uMatrixCleaner.TypePredicate.All : (TypePredicate)Enum.Parse(typeof(TypePredicate), parts[2], true); Selector = new Selector(source, destination, type); IsAllow = parts[3] == "allow"; }
public UMatrixRule(HostPredicate source, HostPredicate destination, TypePredicate type, bool isAllow) { if (HostPredicate.N1stParty.Equals(source)) { throw new ArgumentException("source不能为1st-party。"); } Selector = new Selector(source, destination, type); IsAllow = isAllow; }
/// <summary> /// 自己是自己的子域名 /// </summary> /// <param name="other"></param> /// <returns></returns> public bool IsSubDomain(HostPredicate other) { Debug.Assert(IsDomain == false || this.IsSubDomainCore(this)); return(IsSubDomainCore(other)); }
public Selector(HostPredicate source, HostPredicate destination, TypePredicate type) { Source = source; Destination = destination; Type = type; }
public Selector(HostPredicate source, HostPredicate destination, TypePredicate type, Selector selector) : this(source, destination, type) { this.originalRule = selector; }