package xmpp import ( "encoding/base64" "encoding/xml" "log" ) type saslRequest struct { Payload []byte `xml:",chardata"` } func (s *session) sasl() { start := xml.StartElement{ xml.Name{"urn:ietf:params:xml:ns:xmpp-sasl", "auth"}, []xml.Attr{ xml.Attr{xml.Name{"", "mechanism"}, "PLAIN"}, }, } data := []byte("\x00" + username(s.jid) + "\x00" + s.pwd) inner := saslRequest{} inner.Payload = make([]byte, base64.StdEncoding.EncodedLen(len(data))) base64.StdEncoding.Encode(inner.Payload, data) err := s.tx.EncodeElement(inner, start) if err != nil { log.Println("Could not encode SASL PLAIN element!") } } type saslSuccess struct{} func handleSaslSuccess(s *session) { openStream(s.tx, s.jid) }