summaryrefslogtreecommitdiff
path: root/xmpp/routing.go
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2023-05-21 12:26:02 +0200
committerxengineering <me@xengineering.eu>2023-05-21 12:26:17 +0200
commit1cb8fdc8b7d122486810408f6d9e6c820386b327 (patch)
tree9a7bf87e404d435c4fbbd4672e58161a3cff9a3f /xmpp/routing.go
parent82f67ff228a61b447f9bc0fcf6d9b7c5e17d57c2 (diff)
downloadlimox-1cb8fdc8b7d122486810408f6d9e6c820386b327.tar
limox-1cb8fdc8b7d122486810408f6d9e6c820386b327.tar.zst
limox-1cb8fdc8b7d122486810408f6d9e6c820386b327.zip
Allow error propagation from XML element handlers
Diffstat (limited to 'xmpp/routing.go')
-rw-r--r--xmpp/routing.go29
1 files changed, 19 insertions, 10 deletions
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
}