summaryrefslogtreecommitdiff
path: root/xmpp/xml.go
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2023-07-03 22:28:01 +0200
committerxengineering <me@xengineering.eu>2023-07-03 22:28:01 +0200
commit3efcd60f8ebdc962d5be85003cc8c59a2b43e610 (patch)
tree9f53b6a0895e244e228dbbfa3baa59f4a05957e6 /xmpp/xml.go
parent2fade1039c1842f08b30da5c95b5542b57e38ec6 (diff)
downloadlimox-3efcd60f8ebdc962d5be85003cc8c59a2b43e610.tar
limox-3efcd60f8ebdc962d5be85003cc8c59a2b43e610.tar.zst
limox-3efcd60f8ebdc962d5be85003cc8c59a2b43e610.zip
Remove encoderDecoder struct completely
This was not really necessary because it was all related to the xmpp.session and should thus be implemented there. Using the context package further reduced the complexity for cancelation.
Diffstat (limited to 'xmpp/xml.go')
-rw-r--r--xmpp/xml.go69
1 files changed, 29 insertions, 40 deletions
diff --git a/xmpp/xml.go b/xmpp/xml.go
index f547210..14c6637 100644
--- a/xmpp/xml.go
+++ b/xmpp/xml.go
@@ -1,57 +1,26 @@
package xmpp
import (
+ "context"
+ "crypto/tls"
"encoding/xml"
"errors"
"io"
"log"
)
-type encoderDecoder struct {
- session *session
- rx *xml.Decoder
- terminator chan bool
-}
-
-func newEncoderDecoder(s *session) encoderDecoder {
- ed := encoderDecoder{}
-
- ed.session = s
+func runRx(ctx context.Context, chn chan xml.Token, conn *tls.Conn) {
- lr := logger{"[RX] "}
- r := io.TeeReader(s.transport, lr)
- ed.rx = xml.NewDecoder(r)
+ l := logger{"[RX] "}
+ r := io.TeeReader(conn, l)
+ d := xml.NewDecoder(r)
- return ed
-}
-
-func (s *session) encodeToken(t xml.Token) error {
- var err error
- defer func() {
- if err != nil {
- log.Println(err)
- }
- }()
-
- err = s.tx.EncodeToken(t)
- if err != nil {
- return err
- }
- err = s.tx.Flush()
- if err != nil {
- return err
- }
-
- return nil
-}
-
-func (ed *encoderDecoder) run() {
for {
select {
- case <-ed.terminator:
+ case <-ctx.Done():
return
default:
- t, err := ed.rx.Token()
+ t, err := d.Token()
if t != nil && err == nil {
switch t.(type) {
case xml.ProcInst:
@@ -59,7 +28,7 @@ func (ed *encoderDecoder) run() {
case xml.Comment:
default:
c := xml.CopyToken(t)
- ed.session.rx <- c
+ chn <- c
}
}
if err != nil {
@@ -72,3 +41,23 @@ func (ed *encoderDecoder) run() {
}
}
}
+
+func (s *session) encodeToken(t xml.Token) error {
+ var err error
+ defer func() {
+ if err != nil {
+ log.Println(err)
+ }
+ }()
+
+ err = s.tx.EncodeToken(t)
+ if err != nil {
+ return err
+ }
+ err = s.tx.Flush()
+ if err != nil {
+ return err
+ }
+
+ return nil
+}