github.com/sagernet/sing-box@v1.9.0-rc.20/route/rule_item_wifi_ssid.go (about) 1 package route 2 3 import ( 4 "strings" 5 6 "github.com/sagernet/sing-box/adapter" 7 F "github.com/sagernet/sing/common/format" 8 ) 9 10 var _ RuleItem = (*WIFISSIDItem)(nil) 11 12 type WIFISSIDItem struct { 13 ssidList []string 14 ssidMap map[string]bool 15 router adapter.Router 16 } 17 18 func NewWIFISSIDItem(router adapter.Router, ssidList []string) *WIFISSIDItem { 19 ssidMap := make(map[string]bool) 20 for _, ssid := range ssidList { 21 ssidMap[ssid] = true 22 } 23 return &WIFISSIDItem{ 24 ssidList, 25 ssidMap, 26 router, 27 } 28 } 29 30 func (r *WIFISSIDItem) Match(metadata *adapter.InboundContext) bool { 31 return r.ssidMap[r.router.WIFIState().SSID] 32 } 33 34 func (r *WIFISSIDItem) String() string { 35 if len(r.ssidList) == 1 { 36 return F.ToString("wifi_ssid=", r.ssidList[0]) 37 } 38 return F.ToString("wifi_ssid=[", strings.Join(r.ssidList, " "), "]") 39 }