diff options
Diffstat (limited to 'xmpp.go')
-rw-r--r-- | xmpp.go | 45 |
1 files changed, 34 insertions, 11 deletions
@@ -20,7 +20,7 @@ func xmpp(rxChan chan GuiEvent, txChan chan any, jid string, pwd string) { conn, err := setupConn(jid) if err != nil { - txChan <- err + log.Print(err) return } defer conn.Close() @@ -31,7 +31,9 @@ func xmpp(rxChan chan GuiEvent, txChan chan any, jid string, pwd string) { defer func() { termination <- true }() enc := xml.NewEncoder(conn) + defer enc.Close() dbg := xml.NewEncoder(os.Stdout) + defer dbg.Close() end := sendStreamStart(enc, dbg, jid) defer sendStreamEnd(enc, dbg, end) @@ -45,7 +47,7 @@ func xmpp(rxChan chan GuiEvent, txChan chan any, jid string, pwd string) { case Disconnect: return default: - log.Fatalf("Unknown GuiEvent '%d'!\n", ev) + log.Printf("Unknown GuiEvent '%d'!\n", ev) } case rx := <-receiver: dbg.Indent("S: ", " ") @@ -68,12 +70,16 @@ func setupConn(jid string) (*tls.Conn, error) { func rxRoutine(conn *tls.Conn, tokens chan xml.Token, terminator chan bool) { dec := xml.NewDecoder(conn) + for { select { case <-terminator: return default: - t, _ := dec.Token() // TODO error handling + t, err := dec.Token() + if err != nil { + log.Print(err) + } if t != nil { tokens <- t } @@ -95,35 +101,52 @@ func sendStreamStart(enc *xml.Encoder, dbg *xml.Encoder, jid string) xml.EndElem err := enc.EncodeToken(start) if err != nil { - log.Fatal("Could not encode stream start!") + log.Println("Could not encode stream start to TCP channel!") } err = enc.Flush() if err != nil { - log.Fatal("Could not flush XML encoder!") + log.Println("Could not flush TCP channel XML encoder!") } dbg.Indent("C: ", " ") - dbg.EncodeToken(start) - dbg.Flush() + + err = dbg.EncodeToken(start) + if err != nil { + log.Println("Could not encode stream start to debug output!") + } + + err = dbg.Flush() + if err != nil { + log.Println("Could not flush debug XML encoder!") + } return start.End() } func sendStreamEnd(enc *xml.Encoder, dbg *xml.Encoder, end xml.EndElement) { + err := enc.EncodeToken(end) if err != nil { - log.Fatal("Could not encode stream end!") + log.Println("Could not encode stream end to TCP channel!") } err = enc.Flush() if err != nil { - log.Fatal("Could not flush XML encoder!") + log.Println("Could not flush TCP channel XML encoder!") } dbg.Indent("C: ", " ") - dbg.EncodeToken(end) - dbg.Flush() + + err = dbg.EncodeToken(end) + if err != nil { + log.Println("Could not encode stream end to debug output!") + } + + err = dbg.Flush() + if err != nil { + log.Println("Could not flush debug XML encoder!") + } } // domainpart extracts the domain name from a JID / XMPP address. See |