telegabber/xmpp/extensions/extensions.go

459 lines
11 KiB
Go
Raw Permalink Normal View History

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
Desc IqVcardDesc
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"`
}
// 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 {
2023-03-14 21:16:02 +00:00
XMLName xml.Name `xml:"urn:xmpp:fallback:0 fallback"`
For string `xml:"for,attr"`
Body []FallbackBody `xml:"urn:xmpp:fallback:0 body"`
Subject []FallbackSubject `xml:"urn:xmpp:fallback:0 subject"`
2023-03-08 12:51:19 +00:00
}
// FallbackBody is from XEP-0428
type FallbackBody struct {
2023-03-14 21:16:02 +00:00
XMLName xml.Name `xml:"urn:xmpp:fallback:0 body"`
2023-03-08 12:51:19 +00:00
Start string `xml:"start,attr"`
End string `xml:"end,attr"`
}
// FallbackSubject is from XEP-0428
type FallbackSubject struct {
2023-03-14 21:16:02 +00:00
XMLName xml.Name `xml:"urn:xmpp:fallback:0 subject"`
2023-03-08 12:51:19 +00:00
Start string `xml:"start,attr"`
End string `xml:"end,attr"`
}
2023-03-18 21:43:11 +00:00
// CarbonReceived is from XEP-0280
type CarbonReceived struct {
XMLName xml.Name `xml:"urn:xmpp:carbons:2 received"`
Forwarded stanza.Forwarded `xml:"urn:xmpp:forward:0 forwarded"`
}
// CarbonSent is from XEP-0280
type CarbonSent struct {
XMLName xml.Name `xml:"urn:xmpp:carbons:2 sent"`
Forwarded stanza.Forwarded `xml:"urn:xmpp:forward:0 forwarded"`
}
// ComponentPrivilege is from XEP-0356
2023-08-02 21:08:06 +00:00
type ComponentPrivilege1 struct {
2023-03-18 21:43:11 +00:00
XMLName xml.Name `xml:"urn:xmpp:privilege:1 privilege"`
Perms []ComponentPerm `xml:"perm"`
Forwarded stanza.Forwarded `xml:"urn:xmpp:forward:0 forwarded"`
}
2023-08-02 21:08:06 +00:00
// ComponentPrivilege is from XEP-0356
type ComponentPrivilege2 struct {
XMLName xml.Name `xml:"urn:xmpp:privilege:2 privilege"`
Perms []ComponentPerm `xml:"perm"`
Forwarded stanza.Forwarded `xml:"urn:xmpp:forward:0 forwarded"`
}
2023-03-18 21:43:11 +00:00
// ComponentPerm is from XEP-0356
type ComponentPerm struct {
XMLName xml.Name `xml:"perm"`
Access string `xml:"access,attr"`
Type string `xml:"type,attr"`
Push bool `xml:"push,attr"`
}
// ClientMessage is a jabber:client NS message compatible with Prosody's XEP-0356 implementation
type ClientMessage struct {
XMLName xml.Name `xml:"jabber:client message"`
stanza.Attrs
Subject string `xml:"subject,omitempty"`
Body string `xml:"body,omitempty"`
Thread string `xml:"thread,omitempty"`
Error stanza.Err `xml:"error,omitempty"`
Extensions []stanza.MsgExtension `xml:",omitempty"`
}
2023-06-05 08:22:13 +00:00
// Replace is from XEP-0308
type Replace struct {
XMLName xml.Name `xml:"urn:xmpp:message-correct:0 replace"`
Id string `xml:"id,attr"`
}
2023-08-28 14:16:57 +00:00
// QueryRegister is from XEP-0077
type QueryRegister struct {
XMLName xml.Name `xml:"jabber:iq:register query"`
Instructions string `xml:"instructions"`
Username string `xml:"username"`
Registered *QueryRegisterRegistered `xml:"registered"`
Remove *QueryRegisterRemove `xml:"remove"`
ResultSet *stanza.ResultSet `xml:"set,omitempty"`
}
// QueryRegisterRegistered is a child element from XEP-0077
type QueryRegisterRegistered struct {
XMLName xml.Name `xml:"registered"`
}
// QueryRegisterRemove is a child element from XEP-0077
type QueryRegisterRemove struct {
XMLName xml.Name `xml:"remove"`
}
// PresenceXMucUserExtension is from XEP-0045
type PresenceXMucUserExtension struct {
XMLName xml.Name `xml:"http://jabber.org/protocol/muc#user x"`
Item PresenceXMucUserItem
Statuses []PresenceXMucUserStatus
}
// PresenceXMucUserItem is from XEP-0045
type PresenceXMucUserItem struct {
XMLName xml.Name `xml:"item"`
Affiliation string `xml:"affiliation,attr"`
2023-09-18 05:17:25 +00:00
Jid string `xml:"jid,attr"`
Nick string `xml:"nick,attr,omitempty"`
Role string `xml:"role,attr"`
}
// PresenceXMucUserStatus is from XEP-0045
type PresenceXMucUserStatus struct {
XMLName xml.Name `xml:"status"`
Code uint16 `xml:"code,attr"`
}
2023-09-19 08:23:39 +00:00
// MessageDelay is from XEP-0203
type MessageDelay struct {
XMLName xml.Name `xml:"urn:xmpp:delay delay"`
From string `xml:"from,attr"`
Stamp string `xml:"stamp,attr"`
}
// MessageDelayLegacy is from XEP-0203
type MessageDelayLegacy struct {
XMLName xml.Name `xml:"jabber:x:delay x"`
From string `xml:"from,attr"`
Stamp string `xml:"stamp,attr"`
}
2023-09-19 11:31:24 +00:00
// MessageAddresses is from XEP-0033
type MessageAddresses struct {
XMLName xml.Name `xml:"http://jabber.org/protocol/address addresses"`
Addresses []MessageAddress
}
// MessageAddress is from XEP-0033
type MessageAddress struct {
XMLName xml.Name `xml:"address"`
Type string `xml:"type,attr"`
Jid string `xml:"jid,attr"`
}
// EmptySubject is a dummy for MUCs to circumvent omitempty. Not registered as it would conflict with Subject field
type EmptySubject struct {
XMLName xml.Name `xml:"subject"`
}
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!
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
}
2023-03-18 21:43:11 +00:00
// Namespace is a namespace!
func (c CarbonReceived) Namespace() string {
return c.XMLName.Space
}
// Namespace is a namespace!
func (c CarbonSent) Namespace() string {
return c.XMLName.Space
}
// Namespace is a namespace!
2023-08-02 21:08:06 +00:00
func (c ComponentPrivilege1) Namespace() string {
return c.XMLName.Space
}
// Namespace is a namespace!
func (c ComponentPrivilege2) Namespace() string {
2023-03-18 21:43:11 +00:00
return c.XMLName.Space
}
2023-06-05 08:22:13 +00:00
// Namespace is a namespace!
func (c Replace) Namespace() string {
return c.XMLName.Space
}
2023-08-28 14:16:57 +00:00
// Namespace is a namespace!
func (c QueryRegister) Namespace() string {
return c.XMLName.Space
}
// GetSet getsets!
func (c QueryRegister) GetSet() *stanza.ResultSet {
return c.ResultSet
}
// Namespace is a namespace!
func (c PresenceXMucUserExtension) Namespace() string {
return c.XMLName.Space
}
2023-09-19 08:23:39 +00:00
// Namespace is a namespace!
func (c MessageDelay) Namespace() string {
return c.XMLName.Space
}
// Namespace is a namespace!
func (c MessageDelayLegacy) Namespace() string {
return c.XMLName.Space
}
2023-03-18 21:43:11 +00:00
// Name is a packet name
func (ClientMessage) Name() string {
return "message"
}
2023-03-08 12:51:19 +00:00
// 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),
2023-03-18 21:47:08 +00:00
End: strconv.FormatUint(end, 10),
2023-03-08 12:51:19 +00:00
},
},
}
}
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{})
2023-03-18 21:43:11 +00:00
// carbon received
stanza.TypeRegistry.MapExtension(stanza.PKTMessage, xml.Name{
"urn:xmpp:carbons:2",
"received",
}, CarbonReceived{})
// carbon sent
stanza.TypeRegistry.MapExtension(stanza.PKTMessage, xml.Name{
"urn:xmpp:carbons:2",
"sent",
}, CarbonSent{})
2023-08-02 21:08:06 +00:00
// component privilege v1
2023-03-18 21:43:11 +00:00
stanza.TypeRegistry.MapExtension(stanza.PKTMessage, xml.Name{
"urn:xmpp:privilege:1",
"privilege",
2023-08-02 21:08:06 +00:00
}, ComponentPrivilege1{})
// component privilege v2
stanza.TypeRegistry.MapExtension(stanza.PKTMessage, xml.Name{
"urn:xmpp:privilege:2",
"privilege",
}, ComponentPrivilege2{})
2023-06-05 08:22:13 +00:00
// message edit
stanza.TypeRegistry.MapExtension(stanza.PKTMessage, xml.Name{
"urn:xmpp:message-correct:0",
"replace",
}, Replace{})
2023-08-28 14:16:57 +00:00
// register query
stanza.TypeRegistry.MapExtension(stanza.PKTIQ, xml.Name{
"jabber:iq:register",
"query",
}, QueryRegister{})
// presence muc user
stanza.TypeRegistry.MapExtension(stanza.PKTPresence, xml.Name{
"http://jabber.org/protocol/muc#user",
"x",
}, PresenceXMucUserExtension{})
2023-09-19 08:23:39 +00:00
// message delay
stanza.TypeRegistry.MapExtension(stanza.PKTMessage, xml.Name{
"urn:xmpp:delay",
"delay",
}, MessageDelay{})
// legacy message delay
stanza.TypeRegistry.MapExtension(stanza.PKTMessage, xml.Name{
"jabber:x:delay",
"x",
}, MessageDelayLegacy{})
2023-09-19 11:31:24 +00:00
// message addresses
stanza.TypeRegistry.MapExtension(stanza.PKTMessage, xml.Name{
"http://jabber.org/protocol/address",
"addresses",
}, MessageAddresses{})
2019-11-14 20:11:04 +00:00
}