From 98740fdc1c777778054dc3e444b9f4542fe04abe Mon Sep 17 00:00:00 2001 From: xengineering Date: Fri, 30 Jun 2023 12:44:58 +0200 Subject: Move SASL mechanism detection to xmpp/sasl.go --- xmpp/sasl.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'xmpp/sasl.go') diff --git a/xmpp/sasl.go b/xmpp/sasl.go index 8687782..e06bcd5 100644 --- a/xmpp/sasl.go +++ b/xmpp/sasl.go @@ -34,3 +34,33 @@ func (s *session) sasl() { } } } + +// 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 +} -- cgit v1.2.3-70-g09d2