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

89 lines
1.5 KiB
Go

package pop
import (
osm "git.loafle.net/overflow/service_matcher-go"
)
const (
COMPARE_STR = "+OK"
)
type POPMatcher struct {
osm.Matchers
}
func (m *POPMatcher) Key(matchCtx *osm.MatchCtx) string {
return "POP3"
}
func (m *POPMatcher) Type(matchCtx *osm.MatchCtx) string {
return "MAIL"
}
func (m *POPMatcher) Vendor(matchCtx *osm.MatchCtx) string {
return "UNKNOWN"
}
func (m *POPMatcher) Version(matchCtx *osm.MatchCtx) string {
return "UNKNOWN"
}
func (m *POPMatcher) OsType(matchCtx *osm.MatchCtx) string {
return "UNKNOWN"
}
func (m *POPMatcher) OsVersion(matchCtx *osm.MatchCtx) string {
return "UNKNOWN"
}
func (m *POPMatcher) Name(matchCtx *osm.MatchCtx) string {
return "POP3"
}
func (m *POPMatcher) IsPrePacket() bool {
return true
}
func (m *POPMatcher) HasResponse(matchCtx *osm.MatchCtx, index int) bool {
return true
}
func (m *POPMatcher) IsError(matchCtx *osm.MatchCtx, index int, packet *osm.Packet) bool {
return false
}
func (m *POPMatcher) Match(matchCtx *osm.MatchCtx, index int, packet *osm.Packet) error {
switch index {
case 0:
fallthrough
case 1:
recvStr := string(packet.Bytes())
if len(recvStr) < 3 {
return osm.NotMatchedError()
}
compareStr := recvStr[0:3]
if compareStr == COMPARE_STR {
return nil
}
}
return osm.NotMatchedError()
}
func NewMatcher() osm.Matcher {
m := &POPMatcher{}
reqStr := "QUIT\r\n"
byte := make([]byte, len(reqStr))
copy(byte[:], reqStr)
m.AddPacket(osm.NewPacket(byte, len(reqStr)))
return m
}