aboutsummaryrefslogtreecommitdiff
path: root/xmpp
diff options
context:
space:
mode:
Diffstat (limited to 'xmpp')
-rw-r--r--xmpp/extensions/extensions.go26
-rw-r--r--xmpp/gateway/gateway.go22
-rw-r--r--xmpp/handlers.go21
3 files changed, 53 insertions, 16 deletions
diff --git a/xmpp/extensions/extensions.go b/xmpp/extensions/extensions.go
index 2d547af..192b630 100644
--- a/xmpp/extensions/extensions.go
+++ b/xmpp/extensions/extensions.go
@@ -154,12 +154,19 @@ type CarbonSent struct {
}
// ComponentPrivilege is from XEP-0356
-type ComponentPrivilege struct {
+type ComponentPrivilege1 struct {
XMLName xml.Name `xml:"urn:xmpp:privilege:1 privilege"`
Perms []ComponentPerm `xml:"perm"`
Forwarded stanza.Forwarded `xml:"urn:xmpp:forward:0 forwarded"`
}
+// 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"`
+}
+
// ComponentPerm is from XEP-0356
type ComponentPerm struct {
XMLName xml.Name `xml:"perm"`
@@ -227,7 +234,12 @@ func (c CarbonSent) Namespace() string {
}
// Namespace is a namespace!
-func (c ComponentPrivilege) Namespace() string {
+func (c ComponentPrivilege1) Namespace() string {
+ return c.XMLName.Space
+}
+
+// Namespace is a namespace!
+func (c ComponentPrivilege2) Namespace() string {
return c.XMLName.Space
}
@@ -297,11 +309,17 @@ func init() {
"sent",
}, CarbonSent{})
- // component privilege
+ // component privilege v1
stanza.TypeRegistry.MapExtension(stanza.PKTMessage, xml.Name{
"urn:xmpp:privilege:1",
"privilege",
- }, ComponentPrivilege{})
+ }, ComponentPrivilege1{})
+
+ // component privilege v2
+ stanza.TypeRegistry.MapExtension(stanza.PKTMessage, xml.Name{
+ "urn:xmpp:privilege:2",
+ "privilege",
+ }, ComponentPrivilege2{})
// message edit
stanza.TypeRegistry.MapExtension(stanza.PKTMessage, xml.Name{
diff --git a/xmpp/gateway/gateway.go b/xmpp/gateway/gateway.go
index 1be2fca..7a2500e 100644
--- a/xmpp/gateway/gateway.go
+++ b/xmpp/gateway/gateway.go
@@ -38,8 +38,8 @@ var IdsDB badger.IdsDB
// were changed and need to be re-flushed to the YamlDB
var DirtySessions = false
-// MessageOutgoingPermission allows to fake outgoing messages by foreign JIDs
-var MessageOutgoingPermission = false
+// MessageOutgoingPermissionVersion contains a XEP-0356 version to fake outgoing messages by foreign JIDs
+var MessageOutgoingPermissionVersion = 0
// SendMessage creates and sends a message stanza
func SendMessage(to string, from string, body string, id string, component *xmpp.Component, reply *Reply, isCarbon bool) {
@@ -142,11 +142,19 @@ func sendMessageWrapper(to string, from string, body string, id string, componen
To: toJid.Domain,
},
}
- privilegeMessage.Extensions = append(privilegeMessage.Extensions, extensions.ComponentPrivilege{
- Forwarded: stanza.Forwarded{
- Stanza: carbonMessage,
- },
- })
+ if MessageOutgoingPermissionVersion == 2 {
+ privilegeMessage.Extensions = append(privilegeMessage.Extensions, extensions.ComponentPrivilege2{
+ Forwarded: stanza.Forwarded{
+ Stanza: carbonMessage,
+ },
+ })
+ } else {
+ privilegeMessage.Extensions = append(privilegeMessage.Extensions, extensions.ComponentPrivilege1{
+ Forwarded: stanza.Forwarded{
+ Stanza: carbonMessage,
+ },
+ })
+ }
sendMessage(&privilegeMessage, component)
} else {
sendMessage(&message, component)
diff --git a/xmpp/handlers.go b/xmpp/handlers.go
index 4e3354e..6679a72 100644
--- a/xmpp/handlers.go
+++ b/xmpp/handlers.go
@@ -209,14 +209,25 @@ func HandleMessage(s xmpp.Sender, p stanza.Packet) {
}
if msg.Body == "" {
- var privilege extensions.ComponentPrivilege
- if ok := msg.Get(&privilege); ok {
- log.Debugf("privilege: %#v", privilege)
+ var privilege1 extensions.ComponentPrivilege1
+ if ok := msg.Get(&privilege1); ok {
+ log.Debugf("privilege1: %#v", privilege1)
}
- for _, perm := range privilege.Perms {
+ for _, perm := range privilege1.Perms {
if perm.Access == "message" && perm.Type == "outgoing" {
- gateway.MessageOutgoingPermission = true
+ gateway.MessageOutgoingPermissionVersion = 1
+ }
+ }
+
+ var privilege2 extensions.ComponentPrivilege2
+ if ok := msg.Get(&privilege2); ok {
+ log.Debugf("privilege2: %#v", privilege2)
+ }
+
+ for _, perm := range privilege2.Perms {
+ if perm.Access == "message" && perm.Type == "outgoing" {
+ gateway.MessageOutgoingPermissionVersion = 2
}
}
}