service_matcher-go/lpd/lpd.go
crusader 6ce87348ba ing
2018-09-03 15:42:56 +09:00

60 lines
994 B
Go

package lpd
import (
osm "git.loafle.net/overflow/service_matcher-go"
)
type LPDMatcher struct {
osm.Matchers
meta osm.Metadata
}
func (l *LPDMatcher) Key() string {
return "LPD"
}
func (l *LPDMatcher) Meta() osm.Metadata {
return l.meta
}
func (l *LPDMatcher) Name() string {
return "LPD (Printer)"
}
func (l *LPDMatcher) IsPrePacket() bool {
return false
}
func (l *LPDMatcher) HasResponse(index int) bool {
return true
}
func (l *LPDMatcher) IsError(info osm.MatchInfo, index int, packet *osm.Packet) bool {
return false
}
func (l *LPDMatcher) Match(info osm.MatchInfo, 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
}