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