summaryrefslogtreecommitdiff
path: root/xmpp.go
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2023-05-11 20:22:31 +0200
committerxengineering <me@xengineering.eu>2023-05-11 20:22:31 +0200
commit0dd1fb9f2158dec48c8dc55a078b3d79d475c9d9 (patch)
tree88580bbd6b31b6e83dee2ca02d5c2fa9576693a9 /xmpp.go
parent8569dfec15368986773e67d8c1598c0e02b39084 (diff)
downloadlimox-0dd1fb9f2158dec48c8dc55a078b3d79d475c9d9.tar
limox-0dd1fb9f2158dec48c8dc55a078b3d79d475c9d9.tar.zst
limox-0dd1fb9f2158dec48c8dc55a078b3d79d475c9d9.zip
Restructure xmpp()
Diffstat (limited to 'xmpp.go')
-rw-r--r--xmpp.go22
1 files changed, 8 insertions, 14 deletions
diff --git a/xmpp.go b/xmpp.go
index d7c8790..90a0355 100644
--- a/xmpp.go
+++ b/xmpp.go
@@ -1,11 +1,11 @@
package main
import (
- "os"
"crypto/tls"
"crypto/x509"
"encoding/xml"
"log"
+ "os"
)
type XmppEvent uint8
@@ -16,32 +16,34 @@ const (
)
func (l *Limox) xmpp(jid string, pwd string) {
+ defer func() { l.XmppEvents <- XmppDisconnect }()
conn, err := setupConn(jid)
if err != nil {
l.XmppEvents <- err
return
}
-
- enc := xml.NewEncoder(conn)
+ defer conn.Close()
receiver := make(chan xml.Token)
termination := make(chan bool)
go rxRoutine(conn, receiver, termination)
+ enc := xml.NewEncoder(conn)
dbg := xml.NewEncoder(os.Stdout)
end := sendStreamStart(enc, jid)
+ defer sendStreamEnd(enc, end)
+
l.XmppEvents <- XmppConnect
- var closing bool = false
for {
select {
case ev := <-l.GuiEvents:
switch ev {
case Disconnect:
termination <- true
- closing = true
+ return
default:
log.Fatalf("Unknown GuiEvent '%d'!\n", ev)
}
@@ -50,15 +52,7 @@ func (l *Limox) xmpp(jid string, pwd string) {
dbg.EncodeToken(rx)
dbg.Flush()
}
-
- if closing {
- break
- }
}
-
- sendStreamEnd(enc, end)
- conn.Close()
- l.XmppEvents <- XmppDisconnect
}
func setupConn(jid string) (*tls.Conn, error) {
@@ -91,7 +85,7 @@ func rxRoutine(conn *tls.Conn, tokens chan xml.Token, terminator chan bool) {
}
}
-func sendStreamStart(enc *xml.Encoder, jid string) (xml.EndElement) {
+func sendStreamStart(enc *xml.Encoder, jid string) xml.EndElement {
start := xml.StartElement{
xml.Name{"jabber:client", "stream:stream"},
[]xml.Attr{