From 3a516a43d3fca361abc779b66333e277743a7f09 Mon Sep 17 00:00:00 2001 From: Mickael Remond Date: Mon, 15 Feb 2016 11:08:54 +0100 Subject: [PATCH] Add preliminary support for IoT control (XEP-0325) --- xmpp/iot/control.go | 23 +++++++++++++++++++++++ xmpp/iq.go | 13 ++++++++++--- xmpp/packet.go | 1 + xmpp/parser.go | 2 +- xmpp/session.go | 4 ++-- 5 files changed, 37 insertions(+), 6 deletions(-) create mode 100644 xmpp/iot/control.go diff --git a/xmpp/iot/control.go b/xmpp/iot/control.go new file mode 100644 index 0000000..19a5e4d --- /dev/null +++ b/xmpp/iot/control.go @@ -0,0 +1,23 @@ +package iot + +import "encoding/xml" + +type Control struct { + ControlSet ControlSet `xml:",omitempty"` + ControlGetForm ControlGetForm `xml:",omitempty"` +} + +type ControlSet struct { + XMLName xml.Name `xml:"urn:xmpp:iot:control set"` + Fields []ControlField `xml:",any"` +} + +type ControlGetForm struct { + XMLName xml.Name `xml:"urn:xmpp:iot:control getForm"` +} + +type ControlField struct { + XMLName xml.Name + Name string `xml:"name,attr,omitempty"` + Value string `xml:"value,attr,omitempty"` +} diff --git a/xmpp/iq.go b/xmpp/iq.go index 2e97d8f..10e2ab5 100644 --- a/xmpp/iq.go +++ b/xmpp/iq.go @@ -1,11 +1,18 @@ package xmpp -import "encoding/xml" +import ( + "encoding/xml" -type clientIQ struct { // info/query + "github.com/processone/gox/xmpp/iot" +) + +// info/query +type ClientIQ struct { XMLName xml.Name `xml:"jabber:client iq"` Packet - Bind bindBind + Bind bindBind `xml:",omitempty"` + iot.Control + RawXML string `xml:",innerxml"` // TODO We need to support detecting the IQ namespace / Query packet // Error clientError } diff --git a/xmpp/packet.go b/xmpp/packet.go index 72098c1..2d5b1b1 100644 --- a/xmpp/packet.go +++ b/xmpp/packet.go @@ -1,5 +1,6 @@ package xmpp +// Packet represents the root default structure for an XMPP packet. type Packet struct { Id string `xml:"id,attr,omitempty"` From string `xml:"from,attr,omitempty"` diff --git a/xmpp/parser.go b/xmpp/parser.go index 139cf22..e625142 100644 --- a/xmpp/parser.go +++ b/xmpp/parser.go @@ -82,7 +82,7 @@ func next(p *xml.Decoder) (xml.Name, interface{}, error) { case nsClient + " presence": nv = &clientPresence{} case nsClient + " iq": - nv = &clientIQ{} + nv = &ClientIQ{} default: return xml.Name{}, nil, errors.New("unexpected XMPP message " + se.Name.Space + " <" + se.Name.Local + "/>") diff --git a/xmpp/session.go b/xmpp/session.go index af2c929..2704e22 100644 --- a/xmpp/session.go +++ b/xmpp/session.go @@ -153,7 +153,7 @@ func (s *Session) bind(o Options) { fmt.Fprintf(s.socketProxy, "", s.PacketId(), nsBind) } - var iq clientIQ + var iq ClientIQ if s.err = s.decoder.Decode(&iq); s.err != nil || &iq.Bind == nil { s.err = errors.New("iq bind result missing: " + s.err.Error()) return @@ -169,7 +169,7 @@ func (s *Session) rfc3921Session(o Options) { return } - var iq clientIQ + var iq ClientIQ // TODO: Do no send unconditionally, check if session is optional and omit it fmt.Fprintf(s.socketProxy, "", s.PacketId(), nsSession)