mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-11-22 23:13:01 +00:00
Refine router config parse
This commit is contained in:
parent
68201a8898
commit
44317bd657
@ -44,20 +44,36 @@ func ParseDomainRule(domain string) ([]*dm.Domain, error) {
|
||||
domainRule := new(dm.Domain)
|
||||
switch {
|
||||
case strings.HasPrefix(domain, "regexp:"):
|
||||
regexpVal := domain[7:]
|
||||
if len(regexpVal) == 0 {
|
||||
return nil, newError("empty regexp type of rule: ", domain)
|
||||
}
|
||||
domainRule.Type = dm.MatchingType_Regex
|
||||
domainRule.Value = domain[7:]
|
||||
domainRule.Value = regexpVal
|
||||
|
||||
case strings.HasPrefix(domain, "domain:"):
|
||||
domainName := domain[7:]
|
||||
if len(domainName) == 0 {
|
||||
return nil, newError("empty domain type of rule: ", domain)
|
||||
}
|
||||
domainRule.Type = dm.MatchingType_Subdomain
|
||||
domainRule.Value = domain[7:]
|
||||
domainRule.Value = domainName
|
||||
|
||||
case strings.HasPrefix(domain, "full:"):
|
||||
fullVal := domain[5:]
|
||||
if len(fullVal) == 0 {
|
||||
return nil, newError("empty full domain type of rule: ", domain)
|
||||
}
|
||||
domainRule.Type = dm.MatchingType_Full
|
||||
domainRule.Value = domain[5:]
|
||||
domainRule.Value = fullVal
|
||||
|
||||
case strings.HasPrefix(domain, "keyword:"):
|
||||
keywordVal := domain[8:]
|
||||
if len(keywordVal) == 0 {
|
||||
return nil, newError("empty keyword type of rule: ", domain)
|
||||
}
|
||||
domainRule.Type = dm.MatchingType_Keyword
|
||||
domainRule.Value = domain[8:]
|
||||
domainRule.Value = keywordVal
|
||||
|
||||
case strings.HasPrefix(domain, "dotless:"):
|
||||
domainRule.Type = dm.MatchingType_Regex
|
||||
|
@ -1,5 +1,7 @@
|
||||
package geosite
|
||||
|
||||
import "strings"
|
||||
|
||||
type AttributeList struct {
|
||||
matcher []AttributeMatcher
|
||||
}
|
||||
@ -25,7 +27,7 @@ type BooleanMatcher string
|
||||
|
||||
func (m BooleanMatcher) Match(domain *Domain) bool {
|
||||
for _, attr := range domain.Attribute {
|
||||
if attr.Key == string(m) {
|
||||
if strings.EqualFold(attr.GetKey(), string(m)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
@ -261,21 +261,21 @@ func ParseRule(msg json.RawMessage) (*router.RoutingRule, error) {
|
||||
if err != nil {
|
||||
return nil, newError("invalid router rule").Base(err)
|
||||
}
|
||||
if rawRule.Type == "field" {
|
||||
if strings.EqualFold(rawRule.Type, "field") {
|
||||
fieldrule, err := parseFieldRule(msg)
|
||||
if err != nil {
|
||||
return nil, newError("invalid field rule").Base(err)
|
||||
}
|
||||
return fieldrule, nil
|
||||
}
|
||||
if rawRule.Type == "chinaip" {
|
||||
if strings.EqualFold(rawRule.Type, "chinaip") {
|
||||
chinaiprule, err := parseChinaIPRule(msg)
|
||||
if err != nil {
|
||||
return nil, newError("invalid chinaip rule").Base(err)
|
||||
}
|
||||
return chinaiprule, nil
|
||||
}
|
||||
if rawRule.Type == "chinasites" {
|
||||
if strings.EqualFold(rawRule.Type, "chinasites") {
|
||||
chinasitesrule, err := parseChinaSitesRule(msg)
|
||||
if err != nil {
|
||||
return nil, newError("invalid chinasites rule").Base(err)
|
||||
|
Loading…
Reference in New Issue
Block a user