mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2026-10-29 08:07:03 +09:00
Squashed commit of the following: commit 8606668738add53456063aa8f68ded3812170df3 Merge: 9aff68363b60af4bf3Author: f.setrakov <f.setrakov@adguard.com> Date: Wed May 13 11:45:39 2026 +0300 Merge branch 'master' into AGDNS-3951-querylog-search-criterion commit 9aff6836320a8313900101311adaa28ac826c53e Author: f.setrakov <f.setrakov@adguard.com> Date: Fri May 8 17:40:09 2026 +0300 querylog: rm unicode check commit b093974b08cf02ea42baf492690ad64c93879fa5 Author: f.setrakov <f.setrakov@adguard.com> Date: Fri May 8 16:12:41 2026 +0300 all: imp code commit 2b2c35708ba009e2e93fdd46674311b976c1a123 Author: f.setrakov <f.setrakov@adguard.com> Date: Thu May 7 16:39:20 2026 +0300 all: imp docs, tests commit c1d1fd8294972f66e4333c44309ca65e1a4495d7 Author: f.setrakov <f.setrakov@adguard.com> Date: Wed May 6 15:16:30 2026 +0300 all: imp docs, quick match commit 2cb80fd6b7a7bb2e6eae359b3596f24299c4c817 Merge: 17fac082de5c79502fAuthor: f.setrakov <f.setrakov@adguard.com> Date: Tue May 5 12:56:41 2026 +0300 Merge branch 'master' into AGDNS-3951-querylog-search-criterion commit 17fac082d98b31a3b31e915496a75b4be85102a0 Author: f.setrakov <f.setrakov@adguard.com> Date: Tue May 5 12:50:51 2026 +0300 all: imp code commit 3d093cc9886f0ec5c1ac74fa3e7069edb925963f Author: f.setrakov <f.setrakov@adguard.com> Date: Mon May 4 17:51:45 2026 +0300 all: add tests commit 2a33db2182811dbeb24311a72734d9be46d155c6 Author: f.setrakov <f.setrakov@adguard.com> Date: Wed Apr 29 19:10:02 2026 +0300 all: add reason criterion
100 lines
2.7 KiB
Go
100 lines
2.7 KiB
Go
package filtering
|
|
|
|
import (
|
|
"fmt"
|
|
"maps"
|
|
)
|
|
|
|
// Reason holds an enum detailing why it was filtered, allowed, or rewritten.
|
|
type Reason uint8
|
|
|
|
const (
|
|
// NotFilteredNotFound: the host was not find in any checks, default value
|
|
// for results.
|
|
NotFilteredNotFound Reason = iota
|
|
|
|
// NotFilteredAllowList: the host is explicitly allowed.
|
|
NotFilteredAllowList
|
|
|
|
// NotFilteredError is returned when there was an error during checking.
|
|
// Reserved, currently unused.
|
|
NotFilteredError
|
|
|
|
// FilteredBlockList: the host was matched to be advertising host.
|
|
FilteredBlockList
|
|
|
|
// FilteredSafeBrowsing: the host was matched to be malicious/phishing.
|
|
FilteredSafeBrowsing
|
|
|
|
// FilteredParental: the host was matched to be outside of parental control
|
|
// settings.
|
|
FilteredParental
|
|
|
|
// FilteredInvalid: the request was invalid and was not processed.
|
|
FilteredInvalid
|
|
|
|
// FilteredSafeSearch: the host was replaced with safesearch variant.
|
|
FilteredSafeSearch
|
|
|
|
// FilteredBlockedService: the host is blocked by the blocked services
|
|
// feature.
|
|
FilteredBlockedService
|
|
|
|
// Rewritten is returned when there was a rewrite by a legacy DNS rewrite
|
|
// rule.
|
|
Rewritten
|
|
|
|
// RewrittenAutoHosts is returned when there was a rewrite by /etc/hosts.
|
|
RewrittenAutoHosts
|
|
|
|
// RewrittenRule is returned when a $dnsrewrite filter rule was applied.
|
|
//
|
|
// TODO(a.garipov): Remove [Rewritten] and [RewrittenAutoHosts] by merging
|
|
// their functionality into RewrittenRule.
|
|
//
|
|
// See https://github.com/AdguardTeam/AdGuardHome/issues/2499.
|
|
RewrittenRule
|
|
)
|
|
|
|
// reasonNames maps reason values to their string representations.
|
|
//
|
|
// TODO(a.garipov): Resync with actual code names or replace completely in the
|
|
// next version of HTTP API.
|
|
var reasonNames = []string{
|
|
NotFilteredNotFound: "NotFilteredNotFound",
|
|
NotFilteredAllowList: "NotFilteredWhiteList",
|
|
NotFilteredError: "NotFilteredError",
|
|
|
|
FilteredBlockList: "FilteredBlackList",
|
|
FilteredSafeBrowsing: "FilteredSafeBrowsing",
|
|
FilteredParental: "FilteredParental",
|
|
FilteredInvalid: "FilteredInvalid",
|
|
FilteredSafeSearch: "FilteredSafeSearch",
|
|
FilteredBlockedService: "FilteredBlockedService",
|
|
|
|
Rewritten: "Rewrite",
|
|
RewrittenAutoHosts: "RewriteEtcHosts",
|
|
RewrittenRule: "RewriteRule",
|
|
}
|
|
|
|
// ReasonByName maps reason string names to their values.
|
|
var ReasonByName = maps.Collect(func(yield func(string, Reason) (ok bool)) {
|
|
for i, name := range reasonNames {
|
|
if !yield(name, Reason(i)) {
|
|
break
|
|
}
|
|
}
|
|
})
|
|
|
|
// type check
|
|
var _ fmt.Stringer = NotFilteredNotFound
|
|
|
|
// String implements the [fmt.Stringer] interface for Reason.
|
|
func (r Reason) String() (s string) {
|
|
if int(r) >= len(reasonNames) {
|
|
return ""
|
|
}
|
|
|
|
return reasonNames[r]
|
|
}
|