forked from chteufleur/go-xmpp
Add params for presence and disco info
- Add Show, Status, Photo and Nick into presence stanza - Add Node attribute into DiscoInfo payload
This commit is contained in:
parent
160d4cd390
commit
f7b1e7ecb2
|
|
@ -6,8 +6,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
nsDiscoInfo = "http://jabber.org/protocol/disco#info"
|
NsDiscoInfo = "http://jabber.org/protocol/disco#info"
|
||||||
nsDiscoItems = "http://jabber.org/protocol/disco#items"
|
NsDiscoItems = "http://jabber.org/protocol/disco#items"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Service Discovery (XEP-0030) protocol. "Wraps" XMPP instance to provide a
|
// Service Discovery (XEP-0030) protocol. "Wraps" XMPP instance to provide a
|
||||||
|
|
@ -19,6 +19,7 @@ type Disco struct {
|
||||||
// Iq get/result payload for "info" requests.
|
// Iq get/result payload for "info" requests.
|
||||||
type DiscoInfo struct {
|
type DiscoInfo 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"`
|
||||||
Identity []DiscoIdentity `xml:"identity"`
|
Identity []DiscoIdentity `xml:"identity"`
|
||||||
Feature []DiscoFeature `xml:"feature"`
|
Feature []DiscoFeature `xml:"feature"`
|
||||||
}
|
}
|
||||||
|
|
@ -38,6 +39,7 @@ type DiscoFeature struct {
|
||||||
// Iq get/result payload for "items" requests.
|
// Iq get/result payload for "items" requests.
|
||||||
type DiscoItems struct {
|
type DiscoItems 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"`
|
||||||
Item []DiscoItem `xml:"item"`
|
Item []DiscoItem `xml:"item"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -49,13 +51,13 @@ type DiscoItem struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Request information about the service identified by 'to'.
|
// Request information about the service identified by 'to'.
|
||||||
func (disco *Disco) Info(to string, from string) (*DiscoInfo, error) {
|
func (disco *Disco) Info(to, from string) (*DiscoInfo, error) {
|
||||||
|
|
||||||
if from == "" {
|
if from == "" {
|
||||||
from = disco.XMPP.JID.Full()
|
from = disco.XMPP.JID.Full()
|
||||||
}
|
}
|
||||||
|
|
||||||
req := &Iq{Id: UUID4(), Type: "get", To: to, From: from}
|
req := &Iq{Id: UUID4(), Type: IqTypeGet, To: to, From: from}
|
||||||
req.PayloadEncode(&DiscoInfo{})
|
req.PayloadEncode(&DiscoInfo{})
|
||||||
|
|
||||||
resp, err := disco.XMPP.SendRecv(req)
|
resp, err := disco.XMPP.SendRecv(req)
|
||||||
|
|
@ -72,14 +74,14 @@ func (disco *Disco) Info(to string, from string) (*DiscoInfo, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Request items in the service identified by 'to'.
|
// Request items in the service identified by 'to'.
|
||||||
func (disco *Disco) Items(to string, from string) (*DiscoItems, error) {
|
func (disco *Disco) Items(to, from, node string) (*DiscoItems, error) {
|
||||||
|
|
||||||
if from == "" {
|
if from == "" {
|
||||||
from = disco.XMPP.JID.Full()
|
from = disco.XMPP.JID.Full()
|
||||||
}
|
}
|
||||||
|
|
||||||
req := &Iq{Id: UUID4(), Type: "get", To: to, From: from}
|
req := &Iq{Id: UUID4(), Type: IqTypeGet, To: to, From: from}
|
||||||
req.PayloadEncode(&DiscoItems{})
|
req.PayloadEncode(&DiscoItems{Node: node})
|
||||||
|
|
||||||
resp, err := disco.XMPP.SendRecv(req)
|
resp, err := disco.XMPP.SendRecv(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -94,7 +96,7 @@ func (disco *Disco) Items(to string, from string) (*DiscoItems, error) {
|
||||||
return items, err
|
return items, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var discoNamespacePrefix = strings.Split(nsDiscoInfo, "#")[0]
|
var discoNamespacePrefix = strings.Split(NsDiscoInfo, "#")[0]
|
||||||
|
|
||||||
// Matcher instance to match <iq/> stanzas with a disco payload.
|
// Matcher instance to match <iq/> stanzas with a disco payload.
|
||||||
var DiscoPayloadMatcher = MatcherFunc(
|
var DiscoPayloadMatcher = MatcherFunc(
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,15 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
const (
|
||||||
|
IqTypeGet = "get"
|
||||||
|
IqTypeSet = "set"
|
||||||
|
IqTypeResult = "result"
|
||||||
|
IqTypeError = "error"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
// XMPP <iq/> stanza.
|
// XMPP <iq/> stanza.
|
||||||
type Iq struct {
|
type Iq struct {
|
||||||
XMLName xml.Name `xml:"iq"`
|
XMLName xml.Name `xml:"iq"`
|
||||||
|
|
@ -72,6 +81,10 @@ type Presence struct {
|
||||||
Type string `xml:"type,attr,omitempty"`
|
Type string `xml:"type,attr,omitempty"`
|
||||||
To string `xml:"to,attr,omitempty"`
|
To string `xml:"to,attr,omitempty"`
|
||||||
From string `xml:"from,attr,omitempty"`
|
From string `xml:"from,attr,omitempty"`
|
||||||
|
Show string `xml:"show"` // away, chat, dnd, xa
|
||||||
|
Status string `xml:"status"` // sb []clientText
|
||||||
|
Photo string `xml:"photo,omitempty"` // Avatar
|
||||||
|
Nick string `xml:"nick,omitempty"` // Nickname
|
||||||
}
|
}
|
||||||
|
|
||||||
// XMPP <error/>. May occur as a top-level stanza or embedded in another
|
// XMPP <error/>. May occur as a top-level stanza or embedded in another
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue