mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2024-11-16 19:56:51 +08:00
d6dc5ba19c
rules: - SUB-RULE,(AND,((NETWORK,TCP),(DOMAIN-KEYWORD,google))),TEST2 - SUB-RULE,(GEOIP,!CN),TEST1 - MATCH,DIRECT sub-rules: TEST2: - MATCH,Proxy TEST1: - RULE-SET,Local,DIRECT,no-resolve - GEOSITE,CN,Domestic - GEOIP,CN,Domestic - MATCH,Proxy
52 lines
1018 B
Go
52 lines
1018 B
Go
package common
|
|
|
|
import (
|
|
"golang.org/x/net/idna"
|
|
"strings"
|
|
|
|
C "github.com/Dreamacro/clash/constant"
|
|
)
|
|
|
|
type DomainKeyword struct {
|
|
*Base
|
|
keyword string
|
|
adapter string
|
|
isIDNA bool
|
|
}
|
|
|
|
func (dk *DomainKeyword) RuleType() C.RuleType {
|
|
return C.DomainKeyword
|
|
}
|
|
|
|
func (dk *DomainKeyword) Match(metadata *C.Metadata) (bool, string) {
|
|
if metadata.AddrType != C.AtypDomainName {
|
|
return false, ""
|
|
}
|
|
domain := metadata.Host
|
|
return strings.Contains(domain, dk.keyword), dk.adapter
|
|
}
|
|
|
|
func (dk *DomainKeyword) Adapter() string {
|
|
return dk.adapter
|
|
}
|
|
|
|
func (dk *DomainKeyword) Payload() string {
|
|
keyword := dk.keyword
|
|
if dk.isIDNA {
|
|
keyword, _ = idna.ToUnicode(keyword)
|
|
}
|
|
return keyword
|
|
}
|
|
|
|
func NewDomainKeyword(keyword string, adapter string) *DomainKeyword {
|
|
actualDomainKeyword, _ := idna.ToASCII(keyword)
|
|
return &DomainKeyword{
|
|
Base: &Base{},
|
|
keyword: strings.ToLower(actualDomainKeyword),
|
|
adapter: adapter,
|
|
isIDNA: keyword != actualDomainKeyword,
|
|
}
|
|
}
|
|
|
|
//var _ C.Rule = (*DomainKeyword)(nil)
|