sum7
/
yaja
Archived
1
0
Fork 0

[TASK] add roster in xmpp library

This commit is contained in:
Martin/Geno 2018-02-22 03:12:07 +01:00
parent 255c2ef9ad
commit 7d73d323a6
No known key found for this signature in database
GPG Key ID: F0D39A37E925E941
19 changed files with 73 additions and 49 deletions

View File

@ -31,8 +31,9 @@
all implementation of all comman (RFCs and XEPs) xml element all implementation of all comman (RFCs and XEPs) xml element
**Version** **Version**
- [RFC 6120 (XMPP - Core)](https://xmpp.org/rfcs/rfc3920.html) - [RFC 6120 (XMPP - Core)](https://xmpp.org/rfcs/rfc6120.html)
- [XEP 0030: Service Discovery](https://xmpp.org/extensions/xep-0030.html) - [RFC 6121 (XMPP - Instant Messaging and Presence)](https://xmpp.org/rfcs/rfc6121.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-0049: Private XML Storage](https://xmpp.org/extensions/xep-0049.html)
- [XEP-0092: Software Version](https://xmpp.org/extensions/xep-0092.html) - [XEP-0092: Software Version](https://xmpp.org/extensions/xep-0092.html)
- [XEP-0138: Stream Compression](https://xmpp.org/extensions/xep-0138.html) - [XEP-0138: Stream Compression](https://xmpp.org/extensions/xep-0138.html)

View File

@ -11,7 +11,7 @@ func init() {
jidRegex = regexp.MustCompile(`^(?:([^@/<>'\" ]+)@)?([^@/<>'\"]+)(?:/([^<>'\" ][^<>'\"]*))?$`) jidRegex = regexp.MustCompile(`^(?:([^@/<>'\" ]+)@)?([^@/<>'\"]+)(?:/([^<>'\" ][^<>'\"]*))?$`)
} }
// JID implements RFC6122: XMPP - Address Format // JID implements RFC 6122: XMPP - Address Format
type JID struct { type JID struct {
Local string Local string
Domain string Domain string

View File

@ -6,7 +6,7 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
// Test Values for NewJID from RFC7622 // Test Values for NewJID from RFC 7622
// https://tools.ietf.org/html/rfc7622 // https://tools.ietf.org/html/rfc7622
func TestNewJID(t *testing.T) { func TestNewJID(t *testing.T) {
assert := assert.New(t) assert := assert.New(t)

View File

@ -9,8 +9,7 @@ type ErrorClient struct {
Type ErrorType `xml:"type,attr"` // required Type ErrorType `xml:"type,attr"` // required
Text *Text Text *Text
// RFC 6120 A.8 Resource binding namespace StanzaErrorGroup // RFC 6120: A.8 Resource binding namespace
StanzaErrorGroup
// Any hasn't matched element // Any hasn't matched element
Other []XMLElement `xml:",any"` Other []XMLElement `xml:",any"`

View File

@ -16,7 +16,8 @@ type IQClient struct {
Type IQType `xml:"type,attr"` // required Type IQType `xml:"type,attr"` // required
Error *ErrorClient Error *ErrorClient
Bind *Bind // RFC 6120 A.7 Resource binding namespace (But in a IQ?) Bind *Bind // RFC 6120: A.7 Resource binding namespace (But in a IQ?)
Roster *xmppiq.RosterQuery // RFC 6121: Appendix D.
DiscoQueryInfo *xmppiq.DiscoQueryInfo // XEP-0030: XMPP Service Discovery (see iq/service_discovery.go) 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) 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) PrivateXMLStorage *xmppiq.PrivateXMLStorage // XEP-0049: Private XML Storage (see iq/private_xml_storage.go)

View File

@ -10,7 +10,7 @@ import (
type StreamFeatures struct { type StreamFeatures struct {
XMLName xml.Name `xml:"http://etherx.jabber.org/streams features"` XMLName xml.Name `xml:"http://etherx.jabber.org/streams features"`
StartTLS *TLSStartTLS StartTLS *TLSStartTLS
Mechanisms SASLMechanisms // RFC 6120 - A.4 SASL Namespace (see sasl.go) Mechanisms SASLMechanisms // RFC 6120: A.4 SASL Namespace (see sasl.go)
Compression *CompressionFeature // XEP-0138: Stream Compression (see compression.go) Compression *CompressionFeature // XEP-0138: Stream Compression (see compression.go)
Bind *Bind Bind *Bind
Session bool Session bool
@ -32,7 +32,7 @@ type TLSFailure struct {
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-tls failure"` XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-tls failure"`
} }
// Bind implements RFC 6120 A.7 Resource binding namespace // Bind implements RFC 6120 - A.7 Resource binding namespace
type Bind struct { type Bind struct {
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-bind bind"` XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-bind bind"`
Resource string `xml:"resource"` Resource string `xml:"resource"`

View File

@ -3,7 +3,7 @@ package xmpp
// ErrorType is a Enum of error attribute type // ErrorType is a Enum of error attribute type
type ErrorType string type ErrorType string
// RFC 6120 part of A.5 Client Namespace and A.6 Server Namespace // RFC 6120: part of A.5 Client Namespace and A.6 Server Namespace
const ( const (
ErrorTypeAuth ErrorType = "auth" ErrorTypeAuth ErrorType = "auth"
ErrorTypeCancel ErrorType = "cancel" ErrorTypeCancel ErrorType = "cancel"

View File

@ -3,7 +3,7 @@ package xmpp
// IQType is a Enum of iq attribute type // IQType is a Enum of iq attribute type
type IQType string type IQType string
// RFC 6120 part of A.5 Client Namespace and A.6 Server Namespace // RFC 6120: part of A.5 Client Namespace and A.6 Server Namespace
const ( const (
IQTypeError IQType = "error" IQTypeError IQType = "error"
IQTypeGet IQType = "get" IQTypeGet IQType = "get"

View File

@ -3,7 +3,7 @@ package xmpp
// MessageType is a Enum of message attribute type // MessageType is a Enum of message attribute type
type MessageType string type MessageType string
// RFC 6120 part of A.5 Client Namespace and A.6 Server Namespace // RFC 6120: part of A.5 Client Namespace and A.6 Server Namespace
const ( const (
MessageTypeChat MessageType = "chat" MessageTypeChat MessageType = "chat"
MessageTypeError MessageType = "error" MessageTypeError MessageType = "error"

View File

@ -3,7 +3,7 @@ package xmpp
// PresenceType is a Enum of presence attribute type // PresenceType is a Enum of presence attribute type
type PresenceType string type PresenceType string
// RFC 6120 part of A.5 Client Namespace and A.6 Server Namespace // RFC 6120: part of A.5 Client Namespace and A.6 Server Namespace
const ( const (
PresenceTypeError PresenceType = "error" PresenceTypeError PresenceType = "error"
PresenceTypeProbe PresenceType = "probe" PresenceTypeProbe PresenceType = "probe"
@ -17,7 +17,7 @@ const (
// PresenceShow is a Enum of presence element show // PresenceShow is a Enum of presence element show
type PresenceShow string type PresenceShow string
// RFC 6120 part of A.5 Client Namespace and A.6 Server Namespace // RFC 6120: part of A.5 Client Namespace and A.6 Server Namespace
const ( const (
PresenceShowAway PresenceShow = "away" PresenceShowAway PresenceShow = "away"
PresenceShowChat PresenceShow = "chat" PresenceShowChat PresenceShow = "chat"

View File

@ -2,7 +2,7 @@ package xmpp
import "encoding/xml" import "encoding/xml"
// StanzaErrorGroup implements RFC 6120 A.8 Resource binding namespace // StanzaErrorGroup implements RFC 6120 - A.8 Resource binding namespace
type StanzaErrorGroup struct { type StanzaErrorGroup struct {
BadRequest *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-stanzas bad-request"` BadRequest *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-stanzas bad-request"`
Conflict *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-stanzas conflict"` Conflict *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-stanzas conflict"`

View File

@ -2,7 +2,7 @@ package xmpp
import "encoding/xml" import "encoding/xml"
// StreamErrorGroup implements RFC 6120 A.2 Stream Error Namespace // StreamErrorGroup implements RFC 6120 - A.2 Stream Error Namespace
type StreamErrorGroup struct { type StreamErrorGroup struct {
BadFormat *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-streams bad-format"` BadFormat *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-streams bad-format"`
BadNamespacePrefix *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-streams bad-namespace-prefix"` BadNamespacePrefix *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-streams bad-namespace-prefix"`
@ -31,7 +31,7 @@ type StreamErrorGroup struct {
UnsupportedVersion *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-streams unsupported-version"` UnsupportedVersion *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-streams unsupported-version"`
} }
// StreamError implements RFC 6120 A.2 Stream Error Namespace // StreamError implements RFC 6120 - A.2 Stream Error Namespace
type StreamError struct { type StreamError struct {
XMLName xml.Name `xml:"http://etherx.jabber.org/streams error"` XMLName xml.Name `xml:"http://etherx.jabber.org/streams error"`
Text *Text Text *Text

View File

@ -2,7 +2,7 @@ package xmpp
import "encoding/xml" import "encoding/xml"
// Text implements RFC 6120 part of A.2 Stream Error Namespace, A.4 SASL Namespace and A.8 Stanza Error Namespace // Text implements RFC 6120 - part of A.2 Stream Error Namespace, A.4 SASL Namespace and A.8 Stanza Error Namespace
type Text struct { type Text struct {
// `xml:"urn:ietf:params:xml:ns:xmpp-streams text"` // `xml:"urn:ietf:params:xml:ns:xmpp-streams text"`
// `xml:"urn:ietf:params:xml:ns:xmpp-sasl text"` // `xml:"urn:ietf:params:xml:ns:xmpp-sasl text"`

View File

@ -1,10 +1,10 @@
package xmppiq package xmppiq
const ( const (
// NSDiscoInfo implements XEP 0030: Service Discovery - 11.1 disco#info // NSDiscoInfo implements XEP-0030: Service Discovery - 11.1 disco#info
NSDiscoInfo = "http://jabber.org/protocol/disco#info" NSDiscoInfo = "http://jabber.org/protocol/disco#info"
// NSDiscoItems implements XEP 0030: Service Discovery - 11.2 disco#items // NSDiscoItems implements XEP-0030: Service Discovery - 11.2 disco#items
NSDiscoItems = "http://jabber.org/protocol/disco#items" NSDiscoItems = "http://jabber.org/protocol/disco#items"
// NSPrivateXMLStorage implements XEP-0049: Private XML Storage - 7 // NSPrivateXMLStorage implements XEP-0049: Private XML Storage - 7

45
xmpp/iq/roster.go Normal file
View File

@ -0,0 +1,45 @@
package xmppiq
import (
"encoding/xml"
"dev.sum7.eu/genofire/yaja/xmpp/base"
)
// RosterQuery implements RFC 6121 - Appendix D. XML Schema for jabber:iq:roster
type RosterQuery struct {
XMLName xml.Name `xml:"jabber:iq:roster query"`
Version string `xml:"ver,attr,omitempty"`
Items []RosterItem `xml:"item"`
}
// RosterAskType is a Enum of item attribute ask
type RosterAskType string
// RFC 6121: Appendix D. XML Schema for jabber:iq:roster
const (
RosterAskSubscribe RosterAskType = "subscribe"
RosterAskNone RosterAskType = ""
)
// RosterAskType is a Enum of item attribute subscription
type RosterSubscriptionType string
// RFC 6121: Appendix D. XML Schema for jabber:iq:roster
const (
RosterSubscriptionBoth RosterSubscriptionType = "both"
RosterSubscriptionFrom RosterSubscriptionType = "from"
RosterSubscriptionNone RosterSubscriptionType = "none"
RosterSubscriptionRemove RosterSubscriptionType = "remove"
RosterSubscriptionTo RosterSubscriptionType = "to"
)
// RosterItem implements RFC 6121 - Appendix D. XML Schema for jabber:iq:roster
type RosterItem struct {
JID *xmppbase.JID `xml:"jid,attr"`
Approved *bool `xml:"approved,attr,omitempty"`
Ask RosterAskType `xml:"ask,attr,omitempty"`
Name string `xml:"name,attr,omitempty"`
Subscription RosterSubscriptionType `xml:"subscription,attr"`
Group []string `xml:"group"`
}

View File

@ -6,7 +6,7 @@ import (
"dev.sum7.eu/genofire/yaja/xmpp/base" "dev.sum7.eu/genofire/yaja/xmpp/base"
) )
// DiscoQueryInfo implements XEP 0030: Service Discovery - 11.1 disco#info // DiscoQueryInfo implements XEP-0030: Service Discovery - 11.1 disco#info
type DiscoQueryInfo struct { type DiscoQueryInfo struct {
XMLName xml.Name `xml:"http://jabber.org/protocol/disco#info query"` XMLName xml.Name `xml:"http://jabber.org/protocol/disco#info query"`
Node string `xml:"node,attr,omitempty"` Node string `xml:"node,attr,omitempty"`
@ -14,7 +14,7 @@ type DiscoQueryInfo struct {
Features []*DiscoFeature Features []*DiscoFeature
} }
// DiscoIdentity implements XEP 0030: Service Discovery - 11.1 disco#info // DiscoIdentity implements XEP-0030: Service Discovery - 11.1 disco#info
type DiscoIdentity struct { type DiscoIdentity struct {
XMLName xml.Name `xml:"http://jabber.org/protocol/disco#info identity"` XMLName xml.Name `xml:"http://jabber.org/protocol/disco#info identity"`
Category string `xml:"category"` //required Category string `xml:"category"` //required
@ -22,20 +22,20 @@ type DiscoIdentity struct {
Type string `xml:"type"` //required Type string `xml:"type"` //required
} }
// DiscoFeature implements XEP 0030: Service Discovery - 11.1 disco#info // DiscoFeature implements XEP-0030: Service Discovery - 11.1 disco#info
type DiscoFeature struct { type DiscoFeature struct {
XMLName xml.Name `xml:"http://jabber.org/protocol/disco#info feature"` XMLName xml.Name `xml:"http://jabber.org/protocol/disco#info feature"`
Var string `xml:"var"` //required Var string `xml:"var"` //required
} }
// DiscoQueryItem implements XEP 0030: Service Discovery - 11.2 disco#items // DiscoQueryItem implements XEP-0030: Service Discovery - 11.2 disco#items
type DiscoQueryItem struct { type DiscoQueryItem struct {
XMLName xml.Name `xml:"http://jabber.org/protocol/disco#items query"` XMLName xml.Name `xml:"http://jabber.org/protocol/disco#items query"`
Node string `xml:"node,attr,omitempty"` Node string `xml:"node,attr,omitempty"`
Items []*DiscoItem Items []*DiscoItem
} }
// DiscoItem implements XEP 0030: Service Discovery - 11.2 disco#items // DiscoItem implements XEP-0030: Service Discovery - 11.2 disco#items
type DiscoItem struct { type DiscoItem struct {
XMLName xml.Name `xml:"http://jabber.org/protocol/disco#items item"` XMLName xml.Name `xml:"http://jabber.org/protocol/disco#items item"`
JID *xmppbase.JID `xml:"jid"` JID *xmppbase.JID `xml:"jid"`

View File

@ -1,21 +0,0 @@
package xmpp
import (
"encoding/xml"
"dev.sum7.eu/genofire/yaja/xmpp/base"
)
// ClientQuery implements which XEP ????
type ClientQuery struct {
Item []RosterItem
}
// RosterItem implements which XEP ????
type RosterItem struct {
XMLName xml.Name `xml:"jabber:iq:roster item"`
JID *xmppbase.JID `xml:",attr"`
Name string `xml:",attr"`
Subscription string `xml:",attr"`
Group []string
}

View File

@ -9,8 +9,7 @@ type ErrorServer struct {
Type ErrorType `xml:"type,attr"` // required Type ErrorType `xml:"type,attr"` // required
Text *Text Text *Text
// RFC 6120 A.8 Resource binding namespace StanzaErrorGroup // RFC 6120: A.8 - Resource binding namespace
StanzaErrorGroup
// Any hasn't matched element // Any hasn't matched element
Other []XMLElement `xml:",any"` Other []XMLElement `xml:",any"`

View File

@ -16,7 +16,7 @@ type IQServer struct {
Type IQType `xml:"type,attr"` // required Type IQType `xml:"type,attr"` // required
Error *ErrorServer Error *ErrorServer
Bind *Bind // RFC 6120 A.7 Resource binding namespace (But in a IQ?) Bind *Bind // RFC 6120: A.7 Resource binding namespace (But in a IQ?)
Ping *xmppiq.Ping // XEP-0199: XMPP Ping (see iq/ping.go) Ping *xmppiq.Ping // XEP-0199: XMPP Ping (see iq/ping.go)
// Any hasn't matched element // Any hasn't matched element