Lock the bound JID in the JID cache.

This commit is contained in:
Lance Stout 2012-10-24 12:56:54 -07:00
parent d0666a5eb6
commit a22ca228cc
4 changed files with 17 additions and 9 deletions

View File

@ -69,12 +69,12 @@ class BaseXMPP(XMLStream):
self.stream_id = None self.stream_id = None
#: The JabberID (JID) requested for this connection. #: The JabberID (JID) requested for this connection.
self.requested_jid = JID(jid) self.requested_jid = JID(jid, cache_lock=True)
#: The JabberID (JID) used by this connection, #: The JabberID (JID) used by this connection,
#: as set after session binding. This may even be a #: as set after session binding. This may even be a
#: different bare JID than what was requested. #: different bare JID than what was requested.
self.boundjid = JID(jid) self.boundjid = JID(jid, cache_lock=True)
self._expected_server_name = self.boundjid.host self._expected_server_name = self.boundjid.host
self._redirect_attempts = 0 self._redirect_attempts = 0
@ -665,7 +665,7 @@ class BaseXMPP(XMLStream):
def set_jid(self, jid): def set_jid(self, jid):
"""Rip a JID apart and claim it as our own.""" """Rip a JID apart and claim it as our own."""
log.debug("setting jid to %s", jid) log.debug("setting jid to %s", jid)
self.boundjid.full = jid self.boundjid = JID(jid, cache_lock=True)
def getjidresource(self, fulljid): def getjidresource(self, fulljid):
if '/' in fulljid: if '/' in fulljid:

View File

@ -64,7 +64,6 @@ class ClientXMPP(BaseXMPP):
escape_quotes=True, sasl_mech=None, lang='en'): escape_quotes=True, sasl_mech=None, lang='en'):
BaseXMPP.__init__(self, jid, 'jabber:client') BaseXMPP.__init__(self, jid, 'jabber:client')
self.set_jid(jid)
self.escape_quotes = escape_quotes self.escape_quotes = escape_quotes
self.plugin_config = plugin_config self.plugin_config = plugin_config
self.plugin_whitelist = plugin_whitelist self.plugin_whitelist = plugin_whitelist

View File

@ -8,6 +8,7 @@
import logging import logging
from sleekxmpp.jid import JID
from sleekxmpp.stanza import Iq, StreamFeatures from sleekxmpp.stanza import Iq, StreamFeatures
from sleekxmpp.features.feature_bind import stanza from sleekxmpp.features.feature_bind import stanza
from sleekxmpp.xmlstream import register_stanza_plugin from sleekxmpp.xmlstream import register_stanza_plugin
@ -48,7 +49,7 @@ class FeatureBind(BasePlugin):
iq['bind']['resource'] = self.xmpp.boundjid.resource iq['bind']['resource'] = self.xmpp.boundjid.resource
response = iq.send(now=True) response = iq.send(now=True)
self.xmpp.set_jid(response['bind']['jid']) self.xmpp.boundjid = JID(response['bind']['jid'], cache_lock=True)
self.xmpp.bound = True self.xmpp.bound = True
self.xmpp.event('session_bind', self.xmpp.boundjid, direct=True) self.xmpp.event('session_bind', self.xmpp.boundjid, direct=True)
self.xmpp.session_bind_event.set() self.xmpp.session_bind_event.set()

View File

@ -11,6 +11,7 @@ import hashlib
import random import random
import sys import sys
from sleekxmpp.jid import JID
from sleekxmpp.exceptions import IqError, IqTimeout from sleekxmpp.exceptions import IqError, IqTimeout
from sleekxmpp.stanza import Iq, StreamFeatures from sleekxmpp.stanza import Iq, StreamFeatures
from sleekxmpp.xmlstream import ElementBase, ET, register_stanza_plugin from sleekxmpp.xmlstream import ElementBase, ET, register_stanza_plugin
@ -95,10 +96,11 @@ class XEP_0078(BasePlugin):
iq['auth']['username'] = self.xmpp.requested_jid.user iq['auth']['username'] = self.xmpp.requested_jid.user
# A resource is required, so create a random one if necessary # A resource is required, so create a random one if necessary
if self.xmpp.requested_jid.resource: resource = self.xmpp.requested_jid.resource
iq['auth']['resource'] = self.xmpp.requested_jid.resource if not resource:
else: resource = uuid.uuid4()
iq['auth']['resource'] = '%s' % random.random()
iq['auth']['resource'] = resource
if 'digest' in resp['auth']['fields']: if 'digest' in resp['auth']['fields']:
log.debug('Authenticating via jabber:iq:auth Digest') log.debug('Authenticating via jabber:iq:auth Digest')
@ -130,6 +132,12 @@ class XEP_0078(BasePlugin):
self.xmpp.features.add('auth') self.xmpp.features.add('auth')
self.xmpp.authenticated = True self.xmpp.authenticated = True
self.xmpp.boundjid = JID(self.xmpp.requested_jid,
resource=resource,
cache_lock=True)
self.xmpp.event('session_bind', self.xmpp.boundjid, direct=True)
log.debug("Established Session") log.debug("Established Session")
self.xmpp.sessionstarted = True self.xmpp.sessionstarted = True
self.xmpp.session_started_event.set() self.xmpp.session_started_event.set()