comparison src/core/xmpp.py @ 341:9eebdc655b8b

code: added asyncConnect
author Goffi <goffi@goffi.org>
date Thu, 26 May 2011 16:49:47 +0200
parents 953536246d9d
children ca3a041fed30
comparison
equal deleted inserted replaced
340:2572351d875a 341:9eebdc655b8b
32 self.factory.clientConnectionLost = self.connectionLost 32 self.factory.clientConnectionLost = self.connectionLost
33 self.__connected=False 33 self.__connected=False
34 self.profile = profile 34 self.profile = profile
35 self.host_app = host_app 35 self.host_app = host_app
36 self.client_initialized = defer.Deferred() 36 self.client_initialized = defer.Deferred()
37 self.conn_deferred = defer.Deferred()
38
39 def getConnectionDeferred(self):
40 """Return a deferred which fire when the client is connected"""
41 return self.conn_deferred
37 42
38 def _authd(self, xmlstream): 43 def _authd(self, xmlstream):
39 if not self.host_app.trigger.point("XML Initialized", xmlstream, self.profile): 44 if not self.host_app.trigger.point("XML Initialized", xmlstream, self.profile):
40 return 45 return
41 client.XMPPClient._authd(self, xmlstream) 46 client.XMPPClient._authd(self, xmlstream)
63 68
64 self.presence.available() 69 self.presence.available()
65 70
66 self.disco.requestInfo(jid.JID(self.host_app.memory.getParamA("Server", "Connection", profile_key=self.profile))).addCallback(self.host_app.serverDisco, self.profile) #FIXME: use these informations 71 self.disco.requestInfo(jid.JID(self.host_app.memory.getParamA("Server", "Connection", profile_key=self.profile))).addCallback(self.host_app.serverDisco, self.profile) #FIXME: use these informations
67 self.disco.requestItems(jid.JID(self.host_app.memory.getParamA("Server", "Connection", profile_key=self.profile))).addCallback(self.host_app.serverDiscoItems, self.disco, self.profile, self.client_initialized) 72 self.disco.requestItems(jid.JID(self.host_app.memory.getParamA("Server", "Connection", profile_key=self.profile))).addCallback(self.host_app.serverDiscoItems, self.disco, self.profile, self.client_initialized)
73 self.conn_deferred.callback(None)
68 74
69 def initializationFailed(self, reason): 75 def initializationFailed(self, reason):
70 print ("initializationFailed: %s" % reason) 76 print ("initializationFailed: %s" % reason)
71 self.host_app.bridge.connectionError("AUTH_ERROR", self.profile) 77 self.host_app.bridge.connectionError("AUTH_ERROR", self.profile)
72 try: 78 try:
73 client.XMPPClient.initializationFailed(self, reason) 79 client.XMPPClient.initializationFailed(self, reason)
74 except: 80 except:
75 #we already send an error signal, no need to raise an exception 81 #we already send an error signal, no need to raise an exception
76 pass 82 pass
83 self.conn_deferred.errback()
77 84
78 def isConnected(self): 85 def isConnected(self):
79 return self.__connected 86 return self.__connected
80 87
81 def connectionLost(self, connector, unused_reason): 88 def connectionLost(self, connector, unused_reason):
260 _pass = query.addElement('password') 267 _pass = query.addElement('password')
261 _pass.addContent(self.user_pass) 268 _pass.addContent(self.user_pass)
262 if self.user_email: 269 if self.user_email:
263 _email = query.addElement('email') 270 _email = query.addElement('email')
264 _email.addContent(self.user_email) 271 _email.addContent(self.user_email)
265 print iq.toXml()
266 reg = iq.send(self.jabber_host).addCallbacks(self.registrationAnswer, self.registrationFailure) 272 reg = iq.send(self.jabber_host).addCallbacks(self.registrationAnswer, self.registrationFailure)
267 273
268 def registrationAnswer(self, answer): 274 def registrationAnswer(self, answer):
269 debug (_("registration answer: %s") % answer.toXml()) 275 debug (_("registration answer: %s") % answer.toXml())
270 answer_type = "SUCCESS" 276 answer_type = "SUCCESS"