forked from jshiffer/go-xmpp
Add preliminary support for IoT control (XEP-0325)
This commit is contained in:
parent
adcd2bd467
commit
3a516a43d3
23
xmpp/iot/control.go
Normal file
23
xmpp/iot/control.go
Normal file
@ -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"`
|
||||||
|
}
|
13
xmpp/iq.go
13
xmpp/iq.go
@ -1,11 +1,18 @@
|
|||||||
package xmpp
|
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"`
|
XMLName xml.Name `xml:"jabber:client iq"`
|
||||||
Packet
|
Packet
|
||||||
Bind bindBind
|
Bind bindBind `xml:",omitempty"`
|
||||||
|
iot.Control
|
||||||
|
RawXML string `xml:",innerxml"`
|
||||||
// TODO We need to support detecting the IQ namespace / Query packet
|
// TODO We need to support detecting the IQ namespace / Query packet
|
||||||
// Error clientError
|
// Error clientError
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package xmpp
|
package xmpp
|
||||||
|
|
||||||
|
// Packet represents the root default structure for an XMPP packet.
|
||||||
type Packet struct {
|
type Packet struct {
|
||||||
Id string `xml:"id,attr,omitempty"`
|
Id string `xml:"id,attr,omitempty"`
|
||||||
From string `xml:"from,attr,omitempty"`
|
From string `xml:"from,attr,omitempty"`
|
||||||
|
@ -82,7 +82,7 @@ func next(p *xml.Decoder) (xml.Name, interface{}, error) {
|
|||||||
case nsClient + " presence":
|
case nsClient + " presence":
|
||||||
nv = &clientPresence{}
|
nv = &clientPresence{}
|
||||||
case nsClient + " iq":
|
case nsClient + " iq":
|
||||||
nv = &clientIQ{}
|
nv = &ClientIQ{}
|
||||||
default:
|
default:
|
||||||
return xml.Name{}, nil, errors.New("unexpected XMPP message " +
|
return xml.Name{}, nil, errors.New("unexpected XMPP message " +
|
||||||
se.Name.Space + " <" + se.Name.Local + "/>")
|
se.Name.Space + " <" + se.Name.Local + "/>")
|
||||||
|
@ -153,7 +153,7 @@ func (s *Session) bind(o Options) {
|
|||||||
fmt.Fprintf(s.socketProxy, "<iq type='set' id='%s'><bind xmlns='%s'/></iq>", s.PacketId(), nsBind)
|
fmt.Fprintf(s.socketProxy, "<iq type='set' id='%s'><bind xmlns='%s'/></iq>", s.PacketId(), nsBind)
|
||||||
}
|
}
|
||||||
|
|
||||||
var iq clientIQ
|
var iq ClientIQ
|
||||||
if s.err = s.decoder.Decode(&iq); s.err != nil || &iq.Bind == nil {
|
if s.err = s.decoder.Decode(&iq); s.err != nil || &iq.Bind == nil {
|
||||||
s.err = errors.New("iq bind result missing: " + s.err.Error())
|
s.err = errors.New("iq bind result missing: " + s.err.Error())
|
||||||
return
|
return
|
||||||
@ -169,7 +169,7 @@ func (s *Session) rfc3921Session(o Options) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var iq clientIQ
|
var iq ClientIQ
|
||||||
|
|
||||||
// TODO: Do no send unconditionally, check if session is optional and omit it
|
// TODO: Do no send unconditionally, check if session is optional and omit it
|
||||||
fmt.Fprintf(s.socketProxy, "<iq type='set' id='%s'><session xmlns='%s'/></iq>", s.PacketId(), nsSession)
|
fmt.Fprintf(s.socketProxy, "<iq type='set' id='%s'><session xmlns='%s'/></iq>", s.PacketId(), nsSession)
|
||||||
|
Loading…
Reference in New Issue
Block a user