changeset 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 6a64e0a759e6
children a79a6843928c
files src/core/sat_main.py src/core/xmpp.py
diffstat 2 files changed, 23 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/core/sat_main.py	Tue Nov 05 22:40:46 2013 +0100
+++ b/src/core/sat_main.py	Tue Nov 05 22:40:55 2013 +0100
@@ -247,6 +247,9 @@
                                                             self.get_const('client_version'))
             current.versionHandler.setHandlerParent(current)
 
+            current.identityHandler = xmpp.SatIdentityHandler()
+            current.identityHandler.setHandlerParent(current)
+
             debug(_("setting plugins parents"))
 
             for plugin in self.plugins.iteritems():
--- a/src/core/xmpp.py	Tue Nov 05 22:40:46 2013 +0100
+++ b/src/core/xmpp.py	Tue Nov 05 22:40:55 2013 +0100
@@ -19,13 +19,19 @@
 
 from twisted.internet import task, defer
 from twisted.words.protocols.jabber import jid, xmlstream
-from wokkel import client, disco, xmppim, generic, compat, delay
+from wokkel import client, disco, xmppim, generic, compat, delay, iwokkel
 from logging import debug, info, warning, error
 from sat.core import exceptions
 from calendar import timegm
+from zope.interface import implements
+try:
+    from twisted.words.protocols.xmlstream import XMPPHandler
+except ImportError:
+    from wokkel.subprotocols import XMPPHandler
 
 
 class SatXMPPClient(client.XMPPClient):
+    implements(iwokkel.IDisco)
 
     def __init__(self, host_app, profile, user_jid, password, host=None, port=5222):
         client.XMPPClient.__init__(self, user_jid, password, host, port)
@@ -451,3 +457,16 @@
         # disco features, and when the server (seen on ejabberd) generate its own hash for security check
         # it reject our features (resulting in e.g. no notification on PEP)
         return generic.VersionHandler.getDiscoInfo(self, requestor, target, None)
+
+class SatIdentityHandler(XMPPHandler):
+    """ Manage disco Identity of SàT. Currently, we use "client/pc/Salut à Toi", but as
+    SàT is multi-frontends and can be used on mobile devices, as a bot, with a web frontend,
+    etc, we should implement a way to dynamically update identities through the bridge """
+    #TODO: dynamic identity update (see docstring). Note that a XMPP entity can have several identities
+    implements(iwokkel.IDisco)
+
+    def getDiscoInfo(self, requestor, target, nodeIdentifier=''):
+        return [disco.DiscoIdentity(u"client", u"pc", u"Salut à Toi")]
+
+    def getDiscoItems(self, requestor, target, nodeIdentifier=''):
+        return []