2022-01-22 14:10:45 +00:00
|
|
|
package common
|
2020-12-17 14:17:27 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
C "github.com/Dreamacro/clash/constant"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Process struct {
|
2022-03-17 15:24:07 +00:00
|
|
|
*Base
|
|
|
|
adapter string
|
|
|
|
process string
|
|
|
|
nameOnly bool
|
2022-03-15 16:43:08 +00:00
|
|
|
}
|
|
|
|
|
2020-12-17 14:17:27 +00:00
|
|
|
func (ps *Process) RuleType() C.RuleType {
|
|
|
|
return C.Process
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ps *Process) Match(metadata *C.Metadata) bool {
|
2022-03-26 08:17:44 +00:00
|
|
|
if ps.nameOnly {
|
2021-11-17 08:03:47 +00:00
|
|
|
return strings.EqualFold(metadata.Process, ps.process)
|
|
|
|
}
|
2022-03-26 08:17:44 +00:00
|
|
|
return strings.EqualFold(metadata.ProcessPath, ps.process)
|
2020-12-17 14:17:27 +00:00
|
|
|
}
|
|
|
|
|
2021-03-23 17:00:21 +00:00
|
|
|
func (ps *Process) Adapter() string {
|
|
|
|
return ps.adapter
|
2020-12-17 14:17:27 +00:00
|
|
|
}
|
|
|
|
|
2021-03-23 17:00:21 +00:00
|
|
|
func (ps *Process) Payload() string {
|
|
|
|
return ps.process
|
2020-12-17 14:17:27 +00:00
|
|
|
}
|
|
|
|
|
2022-03-17 15:24:07 +00:00
|
|
|
func NewProcess(process string, adapter string, nameOnly bool) (*Process, error) {
|
2020-12-17 14:17:27 +00:00
|
|
|
return &Process{
|
2022-03-17 15:24:07 +00:00
|
|
|
Base: &Base{},
|
|
|
|
adapter: adapter,
|
|
|
|
process: process,
|
|
|
|
nameOnly: nameOnly,
|
2020-12-17 14:17:27 +00:00
|
|
|
}, nil
|
|
|
|
}
|