summaryrefslogtreecommitdiff
path: root/xmpp/routing.go
diff options
context:
space:
mode:
Diffstat (limited to 'xmpp/routing.go')
-rw-r--r--xmpp/routing.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/xmpp/routing.go b/xmpp/routing.go
new file mode 100644
index 0000000..5cd2040
--- /dev/null
+++ b/xmpp/routing.go
@@ -0,0 +1,41 @@
+package xmpp
+
+import (
+ "encoding/xml"
+ "log"
+)
+
+func route(s *xml.StartElement, d *xml.Decoder, c chan<- any) {
+ switch (*s).Name {
+ case xml.Name{`http://etherx.jabber.org/streams`, `features`}:
+ parse(streamFeatures{}, s, d, c)
+ case xml.Name{`urn:ietf:params:xml:ns:xmpp-sasl`, `success`}:
+ parse(saslSuccess{}, s, d, c)
+ case xml.Name{`jabber:client`, `iq`}:
+ parse(iqResponse{}, s, d, c)
+ default:
+ d.Skip()
+ }
+}
+
+func parse[T any](data T, s *xml.StartElement, d *xml.Decoder, c chan<- any) {
+ err := d.DecodeElement(&data, s)
+ if err != nil {
+ log.Printf("Could not decode stream features: %v\n", err)
+ } else {
+ c <- data
+ }
+}
+
+func handle(s *session, element any) {
+ switch t := element.(type) {
+ case streamFeatures:
+ handleStreamFeatures(s, t)
+ case saslSuccess:
+ handleSaslSuccess(s)
+ case iqResponse:
+ handleIqResponse(s, t)
+ default:
+ log.Printf("Unknown parsed element: %v", t)
+ }
+}