summaryrefslogtreecommitdiff
path: root/xmpp/decoder.go
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2023-05-18 21:43:37 +0200
committerxengineering <me@xengineering.eu>2023-05-18 21:43:37 +0200
commit7fc8ea8ca5efb6adf6fa7c54d1b39f010e17eb7b (patch)
tree956dad006d8e623a36ae2a3213f7246ac5567502 /xmpp/decoder.go
parent05f50be52b03c7e84ba47d3b5349321920748f8b (diff)
downloadlimox-7fc8ea8ca5efb6adf6fa7c54d1b39f010e17eb7b.tar
limox-7fc8ea8ca5efb6adf6fa7c54d1b39f010e17eb7b.tar.zst
limox-7fc8ea8ca5efb6adf6fa7c54d1b39f010e17eb7b.zip
Handle server side debug in xmpp/decoder.go
Diffstat (limited to 'xmpp/decoder.go')
-rw-r--r--xmpp/decoder.go32
1 files changed, 26 insertions, 6 deletions
diff --git a/xmpp/decoder.go b/xmpp/decoder.go
index 97329c7..070f791 100644
--- a/xmpp/decoder.go
+++ b/xmpp/decoder.go
@@ -4,20 +4,29 @@ import (
"crypto/tls"
"encoding/xml"
"log"
+ "os"
+ "io"
+ "errors"
)
type decoder struct {
terminator chan bool
data chan xml.Token
decoder *xml.Decoder
+ debug *xml.Encoder
}
func newDecoder(conn *tls.Conn) decoder {
- return decoder{
+ d := decoder{
make(chan bool),
make(chan xml.Token),
xml.NewDecoder(conn),
+ xml.NewEncoder(os.Stdout),
}
+
+ d.debug.Indent("S: ", " ")
+
+ return d
}
func (r *decoder) run() {
@@ -27,12 +36,23 @@ func (r *decoder) run() {
return
default:
t, err := r.decoder.Token()
- if err != nil {
- log.Print(err)
+ if t != nil && err == nil {
+ err := r.debug.EncodeToken(t)
+ if err != nil {
+ log.Println("Could not encode received XML token to debug output!")
+ }
+ err = r.debug.Flush()
+ if err != nil {
+ log.Println("Could not flush debug output after receive!")
+ }
+ r.data <- t
}
- if t != nil {
- c := xml.CopyToken(t)
- r.data <- c
+ if err != nil {
+ if errors.Is(err, io.EOF) {
+ return
+ } else {
+ log.Printf("Decoding error: %v", err)
+ }
}
}
}