summaryrefslogtreecommitdiff
path: root/xmpp/router.go
diff options
context:
space:
mode:
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")
}