wokkel integration, part II

- disco client
- fallback handler (for unmanaged iq requests)
- software version (XEP-0092)
This commit is contained in:
Goffi 2009-10-30 20:05:25 +01:00
commit af75e43558
2 changed files with 21 additions and 28 deletions

45
sat.tac
View file

@ -19,6 +19,8 @@ You should have received a copy of the GNU General Public License
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.words.xish import domish
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 @@ class SatPresenceProtocol(xmppim.PresenceClientProtocol):
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 @@ class SatPresenceProtocol(xmppim.PresenceClientProtocol):
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 @@ class SAT(service.Service):
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 @@ class SAT(service.Service):
#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 @@ class SAT(service.Service):
## 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 @@ class SAT(service.Service):
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 ##

View file

@ -177,7 +177,3 @@ class Memory:
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