diff --git a/sat/plugins/plugin_xep_0077.py b/sat/plugins/plugin_xep_0077.py index 56927abb..13b418e7 100755 --- a/sat/plugins/plugin_xep_0077.py +++ b/sat/plugins/plugin_xep_0077.py @@ -23,8 +23,7 @@ from sat.core import exceptions from sat.core.log import getLogger log = getLogger(__name__) -from twisted.words.protocols.jabber import jid -from twisted.words.protocols.jabber import xmlstream +from twisted.words.protocols.jabber import jid, xmlstream, client from twisted.internet import defer, reactor from sat.tools import xml_tools @@ -46,23 +45,35 @@ PLUGIN_INFO = { class RegisteringAuthenticator(xmlstream.ConnectAuthenticator): - # FIXME: request IQ is not send to check available fields, while XEP recommand to use it + # FIXME: request IQ is not send to check available fields, + # while XEP recommand to use it # FIXME: doesn't handle data form or oob + namespace = 'jabber:client' def __init__(self, jid_, password, email=None): + log.debug(_(u"Registration asked for {jid}").format(jid=jid_)) xmlstream.ConnectAuthenticator.__init__(self, jid_.host) self.jid = jid_ self.password = password self.email = email self.registered = defer.Deferred() - log.debug(_(u"Registration asked for {jid}").format(jid=jid_)) - def connectionMade(self): - log.debug(_(u"Connection made with {server}".format(server=self.jid.host))) - self.xmlstream.otherEntity = jid.JID(self.jid.host) - self.xmlstream.namespace = C.NS_CLIENT - self.xmlstream.sendHeader() + def associateWithStream(self, xs): + xmlstream.ConnectAuthenticator.associateWithStream(self, xs) + xs.addObserver(xmlstream.STREAM_AUTHD_EVENT, self.register) + xs.initializers = [client.CheckVersionInitializer(xs)] + inits = [ (xmlstream.TLSInitiatingInitializer, False), + ] + + for initClass, required in inits: + init = initClass(xs) + init.required = required + xs.initializers.append(init) + + def register(self, xmlstream): + log.debug(_(u"Stream started with {server}, now registering" + .format(server=self.jid.host))) iq = XEP_0077.buildRegisterIQ(self.xmlstream, self.jid, self.password, self.email) d = iq.send(self.jid.host).addCallbacks(self.registrationCb, self.registrationEb) d.chainDeferred(self.registered)