comparison src/core/xmpp.py @ 2130:f0bc29dc8157

added "send" trigger point as the last one before sending, can be used for e2e encryption
author Goffi <goffi@goffi.org>
date Sat, 04 Feb 2017 17:59:15 +0100
parents 9c861d07b5b6
children c0577837680a
comparison
equal deleted inserted replaced
2129:6a66c8c5a567 2130:f0bc29dc8157
23 from twisted.internet import task, defer 23 from twisted.internet import task, defer
24 from twisted.words.protocols.jabber.xmlstream import XMPPHandler 24 from twisted.words.protocols.jabber.xmlstream import XMPPHandler
25 from twisted.words.protocols.jabber import xmlstream 25 from twisted.words.protocols.jabber import xmlstream
26 from twisted.words.protocols.jabber import error 26 from twisted.words.protocols.jabber import error
27 from twisted.words.protocols.jabber import jid 27 from twisted.words.protocols.jabber import jid
28 from twisted.words.xish import domish
28 from twisted.python import failure 29 from twisted.python import failure
29 from wokkel import client as wokkel_client, disco, xmppim, generic, iwokkel 30 from wokkel import client as wokkel_client, disco, xmppim, generic, iwokkel
30 from wokkel import delay 31 from wokkel import delay
31 from sat.core.log import getLogger 32 from sat.core.log import getLogger
32 log = getLogger(__name__) 33 log = getLogger(__name__)
91 @param condition(unicode): error condition 92 @param condition(unicode): error condition
92 """ 93 """
93 iq_error_elt = error.StanzaError(condition).toResponse(iq_elt) 94 iq_error_elt = error.StanzaError(condition).toResponse(iq_elt)
94 self.xmlstream.send(iq_error_elt) 95 self.xmlstream.send(iq_error_elt)
95 96
97 def send(self, obj):
98 # original send method accept string
99 # but we restrict to domish.Element to make trigger treatments easier
100 assert isinstance(obj, domish.Element)
101 # XXX: this trigger is the last one before sending stanza on wire
102 # is it is intended for things like end 2 end encryption.
103 # *DO NOT* cancel (i.e. return False) without very good reason
104 # (out of band transmission for instance).
105 # e2e should have a priority of 0 here, and out of band transmission
106 # a lower priority
107 if not self.host_app.trigger.point("send", self, obj):
108 return
109 return super(SatXMPPClient, self).send(obj)
110
111
96 def _authd(self, xmlstream): 112 def _authd(self, xmlstream):
97 if not self.host_app.trigger.point("XML Initialized", xmlstream, self.profile): 113 if not self.host_app.trigger.point("XML Initialized", xmlstream, self.profile):
98 return 114 return
99 wokkel_client.XMPPClient._authd(self, xmlstream) 115 wokkel_client.XMPPClient._authd(self, xmlstream)
100 self.__connected = True 116 self.__connected = True