From 2d9864426272055151c42cf6bc2d13fbe11ca50c Mon Sep 17 00:00:00 2001 From: xengineering Date: Mon, 5 Jun 2023 18:48:54 +0200 Subject: Re-implement XML decoding --- xmpp/encoder_decoder.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'xmpp/encoder_decoder.go') diff --git a/xmpp/encoder_decoder.go b/xmpp/encoder_decoder.go index 14113a6..c8ccd89 100644 --- a/xmpp/encoder_decoder.go +++ b/xmpp/encoder_decoder.go @@ -3,13 +3,18 @@ package xmpp import ( "encoding/xml" "log" + "io" "os" + "errors" ) type encoderDecoder struct{ session *session ct *xml.Encoder // client transport encoder cl *xml.Encoder // client log encoder + st *xml.Decoder // server transport decoder + sl *xml.Encoder // server log encoder + terminator chan bool } func newEncoderDecoder(s *session) encoderDecoder { @@ -23,6 +28,11 @@ func newEncoderDecoder(s *session) encoderDecoder { ed.cl = xml.NewEncoder(os.Stdout) ed.cl.Indent("C: ", " ") + ed.st = xml.NewDecoder(s.transport) + + ed.sl = xml.NewEncoder(os.Stdout) + ed.sl.Indent("S: ", " ") + return ed } @@ -42,3 +52,26 @@ func (ed *encoderDecoder) encodeToken(t xml.Token) error { return nil } + +func (ed *encoderDecoder) run() { + for { + select { + case <-ed.terminator: + return + default: + t, err := ed.st.Token() + if t != nil && err == nil { + err = ed.sl.EncodeToken(t) + if err != nil { log.Println("Could not encode to server stream log") } + err = ed.sl.Flush() + if err != nil { log.Println("Could not flush server stream log") } + _ = xml.CopyToken(t) // TODO do something meaningful here + } + if err != nil { + if errors.Is(err, io.EOF) { return } + log.Println(err) // FIXME terminate session on error + return + } + } + } +} -- cgit v1.2.3-70-g09d2