summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2023-06-30 13:22:15 +0200
committerxengineering <me@xengineering.eu>2023-06-30 13:22:15 +0200
commit04f24e0dade8caf029cb78d3281b3587a8362cbe (patch)
treee1ce4b1c0cce0b6ad0ce2cfc23e3a7e38ec9e469
parentf3aa8bec6e7d91b84a73688191751f9723c008a8 (diff)
downloadlimox-04f24e0dade8caf029cb78d3281b3587a8362cbe.tar
limox-04f24e0dade8caf029cb78d3281b3587a8362cbe.tar.zst
limox-04f24e0dade8caf029cb78d3281b3587a8362cbe.zip
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.
-rw-r--r--xmpp/sasl.go1
-rw-r--r--xmpp/session.go1
-rw-r--r--xmpp/stream_pair.go15
3 files changed, 9 insertions, 8 deletions
diff --git a/xmpp/sasl.go b/xmpp/sasl.go
index 62c312f..23e8f3f 100644
--- a/xmpp/sasl.go
+++ b/xmpp/sasl.go
@@ -66,4 +66,5 @@ func hasSaslPlain(e []xml.Token) bool {
}
func saslSuccessHandler(s *session, e []xml.Token) {
+ runStreamPair(s)
}
diff --git a/xmpp/session.go b/xmpp/session.go
index f14cd34..bfa2582 100644
--- a/xmpp/session.go
+++ b/xmpp/session.go
@@ -19,7 +19,6 @@ type session struct {
transport *tls.Conn
ed encoderDecoder
rx chan xml.Token
- streamEnd xml.EndElement
}
func StartSession(out chan<- any, jid string, pwd string) (in chan<- any) {
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!")
}