diff options
Diffstat (limited to 'xmpp/decoder.go')
-rw-r--r-- | xmpp/decoder.go | 32 |
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) + } } } } |