diff options
author | xengineering <me@xengineering.eu> | 2023-06-04 17:12:04 +0200 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2023-06-05 17:54:40 +0200 |
commit | 89d44601930f4a9452fd40c2262652b1a847a8cf (patch) | |
tree | 5d638a3b2ec9d11b5422627863ada059cc949fb6 | |
parent | 3c33d393ddf06b6552b6dd7fbe85ddb985233968 (diff) | |
download | limox-89d44601930f4a9452fd40c2262652b1a847a8cf.tar limox-89d44601930f4a9452fd40c2262652b1a847a8cf.tar.zst limox-89d44601930f4a9452fd40c2262652b1a847a8cf.zip |
Re-implement XML encoding
-rw-r--r-- | xmpp/encoder_decoder.go | 35 | ||||
-rw-r--r-- | xmpp/session.go | 4 |
2 files changed, 36 insertions, 3 deletions
diff --git a/xmpp/encoder_decoder.go b/xmpp/encoder_decoder.go index c2d0423..14113a6 100644 --- a/xmpp/encoder_decoder.go +++ b/xmpp/encoder_decoder.go @@ -1,11 +1,44 @@ package xmpp +import ( + "encoding/xml" + "log" + "os" +) + type encoderDecoder struct{ session *session + ct *xml.Encoder // client transport encoder + cl *xml.Encoder // client log encoder } func newEncoderDecoder(s *session) encoderDecoder { - ed := encoderDecoder{s} + ed := encoderDecoder{} + + ed.session = s + + ed.ct = xml.NewEncoder(s.transport) + ed.ct.Indent("", " ") + + ed.cl = xml.NewEncoder(os.Stdout) + ed.cl.Indent("C: ", " ") return ed } + +func (ed *encoderDecoder) encodeToken(t xml.Token) error { + var err error + defer func() { if err != nil { log.Println(err) } }() + + err = ed.ct.EncodeToken(t) + if err != nil { return err } + err = ed.ct.Flush() + if err != nil { return err } + + err = ed.cl.EncodeToken(t) + if err != nil { return err } + err = ed.cl.Flush() + if err != nil { return err } + + return nil +} diff --git a/xmpp/session.go b/xmpp/session.go index 71b3acf..db9a079 100644 --- a/xmpp/session.go +++ b/xmpp/session.go @@ -24,8 +24,6 @@ func StartSession(out chan any, jid string, pwd string) chan any { s.in = make(chan any) s.out = out - s.ed = newEncoderDecoder(&s) - go s.run() return s.in @@ -38,6 +36,8 @@ func (s *session) run() { if err != nil { return } defer s.transport.Close() + s.ed = newEncoderDecoder(s) + s.out <- SessionConnect{} for { |