service_matcher-go/lpd/lpd.go
crusader bce329e44e ing
2018-10-23 13:31:25 +09:00

74 lines
1.4 KiB
Go

package lpd
import (
osm "git.loafle.net/overflow/service_matcher-go"
)
type LPDMatcher struct {
osm.Matchers
}
func (m *LPDMatcher) Key(matchCtx *osm.MatchCtx) string {
return "LPD"
}
func (m *LPDMatcher) Type(matchCtx *osm.MatchCtx) string {
return "NETWORK"
}
func (m *LPDMatcher) Vendor(matchCtx *osm.MatchCtx) string {
return "UNKNOWN"
}
func (m *LPDMatcher) Version(matchCtx *osm.MatchCtx) string {
return "UNKNOWN"
}
func (m *LPDMatcher) OsType(matchCtx *osm.MatchCtx) string {
return "UNKNOWN"
}
func (m *LPDMatcher) OsVersion(matchCtx *osm.MatchCtx) string {
return "UNKNOWN"
}
func (m *LPDMatcher) Name(matchCtx *osm.MatchCtx) string {
return "LPD (Printer)"
}
func (m *LPDMatcher) IsPrePacket() bool {
return false
}
func (m *LPDMatcher) HasResponse(matchCtx *osm.MatchCtx, index int) bool {
return true
}
func (m *LPDMatcher) IsError(matchCtx *osm.MatchCtx, index int, packet *osm.Packet) bool {
return false
}
func (m *LPDMatcher) Match(matchCtx *osm.MatchCtx, index int, packet *osm.Packet) error {
if packet == nil || !packet.Valid() {
return osm.NoPacketReceivedError()
}
if packet.Len != 1 {
return osm.NotMatchedError()
}
return nil
}
func NewMatcher() osm.Matcher {
m := &LPDMatcher{}
reqStr := "GET / HTTP/1.1\r\n\r\n"
rbyte := make([]byte, len(reqStr))
copy(rbyte[:], reqStr)
m.AddPacket(osm.NewPacket(rbyte, len(reqStr)))
return m
}