forked from jshiffer/go-xmpp
Makes parsing of inner IQ XML generic
This commit is contained in:
parent
e14f58d9a9
commit
94815de173
@ -19,9 +19,11 @@ func main() {
|
|||||||
|
|
||||||
switch p := packet.(type) {
|
switch p := packet.(type) {
|
||||||
case xmpp.IQ:
|
case xmpp.IQ:
|
||||||
switch p.Payload.(type) {
|
switch inner := p.Payload.(type) {
|
||||||
case *xmpp.Query:
|
case *xmpp.Node:
|
||||||
fmt.Println("Received query:", p.Type)
|
fmt.Println("Node:", inner.XMLName.Space, inner.XMLName.Local)
|
||||||
|
default:
|
||||||
|
fmt.Println("default")
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
fmt.Println("Packet unhandled packet:", packet)
|
fmt.Println("Packet unhandled packet:", packet)
|
||||||
|
15
iq.go
15
iq.go
@ -73,11 +73,10 @@ 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
|
default:
|
||||||
|
p = new(Node)
|
||||||
}
|
}
|
||||||
if p != nil {
|
if p != nil {
|
||||||
err = d.DecodeElement(p, &tt)
|
err = d.DecodeElement(p, &tt)
|
||||||
@ -118,10 +117,12 @@ func (iq *IQ) XMPPFormat() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// IQ Query subelement
|
// Genery IQ Node
|
||||||
|
|
||||||
type Query struct {
|
type Node struct {
|
||||||
XMLName xml.Name `xml:"http://jabber.org/protocol/disco#items query"`
|
XMLName xml.Name
|
||||||
|
Content []byte `xml:",innerxml"`
|
||||||
|
Nodes []Node `xml:",any"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*Query) IsIQPayload() {}
|
func (*Node) IsIQPayload() {}
|
||||||
|
Loading…
Reference in New Issue
Block a user