From e22b95e43e0699846a81f448ec215c069062d59e Mon Sep 17 00:00:00 2001 From: Matt Goodall Date: Mon, 16 Jul 2012 16:06:13 +0100 Subject: [PATCH] Add way to peek at Iq's payload element. --- src/xmpp/stanza.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/xmpp/stanza.go b/src/xmpp/stanza.go index adbb4f6..ad03e7e 100644 --- a/src/xmpp/stanza.go +++ b/src/xmpp/stanza.go @@ -1,6 +1,7 @@ package xmpp import ( + "bytes" "encoding/xml" "fmt" ) @@ -33,6 +34,20 @@ func (iq *Iq) PayloadDecode(v interface{}) error { return xml.Unmarshal([]byte(iq.Payload), v) } +// Return the name of the payload element. +func (iq *Iq) PayloadName() (name xml.Name) { + dec := xml.NewDecoder(bytes.NewBufferString(iq.Payload)) + tok, err := dec.Token() + if err != nil { + return + } + start, ok := tok.(xml.StartElement) + if !ok { + return + } + return start.Name +} + // XMPP stanza. type Message struct { XMLName xml.Name `xml:"message"`