overflow_discovery/service/matcher/pop/pop.go

66 lines
994 B
Go
Raw Normal View History

2017-11-21 12:47:55 +00:00
package pop
import (
"git.loafle.net/overflow/overflow_discovery/service/matcher"
)
const (
COMPARE_STR = "+OK"
)
type POPMatcher struct {
matcher.Matchers
}
func (p *POPMatcher) ServiceName() string {
2017-11-22 10:04:04 +00:00
return "POP3"
2017-11-21 12:47:55 +00:00
}
func (p *POPMatcher) IsPrePacket() bool {
return true
}
func (p *POPMatcher) HasResponse(index int) bool {
return true
}
func (p *POPMatcher) IsError(info matcher.MatchInfo, index int, packet *matcher.Packet) bool {
return false
}
func (p *POPMatcher) Match(info matcher.MatchInfo, index int, packet *matcher.Packet) bool {
switch index {
case 0:
fallthrough
case 1:
recvStr := string(packet.Buffer)
if len(recvStr) < 3 {
return false
}
compareStr := recvStr[0:3]
if compareStr == COMPARE_STR {
return true
}
}
return false
}
func NewMatcher() matcher.Matcher {
m := &POPMatcher{}
reqStr := "QUIT\r\n"
byte := make([]byte, len(reqStr))
copy(byte[:], reqStr)
m.AddPacket(matcher.NewPacket(byte, len(reqStr)))
return m
}