From 57835bfcb535f4f74fdc8557e77c1f4474d2d010 Mon Sep 17 00:00:00 2001 From: Mickael Remond Date: Mon, 15 Feb 2016 16:33:27 +0100 Subject: [PATCH] Allow formatting IOT Control SetResponse --- xmpp/iot/control.go | 17 +++++++---------- xmpp/iq.go | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/xmpp/iot/control.go b/xmpp/iot/control.go index 16908cc..20c384d 100644 --- a/xmpp/iot/control.go +++ b/xmpp/iot/control.go @@ -2,16 +2,6 @@ package iot import "encoding/xml" -/* -type Control struct { - ControlSet ControlSet `xml:",omitempty"` - ControlGetForm ControlGetForm `xml:",omitempty"` -} - -func (*Control) IQPayload() { -} -*/ - type ControlSet struct { XMLName xml.Name `xml:"urn:xmpp:iot:control set"` Fields []ControlField `xml:",any"` @@ -29,3 +19,10 @@ type ControlField struct { Name string `xml:"name,attr,omitempty"` Value string `xml:"value,attr,omitempty"` } + +type ControlSetResponse struct { + XMLName xml.Name `xml:"urn:xmpp:iot:control setResponse"` +} + +func (*ControlSetResponse) IsIQPayload() { +} diff --git a/xmpp/iq.go b/xmpp/iq.go index 1ecabf5..a0c5cf2 100644 --- a/xmpp/iq.go +++ b/xmpp/iq.go @@ -2,6 +2,7 @@ package xmpp import ( "encoding/xml" + "fmt" "github.com/processone/gox/xmpp/iot" ) @@ -73,3 +74,22 @@ func (iq *ClientIQ) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { } } } + +func (iq *ClientIQ) XMPPFormat() string { + if iq.Payload != nil { + var payload []byte + var err error + if payload, err = xml.Marshal(iq.Payload); err != nil { + return fmt.Sprintf(""+ + "", + iq.To, iq.Type, iq.Id) + } + return fmt.Sprintf(""+ + "%s", + iq.To, iq.Type, iq.Id, payload) + } + return fmt.Sprintf(""+ + "%s", + iq.To, iq.Type, iq.Id, + iq.RawXML) +}