diff options
author | lovetox <philipp@hoerist.com> | 2020-04-11 23:00:24 +0300 |
---|---|---|
committer | lovetox <philipp@hoerist.com> | 2020-04-11 23:00:24 +0300 |
commit | 5d2bcd74e1ce6d798d39e348be6d897e120a9c98 (patch) | |
tree | 13a24b555618f858d37785979e5a35de972d4748 | |
parent | 828ee78b4cb6947050d407656efff1dcb6723574 (diff) |
Smacks: Copy stanza before adding it to the queue
-rw-r--r-- | nbxmpp/smacks.py | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/nbxmpp/smacks.py b/nbxmpp/smacks.py index 95da2ca..ab80b6c 100644 --- a/nbxmpp/smacks.py +++ b/nbxmpp/smacks.py @@ -126,14 +126,13 @@ class Smacks: # We did not yet sent 'enable' so the server # will not count our stanzas return - if (stanza.getName() == 'message' and - stanza.getType() in ('chat', 'groupchat')): - timestamp = time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime()) - attrs = {'stamp': timestamp} - if stanza.getType() != 'groupchat': - # Dont leak our JID to Groupchats - attrs['from'] = str(self._client.get_bound_jid()) - stanza.addChild('delay', namespace=NS_DELAY2, attrs=attrs) + + # Make a full copy so we dont run into problems when + # the stanza is modified after sending for some reason + stanza = type(stanza)(node=str(stanza)) + + self._add_delay(stanza) + self._uqueue.append(stanza) self._log.debug('OUT, %s', stanza.getName()) self._out_h += 1 @@ -144,6 +143,22 @@ class Smacks: if (self._in_h - self._acked_h) > 100: self._send_ack() + def _add_delay(self, stanza): + if stanza.getName() != 'message': + return + + if stanza.getType() not in ('chat', 'groupchat'): + return + + timestamp = time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime()) + attrs = {'stamp': timestamp} + + if stanza.getType() != 'groupchat': + # Dont leak our JID to Groupchats + attrs['from'] = str(self._client.get_bound_jid()) + + stanza.addChild('delay', namespace=NS_DELAY2, attrs=attrs) + def _resend_queue(self): """ Resends unsent stanzas when a new session is established. |