From a276b17246ab989ad59411ed0ac69427a53d258f Mon Sep 17 00:00:00 2001 From: gVisor bot Date: Sat, 4 Jun 2022 03:22:41 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E8=B0=83=E6=95=B4parseRule=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rule/logic/common.go | 41 ++++++----------------------------------- 1 file changed, 6 insertions(+), 35 deletions(-) diff --git a/rule/logic/common.go b/rule/logic/common.go index 0f43e688..d3d68100 100644 --- a/rule/logic/common.go +++ b/rule/logic/common.go @@ -4,13 +4,14 @@ import ( "fmt" "github.com/Dreamacro/clash/common/collections" C "github.com/Dreamacro/clash/constant" - RC "github.com/Dreamacro/clash/rule/common" - RP "github.com/Dreamacro/clash/rule/provider" - "github.com/Dreamacro/clash/rule/ruleparser" "regexp" "strings" + _ "unsafe" ) +//go:linkname parseRule github.com/Dreamacro/clash/rules.ParseRule +func parseRule(tp, payload, target string, params []string) (parsed C.Rule, parseErr error) + func parseRuleByPayload(payload string) ([]C.Rule, error) { regex, err := regexp.Compile("\\(.*\\)") if err != nil { @@ -55,40 +56,10 @@ func payloadToRule(subPayload string) (C.Rule, error) { tp := splitStr[0] payload := splitStr[1] if tp == "NOT" || tp == "OR" || tp == "AND" { - return parseRule(tp, payload, nil) + return parseRule(tp, payload, "", nil) } param := strings.Split(payload, ",") - return parseRule(tp, param[0], param[1:]) -} - -func parseRule(tp, payload string, params []string) (parsed C.Rule, parseErr error) { - switch tp { - case "AND": - parsed, parseErr = NewAND(payload, "") - case "OR": - parsed, parseErr = NewOR(payload, "") - case "NOT": - parsed, parseErr = NewNOT(payload, "") - case "RULE-SET": - noResolve := RC.HasNoResolve(params) - parsed, parseErr = RP.NewRuleSet(payload, "", noResolve) - default: - parsed, parseErr = ruleparser.ParseSameRule(tp, payload, "", 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 parsed, nil + return parseRule(tp, param[0], "", param[1:]) } type Range struct {