From 04f24e0dade8caf029cb78d3281b3587a8362cbe Mon Sep 17 00:00:00 2001 From: xengineering Date: Fri, 30 Jun 2023 13:22:15 +0200 Subject: Rework and apply stream nesting on SASL success If SASL authentication is successful a new stream has to be opened by the client. This is implemented with this commit. --- xmpp/stream_pair.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'xmpp/stream_pair.go') diff --git a/xmpp/stream_pair.go b/xmpp/stream_pair.go index 5674d7b..f1de345 100644 --- a/xmpp/stream_pair.go +++ b/xmpp/stream_pair.go @@ -6,8 +6,8 @@ import ( ) func runStreamPair(s *session) { - openStream(s) - defer closeStream(s) + end := openStream(s) + defer closeStream(s, end) buf := newElementBuffer() @@ -34,7 +34,7 @@ func runStreamPair(s *session) { } } -func openStream(s *session) { +func openStream(s *session) xml.EndElement { start := xml.StartElement{ xml.Name{"jabber:client", "stream:stream"}, []xml.Attr{ @@ -45,8 +45,7 @@ func openStream(s *session) { xml.Attr{xml.Name{"", "xmlns:stream"}, "http://etherx.jabber.org/streams"}, }, } - - s.streamEnd = start.End() + end := start.End() err := s.ed.encodeToken(start) if err != nil { @@ -54,6 +53,8 @@ func openStream(s *session) { } syncStreams(s) + + return end } // syncStreams drops XML tokens from the receiving stream until an @@ -84,8 +85,8 @@ func syncStreams(s *session) { } } -func closeStream(s *session) { - err := s.ed.encodeToken(s.streamEnd) +func closeStream(s *session, end xml.EndElement) { + err := s.ed.encodeToken(end) if err != nil { log.Println("Could not encode stream end!") } -- cgit v1.2.3-70-g09d2