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/stream_pair.go | 30 +++++------------------------- 1 file changed, 5 insertions(+), 25 deletions(-) (limited to 'xmpp/stream_pair.go') diff --git a/xmpp/stream_pair.go b/xmpp/stream_pair.go index b353947..8f70318 100644 --- a/xmpp/stream_pair.go +++ b/xmpp/stream_pair.go @@ -91,31 +91,11 @@ func closeStream(s *session) { } } -func getCharData(t xml.Token) string { - switch c := t.(type) { - case xml.CharData: - return string(c) - default: - return "" - } -} - func streamFeaturesHandler(e []xml.Token) { - 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) { - if getCharData(e[i+1]) == `PLAIN` { - log.Println("Got offer for SASL PLAIN") - return - } - } - } - } + sasl := hasSaslPlain(e) + if sasl { + log.Println("Stream is compatible with SASL PLAIN mechanism") + } else { + log.Println("Stream is not compatible with SASL PLAIN mechanism!") } - - log.Println("No compatible SASL mechanism offered!") } -- cgit v1.2.3-70-g09d2