forked from WhoJave/clash
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ensure that some expressions take effect
- Loading branch information
Showing
4 changed files
with
57 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package rules | ||
|
||
import ( | ||
C "github.com/metacubex/mihomo/constant" | ||
|
||
"github.com/dlclark/regexp2" | ||
) | ||
|
||
type DomainRegex struct { | ||
regex *regexp2.Regexp | ||
adapter string | ||
} | ||
|
||
func (dr *DomainRegex) RuleType() C.RuleType { | ||
return C.DomainRegex | ||
} | ||
|
||
func (dr *DomainRegex) Match(metadata *C.Metadata) (bool, string) { | ||
domain := metadata.RuleHost() | ||
match, _ := dr.regex.MatchString(domain) | ||
return match, dr.adapter | ||
} | ||
|
||
func (dr *DomainRegex) Adapter() string { | ||
return dr.adapter | ||
} | ||
|
||
func (dr *DomainRegex) Payload() string { | ||
return dr.regex.String() | ||
} | ||
|
||
func (dr *DomainRegex) ShouldResolveIP() bool { | ||
return false | ||
} | ||
|
||
func (dr *DomainRegex) ShouldFindProcess() bool { | ||
return false | ||
} | ||
|
||
func NewDomainRegex(regex string, adapter string) (*DomainRegex, error) { | ||
r, err := regexp2.Compile(regex, regexp2.IgnoreCase) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &DomainRegex{ | ||
regex: r, | ||
adapter: adapter, | ||
}, nil | ||
} | ||
|
||
//var _ C.Rule = (*DomainRegex)(nil) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters