1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
package xmpp
import (
"encoding/xml"
"encoding/base64"
"log"
)
func (s *session) sasl() {
tokens := make([]xml.Token, 0, 3)
start := xml.StartElement{
xml.Name{"urn:ietf:params:xml:ns:xmpp-sasl", "auth"},
[]xml.Attr{
xml.Attr{xml.Name{"", "mechanism"}, "PLAIN"},
},
}
tokens = append(tokens, start)
data := []byte("\x00" + username(s.jid) + "\x00" + s.pwd)
dst := make([]byte, base64.StdEncoding.EncodedLen(len(data)))
base64.StdEncoding.Encode(dst, data)
payload := xml.CharData(dst)
tokens = append(tokens, payload)
end := start.End()
tokens = append(tokens, end)
for _, t := range tokens {
err := s.ed.encodeToken(t)
if err != nil {
log.Println("Could not encode stream end!")
return
}
}
}
|