diff options
author | xengineering <me@xengineering.eu> | 2023-06-28 10:56:53 +0200 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2023-06-28 16:54:51 +0200 |
commit | d170626154a4853be386c7180050afe09be3ca0b (patch) | |
tree | 31281e115846bbf2d779c103657a242e217e8482 /xmpp/stream_pair.go | |
parent | 9afa580f3f3207ac449be86c1a305cb716b77f76 (diff) | |
download | limox-d170626154a4853be386c7180050afe09be3ca0b.tar limox-d170626154a4853be386c7180050afe09be3ca0b.tar.zst limox-d170626154a4853be386c7180050afe09be3ca0b.zip |
xmpp: Implement basic elementBuffer
This is needed to buffer XML elements of a stream until they are
complete and can be given to an element handler.
Diffstat (limited to 'xmpp/stream_pair.go')
-rw-r--r-- | xmpp/stream_pair.go | 20 |
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!") + } + } } } } |