From a812aabfe1d96fbdaf5a40dd8fb6654d943a8380 Mon Sep 17 00:00:00 2001 From: xengineering Date: Tue, 9 May 2023 20:53:22 +0200 Subject: Implement logToken() This is a generic XML token logging function which can be used for sent and received XML tokens. --- xmpp.go | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/xmpp.go b/xmpp.go index a8dbcee..36d2135 100644 --- a/xmpp.go +++ b/xmpp.go @@ -77,12 +77,7 @@ func (l *Limox) xmpp(jid string, pwd string) { //log.Fatalf("Unknown GuiEvent '%d'!\n", ev) } case rx := <-receiver: - switch rx.(type) { - case xml.CharData: - log.Printf("S: [ %v ] %s\n", reflect.TypeOf(rx), rx) - default: - log.Printf("S: [ %v ] %+v\n", reflect.TypeOf(rx), rx) - } + logToken(rx, false) } if closing { @@ -95,6 +90,22 @@ func (l *Limox) xmpp(jid string, pwd string) { l.XmppEvents <- XmppDisconnect } +func logToken(t xml.Token, isTx bool) { + var prefix string + if isTx { + prefix = "C" + } else { + prefix = "S" + } + + switch t.(type) { + case xml.CharData: + log.Printf("%s: [ %v ] %s\n", prefix, reflect.TypeOf(t), t) + default: + log.Printf("%s: [ %v ] %+v\n", prefix, reflect.TypeOf(t), t) + } +} + type StreamInit struct { XMLName xml.Name `xml:"stream:stream"` From string `xml:"from,attr"` -- cgit v1.2.3-70-g09d2