service_matcher-go/lpd/lpd.go
2018-08-13 16:48:32 +09:00

60 lines
1017 B
Go

package lpd
import (
csm "git.loafle.net/commons/service_matcher-go"
)
type LPDMatcher struct {
csm.Matchers
meta csm.Metadata
}
func (l *LPDMatcher) Key() string {
return "LPD"
}
func (l *LPDMatcher) Meta() csm.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 csm.MatchInfo, index int, packet *csm.Packet) bool {
return false
}
func (l *LPDMatcher) Match(info csm.MatchInfo, index int, packet *csm.Packet) error {
if packet == nil || packet.Buffer == nil || packet.Len == 0 {
return csm.NoPacketReceivedError()
}
if packet.Len != 1 {
return csm.NotMatchedError()
}
return nil
}
func NewMatcher() csm.Matcher {
m := &LPDMatcher{}
reqStr := "GET / HTTP/1.1\r\n\r\n"
rbyte := make([]byte, len(reqStr))
copy(rbyte[:], reqStr)
m.AddPacket(csm.NewPacket(rbyte, len(reqStr)))
return m
}