diff options
author | xengineering <me@xengineering.eu> | 2023-05-21 12:09:58 +0200 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2023-05-21 12:09:58 +0200 |
commit | 82f67ff228a61b447f9bc0fcf6d9b7c5e17d57c2 (patch) | |
tree | b58f4117511a4e582a047551530b75bcae077be9 /xmpp/routing.go | |
parent | 1446509513a18d0a90546e48938713c05137de16 (diff) | |
download | limox-82f67ff228a61b447f9bc0fcf6d9b7c5e17d57c2.tar limox-82f67ff228a61b447f9bc0fcf6d9b7c5e17d57c2.tar.zst limox-82f67ff228a61b447f9bc0fcf6d9b7c5e17d57c2.zip |
Implement XML element routing
Diffstat (limited to 'xmpp/routing.go')
-rw-r--r-- | xmpp/routing.go | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/xmpp/routing.go b/xmpp/routing.go index c691af3..3d1f9fe 100644 --- a/xmpp/routing.go +++ b/xmpp/routing.go @@ -44,9 +44,49 @@ func (r *tokenRouter) route(t xml.Token) error { return errors.New("Stream was closed by server") case 1: // call elementRouter - r.buffer = r.buffer[:1] + routeElement(r.buffer) + r.buffer = r.buffer[:0] } + case xml.ProcInst: + log.Println("Ignoring xml.ProcInst element") + r.buffer = r.buffer[:len(r.buffer)-1] + case xml.Directive: + log.Println("Ignoring xml.Directive element") + r.buffer = r.buffer[:len(r.buffer)-1] + case xml.Comment: + log.Println("Ignoring xml.Comment element") + r.buffer = r.buffer[:len(r.buffer)-1] } return nil } + +func routeElement(b []xml.Token) { + tab := elementRoutingTable{ + {xml.Name{"http://etherx.jabber.org/streams", "features"}, streamFeatures}, + } + + switch unwrapped := b[0].(type) { + case xml.StartElement: + for _, v := range(tab) { + if unwrapped.Name == v.name { + v.handler(b) + return + } + 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 + } +} + +type elementRoutingTable []struct { + name xml.Name + handler func(b []xml.Token) +} + +func streamFeatures(b []xml.Token) { + log.Println("Received stream features") +} |