summaryrefslogtreecommitdiff
path: root/xmpp/routing.go
blob: 2b1680f0ae1bb7ac5665273defac56ee5b4c4198 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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)
	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
	}
}