diff options
author | Wim <wim@42.be> | 2017-07-28 14:26:26 +0200 |
---|---|---|
committer | Wim <wim@42.be> | 2017-07-28 14:26:26 +0200 |
commit | 38d09dba2e02a3136ea202cea8b6df58dea19d1d (patch) | |
tree | 9108e0e1ad5db19c1d9cdb3eb1bbfc412b3fd91a /vendor/github.com/42wim/go-ircevent/irc_sasl.go | |
parent | fafd0c68e9d0b0db601465da2ab52ee8a47302e5 (diff) | |
download | matterbridge-msglm-38d09dba2e02a3136ea202cea8b6df58dea19d1d.tar.gz matterbridge-msglm-38d09dba2e02a3136ea202cea8b6df58dea19d1d.tar.bz2 matterbridge-msglm-38d09dba2e02a3136ea202cea8b6df58dea19d1d.zip |
Update vendor (go-irc)
Diffstat (limited to 'vendor/github.com/42wim/go-ircevent/irc_sasl.go')
-rw-r--r-- | vendor/github.com/42wim/go-ircevent/irc_sasl.go | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/vendor/github.com/42wim/go-ircevent/irc_sasl.go b/vendor/github.com/42wim/go-ircevent/irc_sasl.go new file mode 100644 index 00000000..fd9df7ba --- /dev/null +++ b/vendor/github.com/42wim/go-ircevent/irc_sasl.go @@ -0,0 +1,53 @@ +package irc + +import ( + "encoding/base64" + "errors" + "fmt" + "strings" +) + +type SASLResult struct { + Failed bool + Err error +} + +func (irc *Connection) setupSASLCallbacks(result chan<- *SASLResult) { + irc.AddCallback("CAP", func(e *Event) { + if len(e.Arguments) == 3 { + if e.Arguments[1] == "LS" { + if !strings.Contains(e.Arguments[2], "sasl") { + result <- &SASLResult{true, errors.New("no SASL capability " + e.Arguments[2])} + } + } + if e.Arguments[1] == "ACK" { + if irc.SASLMech != "PLAIN" { + result <- &SASLResult{true, errors.New("only PLAIN is supported")} + } + irc.SendRaw("AUTHENTICATE " + irc.SASLMech) + } + } + }) + irc.AddCallback("AUTHENTICATE", func(e *Event) { + str := base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%s\x00%s\x00%s", irc.SASLLogin, irc.SASLLogin, irc.SASLPassword))) + irc.SendRaw("AUTHENTICATE " + str) + }) + irc.AddCallback("901", func(e *Event) { + irc.SendRaw("CAP END") + irc.SendRaw("QUIT") + result <- &SASLResult{true, errors.New(e.Arguments[1])} + }) + irc.AddCallback("902", func(e *Event) { + irc.SendRaw("CAP END") + irc.SendRaw("QUIT") + result <- &SASLResult{true, errors.New(e.Arguments[1])} + }) + irc.AddCallback("903", func(e *Event) { + result <- &SASLResult{false, nil} + }) + irc.AddCallback("904", func(e *Event) { + irc.SendRaw("CAP END") + irc.SendRaw("QUIT") + result <- &SASLResult{true, errors.New(e.Arguments[1])} + }) +} |