mirror of
https://gitclone.com/github.com/MetaCubeX/Clash.Meta
synced 2025-02-23 06:33:14 +08:00
feat: add DOMAIN-REGEX
rule
This commit is contained in:
parent
fad1a08378
commit
234a4bfc93
@ -5,6 +5,7 @@ const (
|
|||||||
Domain RuleType = iota
|
Domain RuleType = iota
|
||||||
DomainSuffix
|
DomainSuffix
|
||||||
DomainKeyword
|
DomainKeyword
|
||||||
|
DomainRegex
|
||||||
GEOSITE
|
GEOSITE
|
||||||
GEOIP
|
GEOIP
|
||||||
IPCIDR
|
IPCIDR
|
||||||
@ -40,6 +41,8 @@ func (rt RuleType) String() string {
|
|||||||
return "DomainSuffix"
|
return "DomainSuffix"
|
||||||
case DomainKeyword:
|
case DomainKeyword:
|
||||||
return "DomainKeyword"
|
return "DomainKeyword"
|
||||||
|
case DomainRegex:
|
||||||
|
return "DomainRegex"
|
||||||
case GEOSITE:
|
case GEOSITE:
|
||||||
return "GeoSite"
|
return "GeoSite"
|
||||||
case GEOIP:
|
case GEOIP:
|
||||||
|
42
rules/common/domain_regex.go
Normal file
42
rules/common/domain_regex.go
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
package common
|
||||||
|
|
||||||
|
import (
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
C "github.com/metacubex/mihomo/constant"
|
||||||
|
)
|
||||||
|
|
||||||
|
type DomainRegex struct {
|
||||||
|
*Base
|
||||||
|
regex string
|
||||||
|
adapter string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (dr *DomainRegex) RuleType() C.RuleType {
|
||||||
|
return C.DomainRegex
|
||||||
|
}
|
||||||
|
|
||||||
|
func (dr *DomainRegex) Match(metadata *C.Metadata) (bool, string) {
|
||||||
|
domain := metadata.RuleHost()
|
||||||
|
match, _ := regexp.MatchString(dr.regex, domain)
|
||||||
|
return match, dr.adapter
|
||||||
|
}
|
||||||
|
|
||||||
|
func (dr *DomainRegex) Adapter() string {
|
||||||
|
return dr.adapter
|
||||||
|
}
|
||||||
|
|
||||||
|
func (dr *DomainRegex) Payload() string {
|
||||||
|
return dr.regex
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewDomainRegex(regex string, adapter string) *DomainRegex {
|
||||||
|
return &DomainRegex{
|
||||||
|
Base: &Base{},
|
||||||
|
regex: strings.ToLower(regex),
|
||||||
|
adapter: adapter,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//var _ C.Rule = (*DomainRegex)(nil)
|
@ -2,7 +2,7 @@ package rules
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
C "github.com/metacubex/mihomo/constant"
|
C "github.com/metacubex/mihomo/constant"
|
||||||
RC "github.com/metacubex/mihomo/rules/common"
|
RC "github.com/metacubex/mihomo/rules/common"
|
||||||
"github.com/metacubex/mihomo/rules/logic"
|
"github.com/metacubex/mihomo/rules/logic"
|
||||||
@ -17,6 +17,8 @@ func ParseRule(tp, payload, target string, params []string, subRules map[string]
|
|||||||
parsed = RC.NewDomainSuffix(payload, target)
|
parsed = RC.NewDomainSuffix(payload, target)
|
||||||
case "DOMAIN-KEYWORD":
|
case "DOMAIN-KEYWORD":
|
||||||
parsed = RC.NewDomainKeyword(payload, target)
|
parsed = RC.NewDomainKeyword(payload, target)
|
||||||
|
case "DOMAIN-REGEX":
|
||||||
|
parsed = RC.NewDomainRegex(payload, target)
|
||||||
case "GEOSITE":
|
case "GEOSITE":
|
||||||
parsed, parseErr = RC.NewGEOSITE(payload, target)
|
parsed, parseErr = RC.NewGEOSITE(payload, target)
|
||||||
case "GEOIP":
|
case "GEOIP":
|
||||||
|
Loading…
Reference in New Issue
Block a user