github.com/chwjbn/xclash@v0.2.0/rule/parser.go (about) 1 package rules 2 3 import ( 4 "fmt" 5 6 C "github.com/chwjbn/xclash/constant" 7 ) 8 9 func ParseRule(tp, payload, target string, params []string) (C.Rule, error) { 10 var ( 11 parseErr error 12 parsed C.Rule 13 ) 14 15 switch tp { 16 case "DOMAIN": 17 parsed = NewDomain(payload, target) 18 case "DOMAIN-SUFFIX": 19 parsed = NewDomainSuffix(payload, target) 20 case "DOMAIN-KEYWORD": 21 parsed = NewDomainKeyword(payload, target) 22 case "GEOIP": 23 noResolve := HasNoResolve(params) 24 parsed = NewGEOIP(payload, target, noResolve) 25 case "IP-CIDR", "IP-CIDR6": 26 noResolve := HasNoResolve(params) 27 parsed, parseErr = NewIPCIDR(payload, target, WithIPCIDRNoResolve(noResolve)) 28 case "SRC-IP-CIDR": 29 parsed, parseErr = NewIPCIDR(payload, target, WithIPCIDRSourceIP(true), WithIPCIDRNoResolve(true)) 30 case "SRC-PORT": 31 parsed, parseErr = NewPort(payload, target, true) 32 case "DST-PORT": 33 parsed, parseErr = NewPort(payload, target, false) 34 case "PROCESS-NAME": 35 parsed, parseErr = NewProcess(payload, target) 36 case "MATCH": 37 parsed = NewMatch(target) 38 default: 39 parseErr = fmt.Errorf("unsupported rule type %s", tp) 40 } 41 42 return parsed, parseErr 43 }