diff options
author | xengineering <me@xengineering.eu> | 2023-05-09 20:53:22 +0200 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2023-05-09 20:53:22 +0200 |
commit | a812aabfe1d96fbdaf5a40dd8fb6654d943a8380 (patch) | |
tree | bb0bcd59ddeac98e2953fdb568b277257bcafb1d /xmpp.go | |
parent | 8ab83cfe65a5487f62ca6d1d2c612a7505c6bd70 (diff) | |
download | limox-a812aabfe1d96fbdaf5a40dd8fb6654d943a8380.tar limox-a812aabfe1d96fbdaf5a40dd8fb6654d943a8380.tar.zst limox-a812aabfe1d96fbdaf5a40dd8fb6654d943a8380.zip |
Implement logToken()
This is a generic XML token logging function which can be used for
sent and received XML tokens.
Diffstat (limited to 'xmpp.go')
-rw-r--r-- | xmpp.go | 23 |
1 files changed, 17 insertions, 6 deletions
@@ -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"` |