network_service_matcher/pop/pop.go

66 lines
969 B
Go
Raw Normal View History

2017-12-04 07:27:08 +00:00
package pop
import (
cnsm "git.loafle.net/commons_go/network_service_matcher"
)
const (
COMPARE_STR = "+OK"
)
type POPMatcher struct {
cnsm.Matchers
}
func (p *POPMatcher) ServiceName() string {
return "POP3"
}
func (p *POPMatcher) IsPrePacket() bool {
return true
}
func (p *POPMatcher) HasResponse(index int) bool {
return true
}
func (p *POPMatcher) IsError(info cnsm.MatchInfo, index int, packet *cnsm.Packet) bool {
return false
}
func (p *POPMatcher) Match(info cnsm.MatchInfo, index int, packet *cnsm.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() cnsm.Matcher {
m := &POPMatcher{}
reqStr := "QUIT\r\n"
byte := make([]byte, len(reqStr))
copy(byte[:], reqStr)
m.AddPacket(cnsm.NewPacket(byte, len(reqStr)))
return m
}