From 02ee2f2087e73bfc50365f96c7416f261e2b3b97 Mon Sep 17 00:00:00 2001 From: Martin/Geno Date: Thu, 15 Feb 2018 20:56:04 +0100 Subject: [PATCH] implements some XEP in xmpp struct library --- README.md | 12 ++++++------ xmpp/client_iq.go | 12 ++++++++---- xmpp/compression.go | 30 ++++++++++++++++++++++++++++++ xmpp/connection.go | 11 ++++++----- xmpp/iq/namespaces.go | 29 +++++++++++++++++++---------- xmpp/iq/ping.go | 2 +- xmpp/iq/private_xml_storage.go | 9 +++++++++ xmpp/iq/register.go | 21 +++++++++++++++++++++ xmpp/iq/service_discovery.go | 26 +++++++++++++------------- xmpp/iq/vcard.go | 14 ++++++++++++++ xmpp/iq/version.go | 13 +++++++++++++ xmpp/iq/wip.go | 19 ------------------- xmpp/wip.go | 11 +++++++++++ 13 files changed, 151 insertions(+), 58 deletions(-) create mode 100644 xmpp/compression.go create mode 100644 xmpp/iq/private_xml_storage.go create mode 100644 xmpp/iq/register.go create mode 100644 xmpp/iq/vcard.go create mode 100644 xmpp/iq/version.go delete mode 100644 xmpp/iq/wip.go create mode 100644 xmpp/wip.go diff --git a/README.md b/README.md index de9342b..4096519 100644 --- a/README.md +++ b/README.md @@ -8,9 +8,6 @@ ## Features - XMPP Library (first version - PR are welcome) - - RFC 6120 (XMPP - Core) - - XEP 0030: Service Discovery - - XEP-0199: XMPP Ping - Client Library (WIP) - Stream: TLS Required - SASL-Auth (PLAIN, DIGEST-MD5) @@ -34,9 +31,12 @@ all implementation of all comman (RFCs and XEPs) xml element **Version** -- RFC 6120 (XMPP - Core) -- XEP 0030: Service Discovery -- XEP-0199: XMPP Ping +- [RFC 6120 (XMPP - Core)](https://xmpp.org/rfcs/rfc3920.html) +- [XEP 0030: Service Discovery](https://xmpp.org/extensions/xep-0030.html) +- [XEP-0049: Private XML Storage](https://xmpp.org/extensions/xep-0049.html) +- [XEP-0092: Software Version](https://xmpp.org/extensions/xep-0092.html) +- [XEP-0138: Stream Compression](https://xmpp.org/extensions/xep-0138.html) +- [XEP-0199: XMPP Ping](https://xmpp.org/extensions/xep-0199.html) ### Client diff --git a/xmpp/client_iq.go b/xmpp/client_iq.go index 4e8a72c..feaa07c 100644 --- a/xmpp/client_iq.go +++ b/xmpp/client_iq.go @@ -16,10 +16,14 @@ type IQClient struct { Type IQType `xml:"type,attr"` // required Error *ErrorClient - Bind *Bind // RFC 6120 A.7 Resource binding namespace (But in a IQ?) - Ping *xmppiq.Ping // XEP-0199: XMPP Ping (see iq/ping.go) - PrivateQuery *xmppiq.IQPrivateQuery // which XEP ? - PrivateRegister *xmppiq.IQPrivateRegister // which XEP ? + Bind *Bind // RFC 6120 A.7 Resource binding namespace (But in a IQ?) + DiscoQueryInfo *xmppiq.DiscoQueryInfo // XEP-0030: XMPP Service Discovery (see iq/service_discovery.go) + DiscoQueryItem *xmppiq.DiscoQueryItem // XEP-0030: XMPP Service Discovery (see iq/service_discovery.go) + PrivateXMLStorage *xmppiq.PrivateXMLStorage // XEP-0049: Private XML Storage (see iq/private_xml_storage.go) + VCard *xmppiq.VCard // XEP-0054: vcard-temp (see iq/vcard.go) - WIP + Register *xmppiq.Register // XEP-0077: In-Band Registration - 14.1 (see iq/register.go) - WIP + Version *xmppiq.Version // XEP-0092: Software Version (see iq/version.go) + Ping *xmppiq.Ping // XEP-0199: XMPP Ping (see iq/ping.go) // Any hasn't matched element Other []XMLElement `xml:",any"` diff --git a/xmpp/compression.go b/xmpp/compression.go new file mode 100644 index 0000000..68b8e36 --- /dev/null +++ b/xmpp/compression.go @@ -0,0 +1,30 @@ +package xmpp + +import "encoding/xml" + +// CompressionFeature implements XEP-0138: Stream Compression - 10.1 Stream Feature +type CompressionFeature struct { + XMLName xml.Name `xml:"http://jabber.org/features/compress compression"` + Methods []string `xml:"method"` +} + +// CompressionCompress implements XEP-0138: Stream Compression - 10.2 Protocol Namespace +type CompressionCompress struct { + XMLName xml.Name `xml:"http://jabber.org/protocol/compress compress"` + Methods []string `xml:"method"` +} + +// CompressionCompressed implements XEP-0138: Stream Compression - 10.2 Protocol Namespace +type CompressionCompressed struct { + XMLName xml.Name `xml:"http://jabber.org/protocol/compress compressed"` +} + +// CompressionFailure implements XEP-0138: Stream Compression - 10.2 Protocol Namespace +type CompressionFailure struct { + XMLName xml.Name `xml:"http://jabber.org/protocol/compress failure"` + SetupFailed *xml.Name `xml:"http://jabber.org/protocol/compress setup-failed"` + ProcessingFailed *xml.Name `xml:"http://jabber.org/protocol/compress processing-failed"` + UnsupportedFailed *xml.Name `xml:"http://jabber.org/protocol/compress unsupported-failed"` + Text *Text + StanzaErrorGroup +} diff --git a/xmpp/connection.go b/xmpp/connection.go index 64c7294..f62c1f7 100644 --- a/xmpp/connection.go +++ b/xmpp/connection.go @@ -8,11 +8,12 @@ import ( // StreamFeatures implements RFC 6120 - A.1 Stream Namespace type StreamFeatures struct { - XMLName xml.Name `xml:"http://etherx.jabber.org/streams features"` - StartTLS *TLSStartTLS - Mechanisms SASLMechanisms - Bind *Bind - Session bool + XMLName xml.Name `xml:"http://etherx.jabber.org/streams features"` + StartTLS *TLSStartTLS + Mechanisms SASLMechanisms // RFC 6120 - A.4 SASL Namespace (see sasl.go) + Compression *CompressionFeature // XEP-0138: Stream Compression (see compression.go) + Bind *Bind + Session bool } // TLSStartTLS implements RFC 6120 - A.3 StartTLS Namespace diff --git a/xmpp/iq/namespaces.go b/xmpp/iq/namespaces.go index 7a3ed9e..2040f10 100644 --- a/xmpp/iq/namespaces.go +++ b/xmpp/iq/namespaces.go @@ -1,18 +1,27 @@ package xmppiq const ( - // NSIQPing implements XEP-0199: XMPP Ping - 10 - NSIQPing = "urn:xmpp:ping" + // NSDiscoInfo implements XEP 0030: Service Discovery - 11.1 disco#info + NSDiscoInfo = "http://jabber.org/protocol/disco#info" - // NSIQDiscoInfo implements XEP 0030: Service Discovery - 11.1 disco#info - NSIQDiscoInfo = "http://jabber.org/protocol/disco#info" + // NSDiscoItems implements XEP 0030: Service Discovery - 11.2 disco#items + NSDiscoItems = "http://jabber.org/protocol/disco#items" - // NSIQDiscoItems implements XEP 0030: Service Discovery - 11.2 disco#items - NSIQDiscoItems = "http://jabber.org/protocol/disco#items" + // NSPrivateXMLStorage implements XEP-0049: Private XML Storage - 7 + NSPrivateXMLStorage = "jabber:iq:private" - // NSIQRegister implements which XEP ? - NSIQRegister = "jabber:iq:register" + // NSVCard implements XEP-0054: vcard-temp - 14 (WIP) + NSVCard = "vcard-temp" - // NSFeaturesIQRegister implements which XEP ? - NSFeaturesIQRegister = "http://jabber.org/features/iq-register" + // NSVersion implements XEP-0092: Software Version - 4 + NSVersion = "jabber:iq:version" + + // NSPing implements XEP-0199: XMPP Ping - 10 + NSPing = "urn:xmpp:ping" + + // NSRegister implements XEP-0077: In-Band Registration - 14.1 jabber:iq:register + NSRegister = "jabber:iq:register" + + // NSFeatureRegister implements XEP-0077: In-Band Registration - 14.2 Stream Feature + NSFeatureRegister = "http://jabber.org/features/iq-register" ) diff --git a/xmpp/iq/ping.go b/xmpp/iq/ping.go index 178e48b..baf6096 100644 --- a/xmpp/iq/ping.go +++ b/xmpp/iq/ping.go @@ -4,7 +4,7 @@ import ( "encoding/xml" ) -// XEP-0199: XMPP Ping +// Ping implements XEP-0199: XMPP Ping - 10 type Ping struct { XMLName xml.Name `xml:"urn:xmpp:ping ping"` } diff --git a/xmpp/iq/private_xml_storage.go b/xmpp/iq/private_xml_storage.go new file mode 100644 index 0000000..34fc613 --- /dev/null +++ b/xmpp/iq/private_xml_storage.go @@ -0,0 +1,9 @@ +package xmppiq + +import "encoding/xml" + +// PrivateXMLStorage implements XEP-0049: Private XML Storage - 7 +type PrivateXMLStorage struct { + XMLName xml.Name `xml:"jabber:iq:private query"` + Body []byte `xml:",innerxml"` +} diff --git a/xmpp/iq/register.go b/xmpp/iq/register.go new file mode 100644 index 0000000..552e959 --- /dev/null +++ b/xmpp/iq/register.go @@ -0,0 +1,21 @@ +package xmppiq + +import ( + "encoding/xml" +) + +// WARNING WIP + +// Register implements XEP-0077: In-Band Registration - 14.1 jabber:iq:register +//TODO +type Register struct { + XMLName xml.Name `xml:"jabber:iq:register query"` + Instructions string `xml:"instructions"` + Username string `xml:"username"` + Password string `xml:"password"` +} + +// FeatureRegister implements XEP-0077: In-Band Registration - 14.2 Stream Feature +type FeatureRegister struct { + XMLName xml.Name `xml:"http://jabber.org/features/iq-register register"` +} diff --git a/xmpp/iq/service_discovery.go b/xmpp/iq/service_discovery.go index c4d9d56..c312f52 100644 --- a/xmpp/iq/service_discovery.go +++ b/xmpp/iq/service_discovery.go @@ -6,37 +6,37 @@ import ( "dev.sum7.eu/genofire/yaja/xmpp/base" ) -// IQDiscoQueryInfo implements XEP 0030: Service Discovery - 11.1 disco#info -type IQDiscoQueryInfo struct { +// DiscoQueryInfo implements XEP 0030: Service Discovery - 11.1 disco#info +type DiscoQueryInfo struct { XMLName xml.Name `xml:"http://jabber.org/protocol/disco#info query"` Node *string `xml:"node,attr"` - Identities []*IQDiscoIdentity - Features []*IQDiscoFeature + Identities []*DiscoIdentity + Features []*DiscoFeature } -// IQDiscoIdentity implements XEP 0030: Service Discovery - 11.1 disco#info -type IQDiscoIdentity struct { +// DiscoIdentity implements XEP 0030: Service Discovery - 11.1 disco#info +type DiscoIdentity struct { XMLName xml.Name `xml:"http://jabber.org/protocol/disco#info identity"` Category string `xml:"category"` //required Name *string `xml:"name"` Type string `xml:"type"` //required } -// IQDiscoFeature implements XEP 0030: Service Discovery - 11.1 disco#info -type IQDiscoFeature struct { +// DiscoFeature implements XEP 0030: Service Discovery - 11.1 disco#info +type DiscoFeature struct { XMLName xml.Name `xml:"http://jabber.org/protocol/disco#info feature"` Var string `xml:"var"` //required } -// IQDiscoQueryItem implements XEP 0030: Service Discovery - 11.2 disco#items -type IQDiscoQueryItem struct { +// DiscoQueryItem implements XEP 0030: Service Discovery - 11.2 disco#items +type DiscoQueryItem struct { XMLName xml.Name `xml:"http://jabber.org/protocol/disco#items query"` Node *string `xml:"node,attr"` - Items []*IQDiscoItem + Items []*DiscoItem } -// IQDiscoItem implements XEP 0030: Service Discovery - 11.2 disco#items -type IQDiscoItem struct { +// DiscoItem implements XEP 0030: Service Discovery - 11.2 disco#items +type DiscoItem struct { XMLName xml.Name `xml:"http://jabber.org/protocol/disco#items item"` JID *xmppbase.JID `xml:"jid"` Node *string `xml:"node"` diff --git a/xmpp/iq/vcard.go b/xmpp/iq/vcard.go new file mode 100644 index 0000000..e7e7614 --- /dev/null +++ b/xmpp/iq/vcard.go @@ -0,0 +1,14 @@ +package xmppiq + +import ( + "encoding/xml" +) + +// WARNING WIP + +// VCard implements XEP-0054: vcard-temp - 14 +//TODO +type VCard struct { + XMLName xml.Name `xml:"vcard-temp vCard"` + Body []byte `xml:",innerxml"` +} diff --git a/xmpp/iq/version.go b/xmpp/iq/version.go new file mode 100644 index 0000000..1791f09 --- /dev/null +++ b/xmpp/iq/version.go @@ -0,0 +1,13 @@ +package xmppiq + +import ( + "encoding/xml" +) + +// Version implements XEP-0092: Software Version - 4 +type Version struct { + XMLName xml.Name `xml:"jabber:iq:version query"` + Name string `xml:"name"` //required + Version string `xml:"version"` //required + OS *string `xml:"os"` +} diff --git a/xmpp/iq/wip.go b/xmpp/iq/wip.go deleted file mode 100644 index 23ee1aa..0000000 --- a/xmpp/iq/wip.go +++ /dev/null @@ -1,19 +0,0 @@ -package xmppiq - -import ( - "encoding/xml" -) - -// which XEP ???? -// where to put: (server part debug? is it part) -type IQPrivateQuery struct { - XMLName xml.Name `xml:"jabber:iq:private query"` - Body []byte `xml:",innerxml"` -} - -type IQPrivateRegister struct { - XMLName xml.Name `xml:"jabber:iq:register query"` - Instructions string `xml:"instructions"` - Username string `xml:"username"` - Password string `xml:"password"` -} diff --git a/xmpp/wip.go b/xmpp/wip.go new file mode 100644 index 0000000..aa70fcb --- /dev/null +++ b/xmpp/wip.go @@ -0,0 +1,11 @@ +package xmpp + +const ( + // NSDiscoOfflineMessages implements XEP-0160: Best Practices for Handling Offline Messages - 7 + //TODO where to put?? + NSDiscoOfflineMessages = "msgoffline" + + // NSDiscoSocks5Bytestreams implements XEP-0065: SOCKS5 Bytestreams - 14 + //TODO where to put WIP iq implemention + NSDiscoSocks5Bytestreams = "http://jabber.org/protocol/bytestreams" +)