summaryrefslogtreecommitdiff
path: root/xmpp/session.go
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2023-06-05 18:11:49 +0200
committerxengineering <me@xengineering.eu>2023-06-05 18:11:49 +0200
commitfeb6a5a38ba15d0cf4bd88283093174991e66eaa (patch)
treed07f8908c90c873bfc7675d13ef02e7e6037ee2d /xmpp/session.go
parent89d44601930f4a9452fd40c2262652b1a847a8cf (diff)
downloadlimox-feb6a5a38ba15d0cf4bd88283093174991e66eaa.tar
limox-feb6a5a38ba15d0cf4bd88283093174991e66eaa.tar.zst
limox-feb6a5a38ba15d0cf4bd88283093174991e66eaa.zip
Re-implement initial stream start/end
Diffstat (limited to 'xmpp/session.go')
-rw-r--r--xmpp/session.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/xmpp/session.go b/xmpp/session.go
index db9a079..234c2e6 100644
--- a/xmpp/session.go
+++ b/xmpp/session.go
@@ -4,6 +4,7 @@ import (
"crypto/tls"
"crypto/x509"
"log"
+ "encoding/xml"
)
type SessionConnect struct{}
@@ -15,6 +16,7 @@ type session struct {
in, out chan any
transport *tls.Conn
ed encoderDecoder
+ streams []stream
}
func StartSession(out chan any, jid string, pwd string) chan any {
@@ -23,6 +25,7 @@ func StartSession(out chan any, jid string, pwd string) chan any {
s.jid = jid
s.in = make(chan any)
s.out = out
+ s.streams = make([]stream, 0)
go s.run()
@@ -38,6 +41,9 @@ func (s *session) run() {
s.ed = newEncoderDecoder(s)
+ s.openStream()
+ defer s.closeStreams()
+
s.out <- SessionConnect{}
for {
@@ -68,3 +74,37 @@ func (s *session) startTransport() error {
return nil
}
+
+func (s *session) openStream() {
+ stream := stream{}
+ stream.session = s
+
+ start := xml.StartElement{
+ xml.Name{"jabber:client", "stream:stream"},
+ []xml.Attr{
+ xml.Attr{xml.Name{"", "from"}, s.jid},
+ xml.Attr{xml.Name{"", "to"}, domainpart(s.jid)},
+ xml.Attr{xml.Name{"", "version"}, "1.0"},
+ xml.Attr{xml.Name{"", "xml:lang"}, "en"},
+ xml.Attr{xml.Name{"", "xmlns:stream"}, "http://etherx.jabber.org/streams"},
+ },
+ }
+
+ stream.end = start.End()
+
+ err := s.ed.encodeToken(start)
+ if err != nil {
+ log.Println("Could not encode stream start!")
+ }
+
+ s.streams = append(s.streams, stream)
+}
+
+func (s *session) closeStreams() {
+ for {
+ limit := len(s.streams)
+ if limit <= 0 { break }
+ s.streams[limit - 1].terminate()
+ s.streams = s.streams[:limit - 1]
+ }
+}