aboutsummaryrefslogtreecommitdiff
path: root/xmpp
diff options
context:
space:
mode:
Diffstat (limited to 'xmpp')
-rw-r--r--xmpp/gateway/gateway.go45
-rw-r--r--xmpp/handlers.go5
2 files changed, 40 insertions, 10 deletions
diff --git a/xmpp/gateway/gateway.go b/xmpp/gateway/gateway.go
index 89f1eb8..9a42077 100644
--- a/xmpp/gateway/gateway.go
+++ b/xmpp/gateway/gateway.go
@@ -44,30 +44,35 @@ var MessageOutgoingPermissionVersion = 0
// SendMessage creates and sends a message stanza
func SendMessage(to, from, body, id string, component *xmpp.Component, reply *Reply, timestamp int64, isCarbon, isGroupchat bool, originalFrom string) {
- sendMessageWrapper(to, from, body, "", id, component, reply, timestamp, "", isCarbon, isGroupchat, false, originalFrom)
+ sendMessageWrapper(to, from, body, "", id, component, reply, timestamp, "", isCarbon, isGroupchat, false, originalFrom, 0)
}
// SendServiceMessage creates and sends a simple message stanza from transport
func SendServiceMessage(to, body string, component *xmpp.Component) {
- sendMessageWrapper(to, "", body, "", "", component, nil, 0, "", false, false, false, "")
+ sendMessageWrapper(to, "", body, "", "", component, nil, 0, "", false, false, false, "", 0)
}
// SendTextMessage creates and sends a simple message stanza
func SendTextMessage(to, from, body string, component *xmpp.Component) {
- sendMessageWrapper(to, from, body, "", "", component, nil, 0, "", false, false, false, "")
+ sendMessageWrapper(to, from, body, "", "", component, nil, 0, "", false, false, false, "", 0)
+}
+
+// SendErrorMessage creates and sends an error message stanza
+func SendErrorMessage(to, from, text string, code int, isGroupchat bool, component *xmpp.Component) {
+ sendMessageWrapper(to, from, text, "", "", component, nil, 0, "", false, isGroupchat, false, "", code)
}
// SendMessageWithOOB creates and sends a message stanza with OOB URL
func SendMessageWithOOB(to, from, body, id string, component *xmpp.Component, reply *Reply, timestamp int64, oob string, isCarbon, isGroupchat bool, originalFrom string) {
- sendMessageWrapper(to, from, body, "", id, component, reply, timestamp, oob, isCarbon, isGroupchat, false, originalFrom)
+ sendMessageWrapper(to, from, body, "", id, component, reply, timestamp, oob, isCarbon, isGroupchat, false, originalFrom, 0)
}
// SendSubjectMessage creates and sends a MUC subject
func SendSubjectMessage(to, from, subject, id string, component *xmpp.Component, timestamp int64) {
- sendMessageWrapper(to, from, "", subject, id, component, nil, timestamp, "", false, true, true, "")
+ sendMessageWrapper(to, from, "", subject, id, component, nil, timestamp, "", false, true, true, "", 0)
}
-func sendMessageWrapper(to, from, body, subject, id string, component *xmpp.Component, reply *Reply, timestamp int64, oob string, isCarbon, isGroupchat, forceSubject bool, originalFrom string) {
+func sendMessageWrapper(to, from, body, subject, id string, component *xmpp.Component, reply *Reply, timestamp int64, oob string, isCarbon, isGroupchat, forceSubject bool, originalFrom string, errorCode int) {
toJid, err := stanza.NewJid(to)
if err != nil {
log.WithFields(log.Fields{
@@ -107,7 +112,9 @@ func sendMessageWrapper(to, from, body, subject, id string, component *xmpp.Comp
}).Warn("Got message")
var messageType stanza.StanzaType
- if isGroupchat {
+ if errorCode != 0 {
+ messageType = stanza.MessageTypeError
+ } else if isGroupchat {
messageType = stanza.MessageTypeGroupchat
} else {
messageType = stanza.MessageTypeChat
@@ -121,7 +128,29 @@ func sendMessageWrapper(to, from, body, subject, id string, component *xmpp.Comp
Id: id,
},
Subject: subject,
- Body: body,
+ }
+ if errorCode == 0 {
+ message.Body = body
+ } else {
+ message.Error = stanza.Err{
+ Code: errorCode,
+ Text: body,
+ }
+ switch errorCode {
+ case 400:
+ message.Error.Type = stanza.ErrorTypeModify
+ message.Error.Reason = "bad-request"
+ case 404:
+ message.Error.Type = stanza.ErrorTypeCancel
+ message.Error.Reason = "item-not-found"
+ case 500:
+ message.Error.Type = stanza.ErrorTypeWait
+ message.Error.Reason = "internal-server-error"
+ default:
+ log.Error("Unknown error code, falling back with empty reason")
+ message.Error.Type = stanza.ErrorTypeCancel
+ message.Error.Reason = "undefined-condition"
+ }
}
if oob != "" {
diff --git a/xmpp/handlers.go b/xmpp/handlers.go
index 0b3e71f..72b46eb 100644
--- a/xmpp/handlers.go
+++ b/xmpp/handlers.go
@@ -194,10 +194,11 @@ func HandleMessage(s xmpp.Sender, p stanza.Packet) {
return
}
}
+ isGroupchat := msg.Type == "groupchat"
session.SendMessageLock.Lock()
defer session.SendMessageLock.Unlock()
- tgMessage := session.ProcessOutgoingMessage(toID, text, msg.From, replyId, replaceId)
+ tgMessage := session.ProcessOutgoingMessage(toID, text, msg.From, replyId, replaceId, isGroupchat)
if tgMessage != nil {
if replaceId != 0 {
// not needed (is it persistent among clients though?)
@@ -214,7 +215,7 @@ func HandleMessage(s xmpp.Sender, p stanza.Packet) {
}
// pong groupchat messages back
- if msg.Type == "groupchat" {
+ if isGroupchat {
toJid, err := stanza.NewJid(msg.To)
if err == nil && toJid.Resource == "" {
session.SendMessageToGateway(