Mercurial > libervia-backend
comparison sat.tac @ 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 |
comparison
equal
deleted
inserted
replaced
13:bd9e9997d540 | 14:a62d7d453f22 |
---|---|
17 | 17 |
18 You should have received a copy of the GNU General Public License | 18 You should have received a copy of the GNU General Public License |
19 along with this program. If not, see <http://www.gnu.org/licenses/>. | 19 along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 """ | 20 """ |
21 | 21 |
22 client_name = u'SàT (Salut à toi)' | |
23 client_version = '0.0.1' | |
22 | 24 |
23 from twisted.application import internet, service | 25 from twisted.application import internet, service |
24 from twisted.internet import glib2reactor, protocol, task | 26 from twisted.internet import glib2reactor, protocol, task |
25 glib2reactor.install() | 27 glib2reactor.install() |
26 | 28 |
28 from twisted.words.xish import domish | 30 from twisted.words.xish import domish |
29 | 31 |
30 from twisted.internet import reactor | 32 from twisted.internet import reactor |
31 import pdb | 33 import pdb |
32 | 34 |
33 from wokkel import client, disco, xmppim | 35 from wokkel import client, disco, xmppim, generic |
34 | 36 |
35 from sat_bridge.DBus import DBusBridge | 37 from sat_bridge.DBus import DBusBridge |
36 import logging | 38 import logging |
37 from logging import debug, info, error | 39 from logging import debug, info, error |
38 | 40 |
138 status = statuses.values()[0] if len(statuses) else "" | 140 status = statuses.values()[0] if len(statuses) else "" |
139 self.host.memory.addPresenceStatus(entity.full(), "", show or "", | 141 self.host.memory.addPresenceStatus(entity.full(), "", show or "", |
140 status or "", int(priority)) | 142 status or "", int(priority)) |
141 | 143 |
142 #now it's time to notify frontends | 144 #now it's time to notify frontends |
143 pdb.set_trace() | |
144 self.host.bridge.presenceUpdate(entity.full(), "", show or "", | 145 self.host.bridge.presenceUpdate(entity.full(), "", show or "", |
145 status or "", int(priority)) | 146 status or "", int(priority)) |
146 | 147 |
147 def unavailableReceived(self, entity, statuses=None): | 148 def unavailableReceived(self, entity, statuses=None): |
148 #TODO: management of differents statuses (differents languages) | 149 #TODO: management of differents statuses (differents languages) |
166 debug ("subscription request for [%s]" % entity) | 167 debug ("subscription request for [%s]" % entity) |
167 self.subscribed(entity) | 168 self.subscribed(entity) |
168 | 169 |
169 def unsubscribeReceived(self, entity): | 170 def unsubscribeReceived(self, entity): |
170 debug ("unsubscription asked for [%s]" % entity) | 171 debug ("unsubscription asked for [%s]" % entity) |
172 | |
173 class SatDiscoProtocol(disco.DiscoClientProtocol): | |
174 def __init__(self, host): | |
175 disco.DiscoClientProtocol.__init__(self) | |
171 | 176 |
172 class SAT(service.Service): | 177 class SAT(service.Service): |
173 | 178 |
174 def __init__(self): | 179 def __init__(self): |
175 #self.reactor=reactor | 180 #self.reactor=reactor |
233 self.roster.setHandlerParent(self.xmppclient) | 238 self.roster.setHandlerParent(self.xmppclient) |
234 | 239 |
235 self.presence = SatPresenceProtocol(self) | 240 self.presence = SatPresenceProtocol(self) |
236 self.presence.setHandlerParent(self.xmppclient) | 241 self.presence.setHandlerParent(self.xmppclient) |
237 | 242 |
243 self.fallBack = generic.FallbackHandler() | |
244 self.fallBack.setHandlerParent(self.xmppclient) | |
245 | |
246 self.versionHandler = generic.VersionHandler(unicode(client_name), client_version) | |
247 self.versionHandler.setHandlerParent(self.xmppclient) | |
248 | |
238 self.xmppclient.startService() | 249 self.xmppclient.startService() |
239 | 250 |
240 def disconnect(self): | 251 def disconnect(self): |
241 if (not self.isConnected()): | 252 if (not self.isConnected()): |
242 info("not connected !") | 253 info("not connected !") |
270 | 281 |
271 self.presence.available() | 282 self.presence.available() |
272 | 283 |
273 #FIXME:tmp | 284 #FIXME:tmp |
274 self.xmlstream.addObserver("/iq[@type='set' or @type='get']", self.iqCb) | 285 self.xmlstream.addObserver("/iq[@type='set' or @type='get']", self.iqCb) |
275 """ | |
276 ###FIXME: tmp disco ### | 286 ###FIXME: tmp disco ### |
277 #self.discoHandler = disco.discoHandler() | 287 self.disco = SatDiscoProtocol(self) |
278 self.memory.registerFeature("http://jabber.org/protocol/disco#info") | 288 self.disco.setHandlerParent(self.xmppclient) |
279 self.disco(self.memory.getParamV("Server", "Connection"), self.serverDisco) | 289 self.disco.requestInfo(jid.JID(self.memory.getParamV("Server", "Connection"))).addCallback(self.serverDisco) |
280 #we now send our presence status | 290 #we now send our presence status |
281 | 291 |
282 # add a callback for the messages | 292 # add a callback for the messages |
283 | 293 |
284 #reactor.callLater(2,self.sendFile,"goffi2@jabber.goffi.int/Psi", "/tmp/fakefile") | 294 #reactor.callLater(2,self.sendFile,"goffi2@jabber.goffi.int/Psi", "/tmp/fakefile") |
285 """ | |
286 | 295 |
287 | 296 |
288 def sendMessage(self,to,msg,type='chat'): | 297 def sendMessage(self,to,msg,type='chat'): |
289 #FIXME: check validity of recipient | 298 #FIXME: check validity of recipient |
290 debug("Sending jabber message to %s...", to) | 299 debug("Sending jabber message to %s...", to) |
315 #xmppclient not available | 324 #xmppclient not available |
316 pass | 325 pass |
317 return False | 326 return False |
318 | 327 |
319 ## jabber methods ## | 328 ## jabber methods ## |
320 | |
321 def disco (self, item, callback, node=None): | |
322 """XEP-0030 Service discovery Feature.""" | |
323 """disco=client.IQ(self.xmlstream,'get') | |
324 disco["from"]=self.me.full() | |
325 disco["to"]=item | |
326 disco.addElement(('http://jabber.org/protocol/disco#info', 'query')) | |
327 disco.addCallback(callback) | |
328 disco.send()""" | |
329 | |
330 | 329 |
331 def setPresence(self, to="", type="", show="", status="", priority=0): | 330 def setPresence(self, to="", type="", show="", status="", priority=0): |
332 """Send our presence information""" | 331 """Send our presence information""" |
333 if not type in ["", "unavailable", "subscribed", "subscribe", | 332 if not type in ["", "unavailable", "subscribed", "subscribe", |
334 "unsubscribe", "unsubscribed", "prob", "error"]: | 333 "unsubscribe", "unsubscribed", "prob", "error"]: |
383 | 382 |
384 | 383 |
385 | 384 |
386 def serverDisco(self, disco): | 385 def serverDisco(self, disco): |
387 """xep-0030 Discovery Protocol.""" | 386 """xep-0030 Discovery Protocol.""" |
388 for element in disco.firstChildElement().elements(): | 387 for feature in disco.features: |
389 if element.name=="feature": | 388 debug ("Feature found: %s",feature) |
390 debug ("Feature dectetee: %s",element["var"]) | 389 self.server_features.append(feature) |
391 self.server_features.append(element["var"]) | 390 for cat, type in disco.identities: |
392 elif element.name=="identity": | 391 debug ("Identity found: [%s/%s] %s" % (cat, type, disco.identities[(cat,type)])) |
393 debug ("categorie= %s",element["category"]) | |
394 debug ("features= %s",self.server_features) | |
395 | 392 |
396 ## Generic HMI ## | 393 ## Generic HMI ## |
397 | 394 |
398 def askConfirmation(self, id, type, data, cb): | 395 def askConfirmation(self, id, type, data, cb): |
399 """Add a confirmation callback""" | 396 """Add a confirmation callback""" |