Decode query

This commit is contained in:
Mickael Remond 2018-01-13 19:14:26 +01:00
parent ec95020ac2
commit e14f58d9a9
No known key found for this signature in database
GPG key ID: E6F6045D79965AA3
2 changed files with 15 additions and 2 deletions

View file

@ -19,8 +19,10 @@ func main() {
switch p := packet.(type) { switch p := packet.(type) {
case xmpp.IQ: case xmpp.IQ:
fmt.Println("IQ received: ", p) switch p.Payload.(type) {
fmt.Println("IQ type:", p.Type) case *xmpp.Query:
fmt.Println("Received query:", p.Type)
}
default: default:
fmt.Println("Packet unhandled packet:", packet) fmt.Println("Packet unhandled packet:", packet)
} }

11
iq.go
View file

@ -73,6 +73,8 @@ func (iq *IQ) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
switch tt.Name.Space + " " + tt.Name.Local { switch tt.Name.Space + " " + tt.Name.Local {
case "urn:ietf:params:xml:ns:xmpp-bind bind": case "urn:ietf:params:xml:ns:xmpp-bind bind":
p = new(bindBind) p = new(bindBind)
case "http://jabber.org/protocol/disco#items query":
p = new(Query)
case "urn:xmpp:iot:control set": case "urn:xmpp:iot:control set":
p = new(iot.ControlSet) p = new(iot.ControlSet)
// TODO: Add a default Type that passes RawXML // TODO: Add a default Type that passes RawXML
@ -114,3 +116,12 @@ func (iq *IQ) XMPPFormat() string {
iq.To, iq.Type, iq.Id, iq.To, iq.Type, iq.Id,
iq.RawXML) iq.RawXML)
} }
// ============================================================================
// IQ Query subelement
type Query struct {
XMLName xml.Name `xml:"http://jabber.org/protocol/disco#items query"`
}
func (*Query) IsIQPayload() {}