2018-09-09 07:01:46 +00:00
|
|
|
package rules
|
|
|
|
|
|
|
|
import (
|
2018-11-21 05:59:39 +00:00
|
|
|
"strings"
|
|
|
|
|
2018-09-09 07:01:46 +00:00
|
|
|
C "github.com/Dreamacro/clash/constant"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Domain struct {
|
2021-11-17 08:03:47 +00:00
|
|
|
domain string
|
|
|
|
adapter string
|
|
|
|
ruleExtra *C.RuleExtra
|
2018-09-09 07:01:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Domain) RuleType() C.RuleType {
|
|
|
|
return C.Domain
|
|
|
|
}
|
|
|
|
|
2019-10-27 16:02:23 +00:00
|
|
|
func (d *Domain) Match(metadata *C.Metadata) bool {
|
2018-09-30 04:25:52 +00:00
|
|
|
if metadata.AddrType != C.AtypDomainName {
|
2018-09-09 07:01:46 +00:00
|
|
|
return false
|
|
|
|
}
|
2018-09-30 04:25:52 +00:00
|
|
|
return metadata.Host == d.domain
|
2018-09-09 07:01:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Domain) Adapter() string {
|
|
|
|
return d.adapter
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Domain) Payload() string {
|
|
|
|
return d.domain
|
|
|
|
}
|
|
|
|
|
2020-07-27 03:57:55 +00:00
|
|
|
func (d *Domain) ShouldResolveIP() bool {
|
|
|
|
return false
|
2019-10-27 16:02:23 +00:00
|
|
|
}
|
|
|
|
|
2021-11-17 08:03:47 +00:00
|
|
|
func (d *Domain) RuleExtra() *C.RuleExtra {
|
|
|
|
return d.ruleExtra
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewDomain(domain string, adapter string, ruleExtra *C.RuleExtra) *Domain {
|
2018-09-09 07:01:46 +00:00
|
|
|
return &Domain{
|
2021-11-17 08:03:47 +00:00
|
|
|
domain: strings.ToLower(domain),
|
|
|
|
adapter: adapter,
|
|
|
|
ruleExtra: ruleExtra,
|
2018-09-09 07:01:46 +00:00
|
|
|
}
|
|
|
|
}
|