2019-11-24 22:20:07 +00:00
|
|
|
package extensions
|
2019-11-14 20:11:04 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/xml"
|
2023-03-08 12:51:19 +00:00
|
|
|
"strconv"
|
2019-11-14 20:11:04 +00:00
|
|
|
|
|
|
|
"gosrc.io/xmpp/stanza"
|
|
|
|
)
|
|
|
|
|
|
|
|
// PresenceNickExtension is from XEP-0172
|
|
|
|
type PresenceNickExtension struct {
|
|
|
|
XMLName xml.Name `xml:"http://jabber.org/protocol/nick nick"`
|
|
|
|
Text string `xml:",chardata"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// PresenceXVCardUpdateExtension is from XEP-0153
|
|
|
|
type PresenceXVCardUpdateExtension struct {
|
|
|
|
XMLName xml.Name `xml:"vcard-temp:x:update x"`
|
|
|
|
Photo PresenceXVCardUpdatePhoto
|
|
|
|
}
|
|
|
|
|
|
|
|
// PresenceXVCardUpdatePhoto is from XEP-0153
|
|
|
|
type PresenceXVCardUpdatePhoto struct {
|
|
|
|
XMLName xml.Name `xml:"photo"`
|
|
|
|
Text string `xml:",chardata"`
|
|
|
|
}
|
|
|
|
|
2019-12-10 18:34:55 +00:00
|
|
|
// IqVcardTemp is from XEP-0054
|
|
|
|
type IqVcardTemp struct {
|
2022-02-08 20:25:58 +00:00
|
|
|
XMLName xml.Name `xml:"vcard-temp vCard"`
|
|
|
|
Fn IqVcardFn
|
|
|
|
Nickname IqVcardNickname
|
|
|
|
N IqVcardN
|
|
|
|
Tel IqVcardTel
|
|
|
|
Photo IqVcardPhoto
|
2022-06-29 13:56:27 +00:00
|
|
|
Desc IqVcardDesc
|
2021-12-18 16:04:24 +00:00
|
|
|
ResultSet *stanza.ResultSet `xml:"set,omitempty"`
|
2019-12-10 18:34:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// IqVcardFn is vCard/FN
|
|
|
|
type IqVcardFn struct {
|
|
|
|
XMLName xml.Name `xml:"FN"`
|
|
|
|
Text string `xml:",chardata"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// IqVcardNickname is vCard/NICKNAME
|
|
|
|
type IqVcardNickname struct {
|
|
|
|
XMLName xml.Name `xml:"NICKNAME"`
|
|
|
|
Text string `xml:",chardata"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// IqVcardN is vCard/N
|
|
|
|
type IqVcardN struct {
|
|
|
|
XMLName xml.Name `xml:"N"`
|
|
|
|
Family IqVcardNFamily
|
|
|
|
Given IqVcardNGiven
|
|
|
|
Middle IqVcardNMiddle
|
|
|
|
}
|
|
|
|
|
|
|
|
// IqVcardNFamily is vCard/N/FAMILY
|
|
|
|
type IqVcardNFamily struct {
|
|
|
|
XMLName xml.Name `xml:"FAMILY"`
|
|
|
|
Text string `xml:",chardata"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// IqVcardNGiven is vCard/N/GIVEN
|
|
|
|
type IqVcardNGiven struct {
|
|
|
|
XMLName xml.Name `xml:"GIVEN"`
|
|
|
|
Text string `xml:",chardata"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// IqVcardNMiddle is vCard/N/MIDDLE
|
|
|
|
type IqVcardNMiddle struct {
|
|
|
|
XMLName xml.Name `xml:"MIDDLE"`
|
|
|
|
Text string `xml:",chardata"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// IqVcardTel is vCard/TEL
|
|
|
|
type IqVcardTel struct {
|
|
|
|
XMLName xml.Name `xml:"TEL"`
|
|
|
|
Number IqVcardTelNumber
|
|
|
|
}
|
|
|
|
|
|
|
|
// IqVcardTelNumber is vCard/TEL/NUMBER
|
|
|
|
type IqVcardTelNumber struct {
|
|
|
|
XMLName xml.Name `xml:"NUMBER"`
|
|
|
|
Text string `xml:",chardata"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// IqVcardPhoto is vCard/PHOTO
|
|
|
|
type IqVcardPhoto struct {
|
|
|
|
XMLName xml.Name `xml:"PHOTO"`
|
|
|
|
Type IqVcardPhotoType
|
|
|
|
Binval IqVcardPhotoBinval
|
|
|
|
}
|
|
|
|
|
|
|
|
// IqVcardPhotoType is vCard/PHOTO/TYPE
|
|
|
|
type IqVcardPhotoType struct {
|
|
|
|
XMLName xml.Name `xml:"TYPE"`
|
|
|
|
Text string `xml:",chardata"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// IqVcardPhotoBinval is vCard/PHOTO/BINVAL
|
|
|
|
type IqVcardPhotoBinval struct {
|
|
|
|
XMLName xml.Name `xml:"BINVAL"`
|
|
|
|
Text string `xml:",chardata"`
|
|
|
|
}
|
|
|
|
|
2022-06-29 13:56:27 +00:00
|
|
|
// IqVcardDesc is vCard/DESC
|
|
|
|
type IqVcardDesc struct {
|
|
|
|
XMLName xml.Name `xml:"DESC"`
|
|
|
|
Text string `xml:",chardata"`
|
|
|
|
}
|
|
|
|
|
2023-03-05 08:00:53 +00:00
|
|
|
// Reply is from XEP-0461
|
|
|
|
type Reply struct {
|
|
|
|
XMLName xml.Name `xml:"urn:xmpp:reply:0 reply"`
|
|
|
|
To string `xml:"to,attr"`
|
|
|
|
Id string `xml:"id,attr"`
|
|
|
|
}
|
|
|
|
|
2023-03-08 12:51:19 +00:00
|
|
|
// Fallback is from XEP-0428
|
|
|
|
type Fallback struct {
|
|
|
|
XMLName xml.Name `xml:"urn:xmpp:fallback:0 fallback"`
|
|
|
|
For string `xml:"for,attr"`
|
|
|
|
Body []FallbackBody
|
|
|
|
Subject []FallbackSubject
|
|
|
|
}
|
|
|
|
|
|
|
|
// FallbackBody is from XEP-0428
|
|
|
|
type FallbackBody struct {
|
|
|
|
XMLName xml.Name `xml:"body"`
|
|
|
|
Start string `xml:"start,attr"`
|
|
|
|
End string `xml:"end,attr"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// FallbackSubject is from XEP-0428
|
|
|
|
type FallbackSubject struct {
|
|
|
|
XMLName xml.Name `xml:"subject"`
|
|
|
|
Start string `xml:"start,attr"`
|
|
|
|
End string `xml:"end,attr"`
|
|
|
|
}
|
|
|
|
|
2019-11-14 20:11:04 +00:00
|
|
|
// Namespace is a namespace!
|
|
|
|
func (c PresenceNickExtension) Namespace() string {
|
|
|
|
return c.XMLName.Space
|
|
|
|
}
|
|
|
|
|
|
|
|
// Namespace is a namespace!
|
|
|
|
func (c PresenceXVCardUpdateExtension) Namespace() string {
|
|
|
|
return c.XMLName.Space
|
|
|
|
}
|
|
|
|
|
2019-12-10 18:34:55 +00:00
|
|
|
// Namespace is a namespace!
|
|
|
|
func (c IqVcardTemp) Namespace() string {
|
|
|
|
return c.XMLName.Space
|
|
|
|
}
|
|
|
|
|
2022-06-28 23:34:14 +00:00
|
|
|
// GetSet getsets!
|
2021-12-18 16:04:24 +00:00
|
|
|
func (c IqVcardTemp) GetSet() *stanza.ResultSet {
|
|
|
|
return c.ResultSet
|
|
|
|
}
|
|
|
|
|
2023-03-05 08:00:53 +00:00
|
|
|
// Namespace is a namespace!
|
|
|
|
func (c Reply) Namespace() string {
|
|
|
|
return c.XMLName.Space
|
|
|
|
}
|
|
|
|
|
2023-03-08 12:51:19 +00:00
|
|
|
// Namespace is a namespace!
|
|
|
|
func (c Fallback) Namespace() string {
|
|
|
|
return c.XMLName.Space
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewReplyFallback initializes a fallback range
|
|
|
|
func NewReplyFallback(start uint64, end uint64) Fallback {
|
|
|
|
return Fallback{
|
|
|
|
For: "urn:xmpp:reply:0",
|
|
|
|
Body: []FallbackBody{
|
|
|
|
FallbackBody{
|
|
|
|
Start: strconv.FormatUint(start, 10),
|
|
|
|
End: strconv.FormatUint(end, 10),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-14 20:11:04 +00:00
|
|
|
func init() {
|
|
|
|
// presence nick
|
|
|
|
stanza.TypeRegistry.MapExtension(stanza.PKTPresence, xml.Name{
|
|
|
|
"http://jabber.org/protocol/nick",
|
|
|
|
"nick",
|
|
|
|
}, PresenceNickExtension{})
|
|
|
|
|
|
|
|
// presence vcard update
|
|
|
|
stanza.TypeRegistry.MapExtension(stanza.PKTPresence, xml.Name{
|
|
|
|
"vcard-temp:x:update",
|
|
|
|
"x",
|
|
|
|
}, PresenceXVCardUpdateExtension{})
|
2019-12-10 18:34:55 +00:00
|
|
|
|
|
|
|
// iq vcard request
|
|
|
|
stanza.TypeRegistry.MapExtension(stanza.PKTIQ, xml.Name{
|
|
|
|
"vcard-temp",
|
|
|
|
"vCard",
|
|
|
|
}, IqVcardTemp{})
|
2023-03-05 08:00:53 +00:00
|
|
|
|
|
|
|
// reply
|
|
|
|
stanza.TypeRegistry.MapExtension(stanza.PKTMessage, xml.Name{
|
|
|
|
"urn:xmpp:reply:0",
|
|
|
|
"reply",
|
|
|
|
}, Reply{})
|
2023-03-08 12:51:19 +00:00
|
|
|
|
|
|
|
// fallback
|
|
|
|
stanza.TypeRegistry.MapExtension(stanza.PKTMessage, xml.Name{
|
|
|
|
"urn:xmpp:fallback:0",
|
|
|
|
"fallback",
|
|
|
|
}, Fallback{})
|
2019-11-14 20:11:04 +00:00
|
|
|
}
|