changeset 14:a62d7d453f22

wokkel integration, part II - disco client - fallback handler (for unmanaged iq requests) - software version (XEP-0092)
author Goffi <goffi@goffi.org>
date Fri, 30 Oct 2009 20:05:25 +0100
parents bd9e9997d540
children 218ec9984fa5
files sat.tac tools/memory.py
diffstat 2 files changed, 21 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/sat.tac	Fri Oct 30 17:38:27 2009 +0100
+++ b/sat.tac	Fri Oct 30 20:05:25 2009 +0100
@@ -19,6 +19,8 @@
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 """
 
+client_name = u'SàT (Salut à toi)'
+client_version = '0.0.1'
 
 from twisted.application import internet, service
 from twisted.internet import glib2reactor, protocol, task
@@ -30,7 +32,7 @@
 from twisted.internet import reactor
 import pdb
 
-from wokkel import client, disco, xmppim
+from wokkel import client, disco, xmppim, generic
 
 from sat_bridge.DBus import DBusBridge
 import logging
@@ -140,7 +142,6 @@
                 status or "", int(priority))
 
         #now it's time to notify frontends
-        pdb.set_trace()
         self.host.bridge.presenceUpdate(entity.full(), "", show or "",
                 status or "", int(priority))
     
@@ -169,6 +170,10 @@
     def unsubscribeReceived(self, entity):
         debug ("unsubscription asked for [%s]" % entity)
 
+class SatDiscoProtocol(disco.DiscoClientProtocol):
+    def __init__(self, host):
+        disco.DiscoClientProtocol.__init__(self)
+
 class SAT(service.Service):
     
     def __init__(self):
@@ -235,6 +240,12 @@
         self.presence = SatPresenceProtocol(self)
         self.presence.setHandlerParent(self.xmppclient)
 
+        self.fallBack = generic.FallbackHandler()
+        self.fallBack.setHandlerParent(self.xmppclient)
+
+        self.versionHandler = generic.VersionHandler(unicode(client_name), client_version)
+        self.versionHandler.setHandlerParent(self.xmppclient)
+
         self.xmppclient.startService()
     
     def disconnect(self):
@@ -272,17 +283,15 @@
         
         #FIXME:tmp
         self.xmlstream.addObserver("/iq[@type='set' or @type='get']", self.iqCb)
-        """
         ###FIXME: tmp disco ###
-        #self.discoHandler = disco.discoHandler()
-        self.memory.registerFeature("http://jabber.org/protocol/disco#info")
-        self.disco(self.memory.getParamV("Server", "Connection"), self.serverDisco)
+        self.disco = SatDiscoProtocol(self)
+        self.disco.setHandlerParent(self.xmppclient)
+        self.disco.requestInfo(jid.JID(self.memory.getParamV("Server", "Connection"))).addCallback(self.serverDisco)
         #we now send our presence status
 
         # add a callback for the messages
 
         #reactor.callLater(2,self.sendFile,"goffi2@jabber.goffi.int/Psi", "/tmp/fakefile")
-        """
         
 
     def sendMessage(self,to,msg,type='chat'):
@@ -318,16 +327,6 @@
 
     ## jabber methods ##
 
-    def disco (self, item, callback, node=None):
-        """XEP-0030 Service discovery Feature."""
-        """disco=client.IQ(self.xmlstream,'get')
-        disco["from"]=self.me.full()
-        disco["to"]=item
-        disco.addElement(('http://jabber.org/protocol/disco#info', 'query'))
-        disco.addCallback(callback)
-        disco.send()"""
-
-
     def setPresence(self, to="", type="", show="", status="", priority=0):
         """Send our presence information"""
         if not type in ["", "unavailable", "subscribed", "subscribe",
@@ -385,13 +384,11 @@
 
     def serverDisco(self, disco):
         """xep-0030 Discovery Protocol."""
-        for element in disco.firstChildElement().elements():
-            if element.name=="feature":
-                debug ("Feature dectetee: %s",element["var"])
-                self.server_features.append(element["var"])
-            elif element.name=="identity":
-                debug ("categorie= %s",element["category"])
-        debug ("features= %s",self.server_features)
+        for feature in disco.features:
+            debug ("Feature found: %s",feature)
+            self.server_features.append(feature)
+        for cat, type in disco.identities:
+            debug ("Identity found: [%s/%s] %s" % (cat, type, disco.identities[(cat,type)]))
 
     ## Generic HMI ## 
 
--- a/tools/memory.py	Fri Oct 30 17:38:27 2009 +0100
+++ b/tools/memory.py	Fri Oct 30 20:05:25 2009 +0100
@@ -177,7 +177,3 @@
         if not self.params.has_key(namespace):
             self.params[namespace]={}
         self.params[namespace][name]=[value,type];
-
-    def registerFeature(self, feature, callback=None):
-        self.features[feature]=callback
-