From 1cb8fdc8b7d122486810408f6d9e6c820386b327 Mon Sep 17 00:00:00 2001 From: xengineering Date: Sun, 21 May 2023 12:26:02 +0200 Subject: Allow error propagation from XML element handlers --- xmpp/routing.go | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'xmpp/routing.go') diff --git a/xmpp/routing.go b/xmpp/routing.go index 3d1f9fe..34136f4 100644 --- a/xmpp/routing.go +++ b/xmpp/routing.go @@ -44,7 +44,10 @@ func (r *tokenRouter) route(t xml.Token) error { return errors.New("Stream was closed by server") case 1: // call elementRouter - routeElement(r.buffer) + err := routeElement(r.buffer) + if err != nil { + return err + } r.buffer = r.buffer[:0] } case xml.ProcInst: @@ -61,7 +64,7 @@ func (r *tokenRouter) route(t xml.Token) error { return nil } -func routeElement(b []xml.Token) { +func routeElement(b []xml.Token) error { tab := elementRoutingTable{ {xml.Name{"http://etherx.jabber.org/streams", "features"}, streamFeatures}, } @@ -70,23 +73,29 @@ func routeElement(b []xml.Token) { case xml.StartElement: for _, v := range(tab) { if unwrapped.Name == v.name { - v.handler(b) - return + err := v.handler(b) + if err != nil { + return err + } + return nil } - log.Printf("Ignoring XML element '%s' from namespace '%s'", - unwrapped.Name.Local, unwrapped.Name.Space) } + log.Printf("Ignoring XML element '%s' from namespace '%s'", + unwrapped.Name.Local, unwrapped.Name.Space) default: - log.Println("First buffer element is not xml.StartElement") - return + log.Println("Ignoring XML element which has no StartElement as first token") } + + return nil } type elementRoutingTable []struct { name xml.Name - handler func(b []xml.Token) + handler func(b []xml.Token) error } -func streamFeatures(b []xml.Token) { +func streamFeatures(b []xml.Token) error { log.Println("Received stream features") + + return nil } -- cgit v1.2.3-70-g09d2