github.com/yaling888/clash@v1.53.0/rule/process.go (about)

     1  package rules
     2  
     3  import (
     4  	"strings"
     5  
     6  	C "github.com/yaling888/clash/constant"
     7  )
     8  
     9  type Process struct {
    10  	*Base
    11  	adapter  string
    12  	process  string
    13  	nameOnly bool
    14  }
    15  
    16  func (ps *Process) RuleType() C.RuleType {
    17  	if ps.nameOnly {
    18  		return C.Process
    19  	}
    20  
    21  	return C.ProcessPath
    22  }
    23  
    24  func (ps *Process) Match(metadata *C.Metadata) bool {
    25  	if ps.nameOnly {
    26  		return strings.EqualFold(metadata.Process, ps.process)
    27  	}
    28  
    29  	return strings.EqualFold(metadata.ProcessPath, ps.process)
    30  }
    31  
    32  func (ps *Process) Adapter() string {
    33  	return ps.adapter
    34  }
    35  
    36  func (ps *Process) Payload() string {
    37  	return ps.process
    38  }
    39  
    40  func (ps *Process) ShouldResolveIP() bool {
    41  	return false
    42  }
    43  
    44  func (ps *Process) ShouldFindProcess() bool {
    45  	return true
    46  }
    47  
    48  func NewProcess(process string, adapter string, nameOnly bool) (*Process, error) {
    49  	return &Process{
    50  		Base:     &Base{},
    51  		adapter:  adapter,
    52  		process:  process,
    53  		nameOnly: nameOnly,
    54  	}, nil
    55  }
    56  
    57  var _ C.Rule = (*Process)(nil)