mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-11-23 13:35:38 +03:00
2819d6cace
Updates #4016. Squashed commit of the following: commit 83bb15c5a5098103cd17e76b49f456fb4fa73408 Merge: 81905503313555b1
Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Dec 27 19:36:44 2021 +0300 Merge branch 'master' into 4016-rw-subdomain commit 81905503c977c004d7ddca1d4e7537bf76443a6e Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Dec 27 19:35:51 2021 +0300 filtering: fix self reqs commit b706f481f00232d28dade0bd747a7496753c7deb Merge: 29cf83de661f4ece
Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Dec 27 19:13:08 2021 +0300 Merge branch 'master' into 4016-rw-subdomain commit 29cf83de8e3ff60ea1c471c2a161055b1377392d Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Dec 27 19:07:08 2021 +0300 all: fix docs commit 9213fd8ec2b81e65b1198ab241400065f14684b1 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Dec 27 18:44:06 2021 +0300 filtering: fix rw to subdomain
60 lines
1.7 KiB
Go
60 lines
1.7 KiB
Go
package querylog
|
|
|
|
import "time"
|
|
|
|
// searchParams represent the search query sent by the client
|
|
type searchParams struct {
|
|
// searchCriteria - list of search criteria that we use to get filter results
|
|
searchCriteria []searchCriterion
|
|
|
|
// olderThen - return entries that are older than this value
|
|
// if not set - disregard it and return any value
|
|
olderThan time.Time
|
|
|
|
offset int // offset for the search
|
|
limit int // limit the number of records returned
|
|
maxFileScanEntries int // maximum log entries to scan in query log files. if 0 - no limit
|
|
}
|
|
|
|
// newSearchParams - creates an empty instance of searchParams
|
|
func newSearchParams() *searchParams {
|
|
return &searchParams{
|
|
// default max log entries to return
|
|
limit: 500,
|
|
|
|
// by default, we scan up to 50k entries at once
|
|
maxFileScanEntries: 50000,
|
|
}
|
|
}
|
|
|
|
// quickMatchClientFunc is a simplified client finder for quick matches.
|
|
type quickMatchClientFunc = func(clientID, ip string) (c *Client)
|
|
|
|
// quickMatch quickly checks if the line matches the given search parameters.
|
|
// It returns false if the line doesn't match. This method is only here for
|
|
// optimization purposes.
|
|
func (s *searchParams) quickMatch(line string, findClient quickMatchClientFunc) (ok bool) {
|
|
for _, c := range s.searchCriteria {
|
|
if !c.quickMatch(line, findClient) {
|
|
return false
|
|
}
|
|
}
|
|
|
|
return true
|
|
}
|
|
|
|
// match - checks if the logEntry matches the searchParams
|
|
func (s *searchParams) match(entry *logEntry) bool {
|
|
if !s.olderThan.IsZero() && !entry.Time.Before(s.olderThan) {
|
|
// Ignore entries newer than what was requested
|
|
return false
|
|
}
|
|
|
|
for _, c := range s.searchCriteria {
|
|
if !c.match(entry) {
|
|
return false
|
|
}
|
|
}
|
|
|
|
return true
|
|
}
|