summaryrefslogtreecommitdiff
path: root/xmpp/stream_pair.go
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2023-06-29 21:39:54 +0200
committerxengineering <me@xengineering.eu>2023-06-29 21:39:54 +0200
commitc8544b19df055235b9106ff296f0a5fe7cb1fe91 (patch)
treeb3da91a3d41746620ca67891797b55df8edfdc09 /xmpp/stream_pair.go
parent9afa580f3f3207ac449be86c1a305cb716b77f76 (diff)
parent3df1a88c726c08704e8b71c467bd8e11c9a52db6 (diff)
downloadlimox-c8544b19df055235b9106ff296f0a5fe7cb1fe91.tar
limox-c8544b19df055235b9106ff296f0a5fe7cb1fe91.tar.zst
limox-c8544b19df055235b9106ff296f0a5fe7cb1fe91.zip
Merge branch 'element-buffer'
This adds xengineering.eu/limox/xmpp/elementBuffer which is a buffer for a collection of XML tokens which are further processed after a full XML element is collected.
Diffstat (limited to 'xmpp/stream_pair.go')
-rw-r--r--xmpp/stream_pair.go20
1 files changed, 18 insertions, 2 deletions
diff --git a/xmpp/stream_pair.go b/xmpp/stream_pair.go
index e02cca6..b13d8a3 100644
--- a/xmpp/stream_pair.go
+++ b/xmpp/stream_pair.go
@@ -9,6 +9,8 @@ func runStreamPair(s *session) {
openStream(s)
defer closeStream(s)
+ buf := newElementBuffer()
+
for {
select {
case data := <-s.in:
@@ -18,8 +20,22 @@ func runStreamPair(s *session) {
default:
log.Printf("Unknown data '%d'!\n", data)
}
- case _ = <-s.rx:
- // TODO route received XML token here
+ case t := <-s.rx:
+ err := buf.add(t)
+ if err != nil {
+ log.Printf("Could not add XML token to buffer: %v\n", err)
+ return
+ }
+ if buf.isComplete() {
+ element := buf.reset()
+ // TODO handle XML element here - this is just a dummy:
+ switch start := element[0].(type) {
+ case xml.StartElement:
+ log.Printf("Got XML element `%s`\n", start.Name.Local)
+ default:
+ log.Println("No xml.StartElement at start of element buffer!")
+ }
+ }
}
}
}