-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathwhitelist_private.go
59 lines (52 loc) · 1.09 KB
/
whitelist_private.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package dnsp
import "strings"
func (s *Server) privateHostEntries() []string {
s.m.RLock()
defer s.m.RUnlock()
result := []string{}
for host := range s.privateHosts {
result = append(result, host)
}
for host := range s.privateHostsRX {
result = append(result, host)
}
return result
}
func (s *Server) addPrivateHostEntry(host string) {
if host == "" {
return
}
if host[len(host)-1] != '.' {
host += "."
}
if !strings.ContainsRune(host, '*') {
// Plain host string:
s.m.Lock()
s.privateHosts[host] = struct{}{}
s.m.Unlock()
} else if rx := compilePattern(host); rx != nil {
// Host pattern (regex):
s.m.Lock()
s.privateHostsRX[rx.String()] = rx
s.m.Unlock()
}
}
func (s *Server) removePrivateHostEntry(host string) {
if host == "" {
return
}
if host[len(host)-1] != '.' {
host += "."
}
if !strings.ContainsRune(host, '*') {
// Plain host string:
s.m.Lock()
delete(s.privateHosts, host)
s.m.Unlock()
} else if rx := compilePattern(host); rx != nil {
// Host pattern (regex):
s.m.Lock()
delete(s.privateHostsRX, rx.String())
s.m.Unlock()
}
}