From cb9016693ce18d0e2e2fed77d03225ce3986043e Mon Sep 17 00:00:00 2001 From: Mickael Remond Date: Thu, 27 Jun 2019 10:22:36 +0200 Subject: [PATCH] Move some IQ declaration in their own files --- stanza/auth_sasl.go | 7 ++++ stanza/iot.go | 7 ++++ stanza/iq.go | 76 -------------------------------------------- stanza/iq_disco.go | 61 +++++++++++++++++++++++++++++++++++ stanza/iq_version.go | 25 +++++++++++++++ 5 files changed, 100 insertions(+), 76 deletions(-) create mode 100644 stanza/iq_disco.go create mode 100644 stanza/iq_version.go diff --git a/stanza/auth_sasl.go b/stanza/auth_sasl.go index a5ea907..5961d9f 100644 --- a/stanza/auth_sasl.go +++ b/stanza/auth_sasl.go @@ -70,3 +70,10 @@ type sessionSession struct { XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-session session"` Optional xml.Name // If it does exist, it mean we are not required to open session } + +// ============================================================================ +// Registry init + +func init() { + TypeRegistry.MapExtension(PKTIQ, xml.Name{"urn:ietf:params:xml:ns:xmpp-bind", "bind"}, BindBind{}) +} diff --git a/stanza/iot.go b/stanza/iot.go index cd3b404..5e15056 100644 --- a/stanza/iot.go +++ b/stanza/iot.go @@ -30,3 +30,10 @@ type ControlSetResponse struct { func (c *ControlSetResponse) Namespace() string { return c.XMLName.Space } + +// ============================================================================ +// Registry init + +func init() { + TypeRegistry.MapExtension(PKTIQ, xml.Name{"urn:xmpp:iot:control", "set"}, ControlSet{}) +} diff --git a/stanza/iq.go b/stanza/iq.go index 24b65cc..34c74bb 100644 --- a/stanza/iq.go +++ b/stanza/iq.go @@ -128,79 +128,3 @@ func (iq *IQ) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { } } } - -// ============================================================================ -// Disco - -const ( - NSDiscoInfo = "http://jabber.org/protocol/disco#info" - NSDiscoItems = "http://jabber.org/protocol/disco#items" -) - -// Disco Info -type DiscoInfo struct { - XMLName xml.Name `xml:"http://jabber.org/protocol/disco#info query"` - Node string `xml:"node,attr,omitempty"` - Identity Identity `xml:"identity"` - Features []Feature `xml:"feature"` -} - -func (d *DiscoInfo) Namespace() string { - return d.XMLName.Space -} - -type Identity struct { - XMLName xml.Name `xml:"identity,omitempty"` - Name string `xml:"name,attr,omitempty"` - Category string `xml:"category,attr,omitempty"` - Type string `xml:"type,attr,omitempty"` -} - -type Feature struct { - XMLName xml.Name `xml:"feature"` - Var string `xml:"var,attr"` -} - -// Disco Items -type DiscoItems struct { - XMLName xml.Name `xml:"http://jabber.org/protocol/disco#items query"` - Node string `xml:"node,attr,omitempty"` - Items []DiscoItem `xml:"item"` -} - -func (d *DiscoItems) Namespace() string { - return d.XMLName.Space -} - -type DiscoItem struct { - XMLName xml.Name `xml:"item"` - Name string `xml:"name,attr,omitempty"` - JID string `xml:"jid,attr,omitempty"` - Node string `xml:"node,attr,omitempty"` -} - -// ============================================================================ -// Software Version (XEP-0092) - -// Version -type Version struct { - XMLName xml.Name `xml:"jabber:iq:version query"` - Name string `xml:"name,omitempty"` - Version string `xml:"version,omitempty"` - OS string `xml:"os,omitempty"` -} - -func (v *Version) Namespace() string { - return v.XMLName.Space -} - -// ============================================================================ -// Registry init - -func init() { - TypeRegistry.MapExtension(PKTIQ, xml.Name{NSDiscoInfo, "query"}, DiscoInfo{}) - TypeRegistry.MapExtension(PKTIQ, xml.Name{NSDiscoItems, "query"}, DiscoItems{}) - TypeRegistry.MapExtension(PKTIQ, xml.Name{"urn:ietf:params:xml:ns:xmpp-bind", "bind"}, BindBind{}) - TypeRegistry.MapExtension(PKTIQ, xml.Name{"urn:xmpp:iot:control", "set"}, ControlSet{}) - TypeRegistry.MapExtension(PKTIQ, xml.Name{"jabber:iq:version", "query"}, Version{}) -} diff --git a/stanza/iq_disco.go b/stanza/iq_disco.go new file mode 100644 index 0000000..da161d1 --- /dev/null +++ b/stanza/iq_disco.go @@ -0,0 +1,61 @@ +package stanza + +import "encoding/xml" + +// ============================================================================ +// Disco + +const ( + NSDiscoInfo = "http://jabber.org/protocol/disco#info" + NSDiscoItems = "http://jabber.org/protocol/disco#items" +) + +// Disco Info +type DiscoInfo struct { + XMLName xml.Name `xml:"http://jabber.org/protocol/disco#info query"` + Node string `xml:"node,attr,omitempty"` + Identity Identity `xml:"identity"` + Features []Feature `xml:"feature"` +} + +func (d *DiscoInfo) Namespace() string { + return d.XMLName.Space +} + +type Identity struct { + XMLName xml.Name `xml:"identity,omitempty"` + Name string `xml:"name,attr,omitempty"` + Category string `xml:"category,attr,omitempty"` + Type string `xml:"type,attr,omitempty"` +} + +type Feature struct { + XMLName xml.Name `xml:"feature"` + Var string `xml:"var,attr"` +} + +// Disco Items +type DiscoItems struct { + XMLName xml.Name `xml:"http://jabber.org/protocol/disco#items query"` + Node string `xml:"node,attr,omitempty"` + Items []DiscoItem `xml:"item"` +} + +func (d *DiscoItems) Namespace() string { + return d.XMLName.Space +} + +type DiscoItem struct { + XMLName xml.Name `xml:"item"` + Name string `xml:"name,attr,omitempty"` + JID string `xml:"jid,attr,omitempty"` + Node string `xml:"node,attr,omitempty"` +} + +// ============================================================================ +// Registry init + +func init() { + TypeRegistry.MapExtension(PKTIQ, xml.Name{NSDiscoInfo, "query"}, DiscoInfo{}) + TypeRegistry.MapExtension(PKTIQ, xml.Name{NSDiscoItems, "query"}, DiscoItems{}) +} diff --git a/stanza/iq_version.go b/stanza/iq_version.go new file mode 100644 index 0000000..ebf4452 --- /dev/null +++ b/stanza/iq_version.go @@ -0,0 +1,25 @@ +package stanza + +import "encoding/xml" + +// ============================================================================ +// Software Version (XEP-0092) + +// Version +type Version struct { + XMLName xml.Name `xml:"jabber:iq:version query"` + Name string `xml:"name,omitempty"` + Version string `xml:"version,omitempty"` + OS string `xml:"os,omitempty"` +} + +func (v *Version) Namespace() string { + return v.XMLName.Space +} + +// ============================================================================ +// Registry init + +func init() { + TypeRegistry.MapExtension(PKTIQ, xml.Name{"jabber:iq:version", "query"}, Version{}) +}