diff options
author | xengineering <me@xengineering.eu> | 2023-06-30 13:58:53 +0200 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2023-06-30 13:58:53 +0200 |
commit | 2f1fd4d1ce2c0c2e46fcfa1ffedfd84f0d36484e (patch) | |
tree | 8f6177e668c2737705949bc2fed200eb5e19a974 /xmpp/sasl.go | |
parent | 04746f75ea935266ded4e28edb6ab25c537d50e1 (diff) | |
parent | 3dc04660a87e1b9fabeea0e55a8511d80d34a694 (diff) | |
download | limox-2f1fd4d1ce2c0c2e46fcfa1ffedfd84f0d36484e.tar limox-2f1fd4d1ce2c0c2e46fcfa1ffedfd84f0d36484e.tar.zst limox-2f1fd4d1ce2c0c2e46fcfa1ffedfd84f0d36484e.zip |
Merge branch 'stream-features'
The added code provides a structured way to handle features offered by
the server.
Diffstat (limited to 'xmpp/sasl.go')
-rw-r--r-- | xmpp/sasl.go | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/xmpp/sasl.go b/xmpp/sasl.go index 8687782..512fd58 100644 --- a/xmpp/sasl.go +++ b/xmpp/sasl.go @@ -29,8 +29,46 @@ func (s *session) sasl() { for _, t := range tokens { err := s.ed.encodeToken(t) if err != nil { - log.Println("Could not encode stream end!") + log.Println("Could not encode SASL PLAIN element!") return } } } + +// hasSaslPlain scans the given stream features XML element for the SASL PLAIN +// mechanism which is supported by xengineering.eu/limox/xmpp. It returns true +// if the stream has support for this mechanism and false otherwise. +func hasSaslPlain(e []xml.Token) bool { + mechanism := xml.Name{`urn:ietf:params:xml:ns:xmpp-sasl`, `mechanism`} + + for i, t := range e { + switch s := t.(type) { + case xml.StartElement: + if s.Name == mechanism { + if i+1 < len(e) { + subtype := func() string { + switch c := e[i+1].(type) { + case xml.CharData: + return string(c) + default: + return "" + } + }() + if subtype == `PLAIN` { + return true + } + } + } + } + } + + return false +} + +func saslSuccessHandler(s *session, e []xml.Token) { + runStreamPair(s) +} + +func saslFailureHandler(s *session, e []xml.Token) { + log.Println("SASL autentication failed!") +} |