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

70 lines
1002 B
Go

package pop
import (
csm "git.loafle.net/commons/service_matcher-go"
)
const (
COMPARE_STR = "+OK"
)
type POPMatcher struct {
csm.Matchers
}
func (p *POPMatcher) Key() string {
return "POP3"
}
func (p *POPMatcher) String() string {
return "POP3"
}
func (p *POPMatcher) IsPrePacket() bool {
return true
}
func (p *POPMatcher) HasResponse(index int) bool {
return true
}
func (p *POPMatcher) IsError(info csm.MatchInfo, index int, packet *csm.Packet) bool {
return false
}
func (p *POPMatcher) Match(info csm.MatchInfo, index int, packet *csm.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() csm.Matcher {
m := &POPMatcher{}
reqStr := "QUIT\r\n"
byte := make([]byte, len(reqStr))
copy(byte[:], reqStr)
m.AddPacket(csm.NewPacket(byte, len(reqStr)))
return m
}