Archived
1
0
This repository has been archived on 2023-08-12. You can view files and clone it, but cannot push or open issues or pull requests.
nntpchan/contrib/backends/srndv2/src/srnd/policy.go

40 lines
577 B
Go
Raw Normal View History

//
// policy.go
//
package srnd
import (
"regexp"
2017-04-23 16:53:56 +05:00
"strings"
)
type FeedPolicy struct {
rules map[string]string
}
// do we allow this newsgroup?
func (self *FeedPolicy) AllowsNewsgroup(newsgroup string) (result bool) {
var k, v string
2017-04-23 17:07:17 +05:00
var allows int
for k, v = range self.rules {
2017-04-23 16:53:56 +05:00
v = strings.Trim(v, " ")
match, err := regexp.MatchString(k, newsgroup)
2017-04-23 16:53:56 +05:00
if err == nil {
if match {
if v == "1" {
allows++
} else if v == "0" {
2017-04-23 17:05:21 +05:00
return false
2017-04-23 16:53:56 +05:00
}
}
}
}
if len(self.rules) > 0 {
result = allows > 0
} else {
result = true
}
2017-04-23 16:53:56 +05:00
return
}