From 3b577ef35fd9c88677fd512e6312d3b431370bce Mon Sep 17 00:00:00 2001
From: xengineering <me@xengineering.eu>
Date: Fri, 19 May 2023 15:27:31 +0200
Subject: Implement basic stream error detection

With this commit LimoX will cancel the connection to the server if it
receives an encoding/xml.EndElement with .Name.Local attribute set to
"error".
---
 xmpp/xmpp.go | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

(limited to 'xmpp')

diff --git a/xmpp/xmpp.go b/xmpp/xmpp.go
index 773ea44..5c6e3e9 100644
--- a/xmpp/xmpp.go
+++ b/xmpp/xmpp.go
@@ -45,8 +45,14 @@ func Run(ch chan Event, jid string, pwd string) {
 			default:
 				log.Printf("Unknown Event '%d'!\n", ev)
 			}
-		case _ = <-decoder.data:
-			// do something with incoming tokens here
+		case token := <-decoder.data:
+			switch element := token.(type) {
+			case xml.EndElement:
+				if element.Name.Local == "error" {
+					log.Println("Received stream error!")
+					return
+				}
+			}
 		}
 	}
 }
-- 
cgit v1.2.3-70-g09d2