summaryrefslogtreecommitdiff
path: root/xmpp/streams.go
diff options
context:
space:
mode:
Diffstat (limited to 'xmpp/streams.go')
-rw-r--r--xmpp/streams.go53
1 files changed, 15 insertions, 38 deletions
diff --git a/xmpp/streams.go b/xmpp/streams.go
index 388be4d..b9c0cb7 100644
--- a/xmpp/streams.go
+++ b/xmpp/streams.go
@@ -5,62 +5,39 @@ import (
"log"
)
-func openStream(s *session) xml.EndElement {
+func openStream(e *xml.Encoder, jid string) {
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{"", "from"}, jid},
+ xml.Attr{xml.Name{"", "to"}, domainpart(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"},
},
}
- end := start.End()
- err := s.encodeToken(start)
+ err := e.EncodeToken(start)
if err != nil {
log.Println("Could not encode stream start!")
}
-
- syncStreams(s)
-
- return end
-}
-
-// syncStreams drops XML tokens from the receiving stream until an
-// xml.StartElement with the local name `stream` is received. If this function
-// is called after opening a new stream in the sending direction it is ensured
-// that both streams directions work on the same stream level and are in sync.
-// Tokens received which are not a stream StartElement are not handled but
-// logged since this should not happen.
-func syncStreams(s *session) {
- for {
- select {
- case data := <-s.in:
- switch data.(type) {
- case SessionShouldDisconnect:
- return
- default:
- log.Printf("Unhandled data '%d' during stream sync!\n", data)
- }
- case t := <-s.rx:
- switch token := t.(type) {
- case xml.StartElement:
- if token.Name.Local == "stream" {
- return
- }
- }
- log.Printf("Unhandled XML token '%v' during stream sync!\n", t)
- }
+ err = e.Flush()
+ if err != nil {
+ log.Println("Could not flush after stream start!")
}
}
-func closeStream(s *session, end xml.EndElement) {
- err := s.encodeToken(end)
+func closeStream(e *xml.Encoder) {
+ end := xml.EndElement{xml.Name{"jabber:client", "stream:stream"}}
+
+ err := e.EncodeToken(end)
if err != nil {
log.Println("Could not encode stream end!")
}
+ err = e.Flush()
+ if err != nil {
+ log.Println("Could not flush after stream end!")
+ }
}
func streamFeaturesHandler(s *session, e []xml.Token) {