chore: add IN-USER
and IN-NAME
rules
This commit is contained in:
49
rules/common/in_name.go
Normal file
49
rules/common/in_name.go
Normal file
@ -0,0 +1,49 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
C "github.com/Dreamacro/clash/constant"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type InName struct {
|
||||
*Base
|
||||
names []string
|
||||
adapter string
|
||||
payload string
|
||||
}
|
||||
|
||||
func (u *InName) Match(metadata *C.Metadata) (bool, string) {
|
||||
for _, name := range u.names {
|
||||
if metadata.InName == name {
|
||||
return true, u.adapter
|
||||
}
|
||||
}
|
||||
return false, ""
|
||||
}
|
||||
|
||||
func (u *InName) RuleType() C.RuleType {
|
||||
return C.InName
|
||||
}
|
||||
|
||||
func (u *InName) Adapter() string {
|
||||
return u.adapter
|
||||
}
|
||||
|
||||
func (u *InName) Payload() string {
|
||||
return u.payload
|
||||
}
|
||||
|
||||
func NewInName(iNames, adapter string) (*InName, error) {
|
||||
names := strings.Split(iNames, "/")
|
||||
if len(names) == 0 {
|
||||
return nil, fmt.Errorf("in name couldn't be empty")
|
||||
}
|
||||
|
||||
return &InName{
|
||||
Base: &Base{},
|
||||
names: names,
|
||||
adapter: adapter,
|
||||
payload: iNames,
|
||||
}, nil
|
||||
}
|
@ -23,7 +23,7 @@ func (u *InType) Match(metadata *C.Metadata) (bool, string) {
|
||||
}
|
||||
|
||||
func (u *InType) RuleType() C.RuleType {
|
||||
return C.INTYPE
|
||||
return C.InType
|
||||
}
|
||||
|
||||
func (u *InType) Adapter() string {
|
||||
@ -37,7 +37,7 @@ func (u *InType) Payload() string {
|
||||
func NewInType(iTypes, adapter string) (*InType, error) {
|
||||
types := strings.Split(iTypes, "/")
|
||||
if len(types) == 0 {
|
||||
return nil, fmt.Errorf("in type could be empty")
|
||||
return nil, fmt.Errorf("in type couldn't be empty")
|
||||
}
|
||||
|
||||
tps, err := parseInTypes(types)
|
||||
|
49
rules/common/in_user.go
Normal file
49
rules/common/in_user.go
Normal file
@ -0,0 +1,49 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
C "github.com/Dreamacro/clash/constant"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type InUser struct {
|
||||
*Base
|
||||
users []string
|
||||
adapter string
|
||||
payload string
|
||||
}
|
||||
|
||||
func (u *InUser) Match(metadata *C.Metadata) (bool, string) {
|
||||
for _, user := range u.users {
|
||||
if metadata.InUser == user {
|
||||
return true, u.adapter
|
||||
}
|
||||
}
|
||||
return false, ""
|
||||
}
|
||||
|
||||
func (u *InUser) RuleType() C.RuleType {
|
||||
return C.InUser
|
||||
}
|
||||
|
||||
func (u *InUser) Adapter() string {
|
||||
return u.adapter
|
||||
}
|
||||
|
||||
func (u *InUser) Payload() string {
|
||||
return u.payload
|
||||
}
|
||||
|
||||
func NewInUser(iUsers, adapter string) (*InUser, error) {
|
||||
users := strings.Split(iUsers, "/")
|
||||
if len(users) == 0 {
|
||||
return nil, fmt.Errorf("in user couldn't be empty")
|
||||
}
|
||||
|
||||
return &InUser{
|
||||
Base: &Base{},
|
||||
users: users,
|
||||
adapter: adapter,
|
||||
payload: iUsers,
|
||||
}, nil
|
||||
}
|
@ -47,6 +47,10 @@ func ParseRule(tp, payload, target string, params []string, subRules map[string]
|
||||
parsed, parseErr = RC.NewUid(payload, target)
|
||||
case "IN-TYPE":
|
||||
parsed, parseErr = RC.NewInType(payload, target)
|
||||
case "IN-USER":
|
||||
parsed, parseErr = RC.NewInUser(payload, target)
|
||||
case "IN-NAME":
|
||||
parsed, parseErr = RC.NewInName(payload, target)
|
||||
case "SUB-RULE":
|
||||
parsed, parseErr = logic.NewSubRule(payload, target, subRules, ParseRule)
|
||||
case "AND":
|
||||
|
Reference in New Issue
Block a user