mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2024-09-06 09:02:32 +00:00
42 lines
1 KiB
Go
42 lines
1 KiB
Go
package rules
|
|
|
|
import (
|
|
C "github.com/Dreamacro/clash/constant"
|
|
RC "github.com/Dreamacro/clash/rules/common"
|
|
"github.com/Dreamacro/clash/rules/logic"
|
|
RP "github.com/Dreamacro/clash/rules/provider"
|
|
"github.com/Dreamacro/clash/rules/ruleparser"
|
|
)
|
|
|
|
func ParseRule(tp, payload, target string, params []string) (parsed C.Rule, parseErr error) {
|
|
switch tp {
|
|
case "AND":
|
|
parsed, parseErr = logic.NewAND(payload, target)
|
|
case "OR":
|
|
parsed, parseErr = logic.NewOR(payload, target)
|
|
case "NOT":
|
|
parsed, parseErr = logic.NewNOT(payload, target)
|
|
case "RULE-SET":
|
|
noResolve := RC.HasNoResolve(params)
|
|
parsed, parseErr = RP.NewRuleSet(payload, target, noResolve)
|
|
case "MATCH":
|
|
parsed = RC.NewMatch(target)
|
|
parseErr = nil
|
|
default:
|
|
parsed, parseErr = ruleparser.ParseSameRule(tp, payload, target, params)
|
|
}
|
|
|
|
if parseErr != nil {
|
|
return nil, parseErr
|
|
}
|
|
|
|
ruleExtra := &C.RuleExtra{
|
|
Network: RC.FindNetwork(params),
|
|
SourceIPs: RC.FindSourceIPs(params),
|
|
ProcessNames: RC.FindProcessName(params),
|
|
}
|
|
|
|
parsed.SetRuleExtra(ruleExtra)
|
|
|
|
return
|
|
}
|