Allow formatting IOT Control SetResponse

disco_info_form
Mickael Remond 8 years ago
parent 268acbff07
commit 57835bfcb5

@ -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() {
}

@ -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='%s' type='%s' id='%s' xml:lang='en'>"+
"</iq>",
iq.To, iq.Type, iq.Id)
}
return fmt.Sprintf("<iq to='%s' type='%s' id='%s' xml:lang='en'>"+
"%s</iq>",
iq.To, iq.Type, iq.Id, payload)
}
return fmt.Sprintf("<iq to='%s' type='%s' id='%s' xml:lang='en'>"+
"%s</iq>",
iq.To, iq.Type, iq.Id,
iq.RawXML)
}

Loading…
Cancel
Save