summaryrefslogtreecommitdiff
path: root/xmpp/router.go
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2023-07-04 13:48:34 +0200
committerxengineering <me@xengineering.eu>2023-07-04 13:48:34 +0200
commit92534f5af88b42665ad44f2495fe5dfb116d3406 (patch)
tree53fe906edb6ce70f22e6602469b9ce4da5d55675 /xmpp/router.go
parent45b04ef092a99d0d3f355e27896c82f1dbf15d28 (diff)
downloadlimox-92534f5af88b42665ad44f2495fe5dfb116d3406.tar
limox-92534f5af88b42665ad44f2495fe5dfb116d3406.tar.zst
limox-92534f5af88b42665ad44f2495fe5dfb116d3406.zip
First working version of new RX concept
This uses xml.Decoder.DecodeElement() which makes parsing way easier. This first step is just able to parse stream features partially.
Diffstat (limited to 'xmpp/router.go')
-rw-r--r--xmpp/router.go38
1 files changed, 8 insertions, 30 deletions
diff --git a/xmpp/router.go b/xmpp/router.go
index 1e21c9b..d437b28 100644
--- a/xmpp/router.go
+++ b/xmpp/router.go
@@ -2,7 +2,6 @@ package xmpp
import (
"encoding/xml"
- "log"
)
// routingTable is a data structure which contains routing information for XML
@@ -12,7 +11,7 @@ import (
// entry of the routingTable.
type routingTable []struct {
name xml.Name
- handler func(*session, []xml.Token)
+ handler func(s *xml.StartElement, d *xml.Decoder, c chan<- any)
}
// getRoutingTable returns the routing table used in
@@ -23,40 +22,19 @@ type routingTable []struct {
func getRoutingTable() routingTable {
return routingTable{
{xml.Name{`http://etherx.jabber.org/streams`, `features`}, streamFeaturesHandler},
- {xml.Name{`urn:ietf:params:xml:ns:xmpp-sasl`, `success`}, saslSuccessHandler},
- {xml.Name{`urn:ietf:params:xml:ns:xmpp-sasl`, `failure`}, saslFailureHandler},
- {xml.Name{`jabber:client`, `iq`}, iqHandler},
+// {xml.Name{`urn:ietf:params:xml:ns:xmpp-sasl`, `success`}, saslSuccessHandler},
+// {xml.Name{`urn:ietf:params:xml:ns:xmpp-sasl`, `failure`}, saslFailureHandler},
+// {xml.Name{`jabber:client`, `iq`}, iqHandler},
}
}
// route determines the correct handler function for the given XML element by a
// given routingTable. In addition it executes the determined handler function.
// If no handler function is found an error message is send via the log module.
-func route(s *session, e []xml.Token, t routingTable) {
- var name xml.Name
-
- // TODO a stronger definition of an XML element (as here
- // https://www.w3schools.com/xml/xml_elements.asp) would define that the
- // first Token of an element is a StartElement token. This would make this
- // code easier.
- escape := false
- for _, token := range e {
- switch s := token.(type) {
- case xml.StartElement:
- name = s.Name
- escape = true
- }
- if escape {
- break
- }
- }
-
- for _, r := range t {
- if name == r.name {
- r.handler(s, e)
- return
+func route(s *xml.StartElement, d *xml.Decoder, c chan<- any, t routingTable) {
+ for _, v := range t {
+ if v.name == (*s).Name {
+ v.handler(s, d, c)
}
}
-
- log.Println("Could not route XML element")
}