Backport a few XMPPPY upstream changes.

* Use namespace instead of attrs={} for addChild
 * Unplug SASL module on auth failure (we currently disconnect so don't really need it)
This commit is contained in:
Stephan Erb 2008-12-28 14:53:20 +00:00
parent f83eb5ae95
commit d8a2d8f447
9 changed files with 36 additions and 22 deletions

View File

@ -480,11 +480,8 @@ class CommandWindow:
assert action in ('execute', 'prev', 'next', 'complete') assert action in ('execute', 'prev', 'next', 'complete')
stanza = xmpp.Iq(typ='set', to=self.jid) stanza = xmpp.Iq(typ='set', to=self.jid)
cmdnode = stanza.addChild('command', attrs={ cmdnode = stanza.addChild('command', namespace=xmpp.NS_COMMANDS, attrs={
'xmlns':xmpp.NS_COMMANDS, 'node':self.commandnode, 'action':action})
'node':self.commandnode,
'action':action
})
if self.sessionid: if self.sessionid:
cmdnode.setAttr('sessionid', self.sessionid) cmdnode.setAttr('sessionid', self.sessionid)
@ -511,8 +508,7 @@ class CommandWindow:
if self.sessionid and self.account.connection: if self.sessionid and self.account.connection:
# we already have sessionid, so the service sent at least one reply. # we already have sessionid, so the service sent at least one reply.
stanza = xmpp.Iq(typ='set', to=self.jid) stanza = xmpp.Iq(typ='set', to=self.jid)
stanza.addChild('command', attrs={ stanza.addChild('command', namespace=xmpp.NS_COMMANDS, attrs={
'xmlns':xmpp.NS_COMMANDS,
'node':self.commandnode, 'node':self.commandnode,
'sessionid':self.sessionid, 'sessionid':self.sessionid,
'action':'cancel' 'action':'cancel'

View File

@ -50,8 +50,7 @@ class AdHocCommand:
assert status in ('executing', 'completed', 'canceled') assert status in ('executing', 'completed', 'canceled')
response = request.buildReply('result') response = request.buildReply('result')
cmd = response.addChild('command', { cmd = response.addChild('command', namespace=xmpp.NS_COMMANDS, attrs={
'xmlns': xmpp.NS_COMMANDS,
'sessionid': self.sessionid, 'sessionid': self.sessionid,
'node': self.commandnode, 'node': self.commandnode,
'status': status}) 'status': status})

View File

@ -33,7 +33,7 @@ class ConnectionPubSub:
if not self.connection or self.connected < 2: if not self.connection or self.connected < 2:
return return
query = xmpp.Iq('get', to=jid) query = xmpp.Iq('get', to=jid)
pb = query.addChild('pubsub', {'xmlns': xmpp.NS_PUBSUB}) pb = query.addChild('pubsub', namespace=xmpp.NS_PUBSUB)
pb.addChild('subscriptions') pb.addChild('subscriptions')
id_ = self.connection.send(query) id_ = self.connection.send(query)

View File

@ -1,5 +1,5 @@
## auth_nb.py ## auth_nb.py
## based on auth.py ## based on auth.py, changes backported up to revision 1.41
## ##
## Copyright (C) 2003-2005 Alexey "Snake" Nezhdanov ## Copyright (C) 2003-2005 Alexey "Snake" Nezhdanov
## modified by Dimitur Kirov <dkirov@gmail.com> ## modified by Dimitur Kirov <dkirov@gmail.com>
@ -143,12 +143,18 @@ class SASL(PlugIn):
def plugout(self): def plugout(self):
''' Remove SASL handlers from owner's dispatcher. Used internally. ''' ''' Remove SASL handlers from owner's dispatcher. Used internally. '''
self._owner.UnregisterHandler('features', self.FeaturesHandler, if 'features' in self._owner.__dict__:
xmlns=NS_STREAMS) self._owner.UnregisterHandler('features', self.FeaturesHandler,
self._owner.UnregisterHandler('challenge', self.SASLHandler, xmlns=NS_STREAMS)
xmlns=NS_SASL) if 'challenge' in self._owner.__dict__:
self._owner.UnregisterHandler('failure', self.SASLHandler, xmlns=NS_SASL) self._owner.UnregisterHandler('challenge', self.SASLHandler,
self._owner.UnregisterHandler('success', self.SASLHandler, xmlns=NS_SASL) xmlns=NS_SASL)
if 'failure' in self._owner.__dict__:
self._owner.UnregisterHandler('failure', self.SASLHandler,
xmlns=NS_SASL)
if 'success' in self._owner.__dict__:
self._owner.UnregisterHandler('success', self.SASLHandler,
xmlns=NS_SASL)
def auth(self): def auth(self):
''' '''
@ -187,7 +193,11 @@ class SASL(PlugIn):
self.MechanismHandler() self.MechanismHandler()
def MechanismHandler(self): def MechanismHandler(self):
if 'GSSAPI' in self.mecs and have_kerberos: if 'ANONYMOUS' in self.mecs and self.username is None:
self.mecs.remove('ANONYMOUS')
node = Node('auth',attrs={'xmlns': NS_SASL, 'mechanism': 'ANONYMOUS'})
self.mechanism = 'ANONYMOUS'
elif 'GSSAPI' in self.mecs and have_kerberos:
self.mecs.remove('GSSAPI') self.mecs.remove('GSSAPI')
self.gss_vc = kerberos.authGSSClientInit('xmpp@' + \ self.gss_vc = kerberos.authGSSClientInit('xmpp@' + \
self._owner.xmpp_hostname)[1] self._owner.xmpp_hostname)[1]

View File

@ -44,6 +44,7 @@ class PlugIn:
self._owner=owner self._owner=owner
log.info('Plugging %s __INTO__ %s' % (self, self._owner)) log.info('Plugging %s __INTO__ %s' % (self, self._owner))
if self.__class__.__name__ in owner.__dict__: if self.__class__.__name__ in owner.__dict__:
print "already plugged", self.__class__.__name__
log.debug('Plugging ignored: another instance already plugged.') log.debug('Plugging ignored: another instance already plugged.')
return return
self._old_owners_methods=[] self._old_owners_methods=[]

View File

@ -1,5 +1,6 @@
## client_nb.py ## client_nb.py
## based on client.py ## based on client.py, changes backported up to revision 1.60
## ##
## Copyright (C) 2003-2005 Alexey "Snake" Nezhdanov ## Copyright (C) 2003-2005 Alexey "Snake" Nezhdanov
## modified by Dimitur Kirov <dkirov@gmail.com> ## modified by Dimitur Kirov <dkirov@gmail.com>
@ -461,6 +462,8 @@ class NonBlockingClient:
self.onreceive(None) self.onreceive(None)
if self.SASL.startsasl == 'failure': if self.SASL.startsasl == 'failure':
# wrong user/pass, stop auth # wrong user/pass, stop auth
if 'SASL' in self.__dict__:
self.SASL.PlugOut()
self.connected = None self.connected = None
self._on_sasl_auth(None) self._on_sasl_auth(None)
elif self.SASL.startsasl == 'success': elif self.SASL.startsasl == 'success':

View File

@ -50,7 +50,7 @@ def getRegInfo(disp, host, info={}, sync=True):
iq.setTagData(i,info[i]) iq.setTagData(i,info[i])
if sync: if sync:
disp.SendAndCallForResponse(iq, lambda resp: disp.SendAndCallForResponse(iq, lambda resp:
_ReceivedRegInfo(disp.Dispatcher,resp, host)) _ReceivedRegInfo(disp.Dispatcher, resp, host))
else: else:
disp.SendAndCallForResponse(iq, _ReceivedRegInfo, {'agent': host }) disp.SendAndCallForResponse(iq, _ReceivedRegInfo, {'agent': host })

View File

@ -21,7 +21,7 @@ Simple roster implementation. Can be used though for different tasks like
mass-renaming of contacts. mass-renaming of contacts.
''' '''
from protocol import JID, Iq, Presence, Node, NS_ROSTER from protocol import JID, Iq, Presence, Node, NodeProcessed, NS_ROSTER
from client import PlugIn from client import PlugIn
import logging import logging
@ -64,7 +64,8 @@ class NonBlockingRoster(PlugIn):
jid=item.getAttr('jid') jid=item.getAttr('jid')
if item.getAttr('subscription')=='remove': if item.getAttr('subscription')=='remove':
if self._data.has_key(jid): del self._data[jid] if self._data.has_key(jid): del self._data[jid]
return # Looks like we have a workaround
# raise NodeProcessed # a MUST
log.info('Setting roster item %s...' % jid) log.info('Setting roster item %s...' % jid)
if not self._data.has_key(jid): self._data[jid]={} if not self._data.has_key(jid): self._data[jid]={}
self._data[jid]['name']=item.getAttr('name') self._data[jid]['name']=item.getAttr('name')
@ -75,6 +76,8 @@ class NonBlockingRoster(PlugIn):
for group in item.getTags('group'): self._data[jid]['groups'].append(group.getData()) for group in item.getTags('group'): self._data[jid]['groups'].append(group.getData())
self._data[self._owner.User+'@'+self._owner.Server]={'resources':{},'name':None,'ask':None,'subscription':None,'groups':None,} self._data[self._owner.User+'@'+self._owner.Server]={'resources':{},'name':None,'ask':None,'subscription':None,'groups':None,}
self.set=1 self.set=1
# Looks like we have a workaround
# raise NodeProcessed # a MUST. Otherwise you'll get back an <iq type='error'/>
def PresenceHandler(self,dis,pres): def PresenceHandler(self,dis,pres):
''' Presence tracker. Used internally for setting items' resources state in ''' Presence tracker. Used internally for setting items' resources state in

View File

@ -145,6 +145,8 @@ class Node(object):
def addChild(self, name=None, attrs={}, payload=[], namespace=None, node=None): def addChild(self, name=None, attrs={}, payload=[], namespace=None, node=None):
''' If "node" argument is provided, adds it as child node. Else creates new node from ''' If "node" argument is provided, adds it as child node. Else creates new node from
the other arguments' values and adds it as well.''' the other arguments' values and adds it as well.'''
if 'xmlns' in attrs:
raise AttributeError("Use namespace=x instead of attrs={'xmlns':x}")
if node: if node:
newnode=node newnode=node
node.parent = self node.parent = self