comparison src/core/xmpp.py @ 666:2a7185b8452c

core: added SatIdentityHandler for Disco Identity, and set identity to "client/pc/Salut à Toi"
author Goffi <goffi@goffi.org>
date Tue, 05 Nov 2013 22:40:55 +0100
parents 8004c7d4aba7
children ffb716804580
comparison
equal deleted inserted replaced
665:6a64e0a759e6 666:2a7185b8452c
17 # You should have received a copy of the GNU Affero General Public License 17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19
20 from twisted.internet import task, defer 20 from twisted.internet import task, defer
21 from twisted.words.protocols.jabber import jid, xmlstream 21 from twisted.words.protocols.jabber import jid, xmlstream
22 from wokkel import client, disco, xmppim, generic, compat, delay 22 from wokkel import client, disco, xmppim, generic, compat, delay, iwokkel
23 from logging import debug, info, warning, error 23 from logging import debug, info, warning, error
24 from sat.core import exceptions 24 from sat.core import exceptions
25 from calendar import timegm 25 from calendar import timegm
26 from zope.interface import implements
27 try:
28 from twisted.words.protocols.xmlstream import XMPPHandler
29 except ImportError:
30 from wokkel.subprotocols import XMPPHandler
26 31
27 32
28 class SatXMPPClient(client.XMPPClient): 33 class SatXMPPClient(client.XMPPClient):
34 implements(iwokkel.IDisco)
29 35
30 def __init__(self, host_app, profile, user_jid, password, host=None, port=5222): 36 def __init__(self, host_app, profile, user_jid, password, host=None, port=5222):
31 client.XMPPClient.__init__(self, user_jid, password, host, port) 37 client.XMPPClient.__init__(self, user_jid, password, host, port)
32 self.factory.clientConnectionLost = self.connectionLost 38 self.factory.clientConnectionLost = self.connectionLost
33 self.__connected = False 39 self.__connected = False
449 # node) as it cause issues with XEP-0115 & PEP (XEP-0163): there is a node when server 455 # node) as it cause issues with XEP-0115 & PEP (XEP-0163): there is a node when server
450 # ask for disco info, and not when we generate the key, so the hash is used with different 456 # ask for disco info, and not when we generate the key, so the hash is used with different
451 # disco features, and when the server (seen on ejabberd) generate its own hash for security check 457 # disco features, and when the server (seen on ejabberd) generate its own hash for security check
452 # it reject our features (resulting in e.g. no notification on PEP) 458 # it reject our features (resulting in e.g. no notification on PEP)
453 return generic.VersionHandler.getDiscoInfo(self, requestor, target, None) 459 return generic.VersionHandler.getDiscoInfo(self, requestor, target, None)
460
461 class SatIdentityHandler(XMPPHandler):
462 """ Manage disco Identity of SàT. Currently, we use "client/pc/Salut à Toi", but as
463 SàT is multi-frontends and can be used on mobile devices, as a bot, with a web frontend,
464 etc, we should implement a way to dynamically update identities through the bridge """
465 #TODO: dynamic identity update (see docstring). Note that a XMPP entity can have several identities
466 implements(iwokkel.IDisco)
467
468 def getDiscoInfo(self, requestor, target, nodeIdentifier=''):
469 return [disco.DiscoIdentity(u"client", u"pc", u"Salut à Toi")]
470
471 def getDiscoItems(self, requestor, target, nodeIdentifier=''):
472 return []