diff options
-rw-r--r-- | xmpp/routing.go | 30 | ||||
-rw-r--r-- | xmpp/xmpp.go | 1 |
2 files changed, 30 insertions, 1 deletions
diff --git a/xmpp/routing.go b/xmpp/routing.go index 34136f4..55ec135 100644 --- a/xmpp/routing.go +++ b/xmpp/routing.go @@ -95,7 +95,35 @@ type elementRoutingTable []struct { } func streamFeatures(b []xml.Token) error { - log.Println("Received stream features") + err := sendSaslAuth(b) + if err != nil { + return err + } return nil } + +func sendSaslAuth(b []xml.Token) error { + mechanisms := make([]string, 0) + for i, v := range(b) { + switch token := v.(type) { + case xml.StartElement: + expected := xml.Name{"urn:ietf:params:xml:ns:xmpp-sasl", "mechanism"} + if token.Name == expected { + if i >= (len(b)-1) { continue } + switch payload := b[i+1].(type) { + case xml.CharData: + mechanisms = append(mechanisms, string(payload)) + } + } + } + } + + for _, v := range(mechanisms) { + if v == "PLAIN" { + return nil + } + } + + return errors.New("No compatible SASL mechanism given") +} diff --git a/xmpp/xmpp.go b/xmpp/xmpp.go index c0a52a0..5193f02 100644 --- a/xmpp/xmpp.go +++ b/xmpp/xmpp.go @@ -50,6 +50,7 @@ func Run(ch chan Event, jid string, pwd string) { case token := <-decoder.data: err = tr.route(token) if err != nil { + log.Println(err) return } } |