From 198db6c2ca3579dd4ff446433bd3db5cd90754e2 Mon Sep 17 00:00:00 2001 From: Goffi Date: Sat, 26 Jan 2019 20:07:45 +0100 Subject: [PATCH] plugin XEP-0045: fixed crash when is used at an unexpected time. --- sat/core/xmpp.py | 5 ++++- sat/plugins/plugin_xep_0045.py | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/sat/core/xmpp.py b/sat/core/xmpp.py index c0cb3c08..985c68bc 100644 --- a/sat/core/xmpp.py +++ b/sat/core/xmpp.py @@ -871,7 +871,10 @@ class SatMessageProtocol(xmppim.MessageProtocol): if message_elt.uri is None: # wokkel element parsing strip out root namespace - message_elt.uri = C.NS_CLIENT + message_elt.defaultUri = message_elt.uri = C.NS_CLIENT + for c in message_elt.children: + if c.uri is None: + c.uri == C.NS_CLIENT elif message_elt.uri != C.NS_CLIENT: log.warning(_( u"received with a wrong namespace: {xml}" diff --git a/sat/plugins/plugin_xep_0045.py b/sat/plugins/plugin_xep_0045.py index f4584e08..74ef948d 100755 --- a/sat/plugins/plugin_xep_0045.py +++ b/sat/plugins/plugin_xep_0045.py @@ -1133,6 +1133,24 @@ class SatMUCClient(muc.MUCClient): u"received history in unexpected state in room {room} (state: " u"{state})").format(room = room.roomJID.userhost(), state = room.state)) + if not hasattr(room, "_history_d"): + # XXX: this hack is due to buggy behaviour seen in the wild because of the + # "mod_delay" prosody module being activated. This module add an + # unexpected elements which break our workflow. + log.warning(_(u"storing the unexpected message anyway, to avoid loss")) + # we have to restore URI which are stripped by wokkel parsing + for c in message.element.children: + if c.uri is None: + c.uri = C.NS_CLIENT + mess_data = self.client.messageProt.parseMessage(message.element) + message.element._mess_data = mess_data + self._addToHistory(None, user, message) + if mess_data[u'message'] or mess_data[u'subject']: + self.host.bridge.messageNew( + *self.client.messageGetBridgeArgs(mess_data), + profile=self.client.profile + ) + return room._history_d.addCallback(self._addToHistory, user, message) room._history_d.addErrback(self._addToHistoryEb)