clash/rule/logic/not.go

57 lines
1,004 B
Go
Raw Normal View History

package logic
import (
"fmt"
C "github.com/Dreamacro/clash/constant"
2022-03-17 15:24:07 +00:00
"github.com/Dreamacro/clash/rule/common"
)
type NOT struct {
*common.Base
rule C.Rule
payload string
adapter string
}
2022-03-15 16:43:08 +00:00
func (not *NOT) ShouldFindProcess() bool {
return false
}
func NewNOT(payload string, adapter string) (*NOT, error) {
not := &NOT{Base: &common.Base{}, payload: payload, adapter: adapter}
2022-04-15 16:21:08 +00:00
rule, err := parseRuleByPayload(payload)
if err != nil {
return nil, err
}
2022-04-15 16:21:08 +00:00
if len(rule) > 1 {
return nil, fmt.Errorf("not rule can contain at most one rule")
}
if len(rule) > 0 {
not.rule = rule[0]
}
return not, nil
}
func (not *NOT) RuleType() C.RuleType {
return C.NOT
}
func (not *NOT) Match(metadata *C.Metadata) bool {
2022-04-15 16:21:08 +00:00
return not.rule == nil || !not.rule.Match(metadata)
}
func (not *NOT) Adapter() string {
return not.adapter
}
func (not *NOT) Payload() string {
return not.payload
}
func (not *NOT) ShouldResolveIP() bool {
2022-04-15 16:21:08 +00:00
return not.rule != nil && not.rule.ShouldResolveIP()
}