Allow !~= for website/uri
This commit is contained in:
@@ -133,9 +133,11 @@ func indexOf(s string, b byte) int {
|
||||
// CompiledFilter wraps a pb.Filter with pre-compiled regular expressions.
|
||||
// Use CompileFilter to construct one before a query loop.
|
||||
type CompiledFilter struct {
|
||||
Proto *pb.Filter
|
||||
WebsiteRe *regexp.Regexp // nil if no website_regex or compilation failed
|
||||
URIRe *regexp.Regexp // nil if no uri_regex or compilation failed
|
||||
Proto *pb.Filter
|
||||
WebsiteRe *regexp.Regexp // nil if no website_regex or compilation failed
|
||||
URIRe *regexp.Regexp // nil if no uri_regex or compilation failed
|
||||
WebsiteReExcl *regexp.Regexp // nil if no website_regex_exclude or compilation failed
|
||||
URIReExcl *regexp.Regexp // nil if no uri_regex_exclude or compilation failed
|
||||
}
|
||||
|
||||
// CompileFilter compiles the regex fields in f once. Invalid regexes are
|
||||
@@ -161,6 +163,22 @@ func CompileFilter(f *pb.Filter) *CompiledFilter {
|
||||
cf.URIRe = re
|
||||
}
|
||||
}
|
||||
if f.WebsiteRegexExclude != nil {
|
||||
re, err := regexp.Compile(f.GetWebsiteRegexExclude())
|
||||
if err != nil {
|
||||
log.Printf("store: invalid website_regex_exclude %q: %v", f.GetWebsiteRegexExclude(), err)
|
||||
} else {
|
||||
cf.WebsiteReExcl = re
|
||||
}
|
||||
}
|
||||
if f.UriRegexExclude != nil {
|
||||
re, err := regexp.Compile(f.GetUriRegexExclude())
|
||||
if err != nil {
|
||||
log.Printf("store: invalid uri_regex_exclude %q: %v", f.GetUriRegexExclude(), err)
|
||||
} else {
|
||||
cf.URIReExcl = re
|
||||
}
|
||||
}
|
||||
return cf
|
||||
}
|
||||
|
||||
@@ -193,6 +211,18 @@ func MatchesFilter(t Tuple6, f *CompiledFilter) bool {
|
||||
if p.UriRegex != nil && f.URIRe == nil {
|
||||
return false
|
||||
}
|
||||
if f.WebsiteReExcl != nil && f.WebsiteReExcl.MatchString(t.Website) {
|
||||
return false
|
||||
}
|
||||
if p.WebsiteRegexExclude != nil && f.WebsiteReExcl == nil {
|
||||
return false
|
||||
}
|
||||
if f.URIReExcl != nil && f.URIReExcl.MatchString(t.URI) {
|
||||
return false
|
||||
}
|
||||
if p.UriRegexExclude != nil && f.URIReExcl == nil {
|
||||
return false
|
||||
}
|
||||
if p.HttpResponse != nil && !matchesStatusOp(t.Status, p.GetHttpResponse(), p.StatusOp) {
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user