comparison src/core/xmpp.py @ 944:e1842ebcb2f3

core, plugin XEP-0115: discovery refactoring: - hashing algorithm of XEP-0115 has been including in core - our own hash is still calculated by XEP-0115 and can be regenerated with XEP_0115.recalculateHash - old discovery methods have been removed. Now the following methods are used: - hasFeature: tell if a feature is available for an entity - getDiscoInfos: self explaining - getDiscoItems: self explaining - findServiceEntities: return all available items of an entity which given (category, type) - findFeaturesSet: search for a set of features in entity + entity's items all these methods are asynchronous, and manage cache automatically - XEP-0115 manage in a better way hashes, and now use a trigger for presence instead of monkey patch - new FeatureNotFound exception, when we want to do something which is not available - refactored client initialisation sequence, removed client.initialized Deferred - added constant APP_URL - test_plugin_xep_0033.py has been temporarly deactivated, the time to adapt it - lot of cleaning
author Goffi <goffi@goffi.org>
date Fri, 28 Mar 2014 18:07:22 +0100
parents 34dd9287dfe5
children 61c4755f0394
comparison
equal deleted inserted replaced
943:71926ec2114d 944:e1842ebcb2f3
39 client.XMPPClient.__init__(self, user_jid, password, host, port) 39 client.XMPPClient.__init__(self, user_jid, password, host, port)
40 self.factory.clientConnectionLost = self.connectionLost 40 self.factory.clientConnectionLost = self.connectionLost
41 self.__connected = False 41 self.__connected = False
42 self.profile = profile 42 self.profile = profile
43 self.host_app = host_app 43 self.host_app = host_app
44 self.client_initialized = defer.Deferred()
45 self.conn_deferred = defer.Deferred() 44 self.conn_deferred = defer.Deferred()
46 self._waiting_conf = {} # callback called when a confirmation is received 45 self._waiting_conf = {} # callback called when a confirmation is received
47 self._progress_cb_map = {} # callback called when a progress is requested (key = progress id) 46 self._progress_cb_map = {} # callback called when a progress is requested (key = progress id)
48 47
49 def getConnectionDeferred(self): 48 def getConnectionDeferred(self):
67 66
68 self.disco = SatDiscoProtocol(self) 67 self.disco = SatDiscoProtocol(self)
69 self.disco.setHandlerParent(self) 68 self.disco.setHandlerParent(self)
70 self.discoHandler = disco.DiscoHandler() 69 self.discoHandler = disco.DiscoHandler()
71 self.discoHandler.setHandlerParent(self) 70 self.discoHandler.setHandlerParent(self)
72 71 disco_d = defer.succeed(None)
73 if not self.host_app.trigger.point("Disco Handled", self.profile): 72
74 return 73 if not self.host_app.trigger.point("Disco handled", disco_d, self.profile):
75 74 return
76 self.roster.requestRoster() 75
77 76 def finish_connection(dummy):
78 self.presence.available() 77 self.roster.requestRoster()
79 78 self.presence.available()
80 jid_ = self.getHostJid() 79 self.conn_deferred.callback(None)
81 self.disco.requestInfo(jid_).addCallback(self.host_app.serverDisco, jid_, self.profile) # FIXME: use these informations 80
82 81 disco_d.addCallback(finish_connection)
83 self.disco.requestItems(jid_).addCallback(self.host_app.serverDiscoItems, self.disco, jid_, self.profile, self.client_initialized)
84 self.conn_deferred.callback(None)
85 82
86 def initializationFailed(self, reason): 83 def initializationFailed(self, reason):
87 error(_("ERROR: XMPP connection failed for profile '%(profile)s': %(reason)s" % {'profile': self.profile, 'reason': reason})) 84 error(_("ERROR: XMPP connection failed for profile '%(profile)s': %(reason)s" % {'profile': self.profile, 'reason': reason}))
88 self.host_app.bridge.connectionError("AUTH_ERROR", self.profile) 85 self.host_app.bridge.connectionError("AUTH_ERROR", self.profile)
89 try: 86 try:
103 self.keep_alife.stop() 100 self.keep_alife.stop()
104 except AttributeError: 101 except AttributeError:
105 debug(_("No keep_alife")) 102 debug(_("No keep_alife"))
106 self.host_app.bridge.disconnected(self.profile) # we send the signal to the clients 103 self.host_app.bridge.disconnected(self.profile) # we send the signal to the clients
107 self.host_app.purgeClient(self.profile) # and we remove references to this client 104 self.host_app.purgeClient(self.profile) # and we remove references to this client
108
109 def getHostJid(self):
110 """@return: the jid of the local server"""
111 return jid.JID(self.jid.host)
112 105
113 106
114 class SatMessageProtocol(xmppim.MessageProtocol): 107 class SatMessageProtocol(xmppim.MessageProtocol):
115 108
116 def __init__(self, host): 109 def __init__(self, host):
290 283
291 def __init__(self, host): 284 def __init__(self, host):
292 xmppim.PresenceClientProtocol.__init__(self) 285 xmppim.PresenceClientProtocol.__init__(self)
293 self.host = host 286 self.host = host
294 287
288 def send(self, obj):
289 if not self.host.trigger.point("Presence send", obj):
290 return
291 super(SatPresenceProtocol, self).send(obj)
292
295 def availableReceived(self, entity, show=None, statuses=None, priority=0): 293 def availableReceived(self, entity, show=None, statuses=None, priority=0):
296 debug(_("presence update for [%(entity)s] (available, show=%(show)s statuses=%(statuses)s priority=%(priority)d)") % {'entity': entity, 'show': show, 'statuses': statuses, 'priority': priority}) 294 debug(_("presence update for [%(entity)s] (available, show=%(show)s statuses=%(statuses)s priority=%(priority)d)") % {'entity': entity, 'show': show, 'statuses': statuses, 'priority': priority})
297 295
298 if not statuses: 296 if not statuses:
299 statuses = {} 297 statuses = {}
432 _pass = query.addElement('password') 430 _pass = query.addElement('password')
433 _pass.addContent(self.user_pass) 431 _pass.addContent(self.user_pass)
434 if self.user_email: 432 if self.user_email:
435 _email = query.addElement('email') 433 _email = query.addElement('email')
436 _email.addContent(self.user_email) 434 _email.addContent(self.user_email)
437 reg = iq.send(self.jabber_host).addCallbacks(self.registrationAnswer, self.registrationFailure) 435 iq.send(self.jabber_host).addCallbacks(self.registrationAnswer, self.registrationFailure)
438 436
439 def registrationAnswer(self, answer): 437 def registrationAnswer(self, answer):
440 debug(_("registration answer: %s") % answer.toXml()) 438 debug(_("registration answer: %s") % answer.toXml())
441 answer_type = "SUCCESS" 439 answer_type = "SUCCESS"
442 answer_data = {"message": _("Registration successfull")} 440 answer_data = {"message": _("Registration successfull")}