summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/thoj
diff options
context:
space:
mode:
authorWim <wim@42.be>2016-07-22 22:51:11 +0200
committerWim <wim@42.be>2016-07-22 22:51:11 +0200
commit3e38c7945c5ae6b26d430e2aa2d913d091826abf (patch)
tree80f851aed0e6bfe7b6327ab0f3e6685ae2cda324 /vendor/github.com/thoj
parent79ffb76f6e87fde36bee3e4bd43d7d5145ba3c67 (diff)
downloadmatterbridge-msglm-3e38c7945c5ae6b26d430e2aa2d913d091826abf.tar.gz
matterbridge-msglm-3e38c7945c5ae6b26d430e2aa2d913d091826abf.tar.bz2
matterbridge-msglm-3e38c7945c5ae6b26d430e2aa2d913d091826abf.zip
Actually add sasl.go
Diffstat (limited to 'vendor/github.com/thoj')
-rw-r--r--vendor/github.com/thoj/go-ircevent/sasl.go54
1 files changed, 54 insertions, 0 deletions
diff --git a/vendor/github.com/thoj/go-ircevent/sasl.go b/vendor/github.com/thoj/go-ircevent/sasl.go
new file mode 100644
index 00000000..e5ff9e38
--- /dev/null
+++ b/vendor/github.com/thoj/go-ircevent/sasl.go
@@ -0,0 +1,54 @@
+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) {
+ irc.SendRaw("CAP END")
+ 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])}
+ })
+}