summaryrefslogtreecommitdiff
path: root/sleekxmpp/plugins
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2012-02-03 16:03:46 +0100
committerLance Stout <lancestout@gmail.com>2012-02-03 16:03:46 +0100
commit85dd005abc9496314f954ed6dbdc22f79387c308 (patch)
treec1abd31901fbd73c53189a1eeec396a0159c40fc /sleekxmpp/plugins
parent021c57205f79919703354cb2a01ac939e9b4afe2 (diff)
downloadslixmpp-85dd005abc9496314f954ed6dbdc22f79387c308.tar.gz
slixmpp-85dd005abc9496314f954ed6dbdc22f79387c308.tar.bz2
slixmpp-85dd005abc9496314f954ed6dbdc22f79387c308.tar.xz
slixmpp-85dd005abc9496314f954ed6dbdc22f79387c308.zip
Fix infinite callback loop.
Diffstat (limited to 'sleekxmpp/plugins')
-rw-r--r--sleekxmpp/plugins/xep_0047/ibb.py48
-rw-r--r--sleekxmpp/plugins/xep_0047/stanza.py2
2 files changed, 29 insertions, 21 deletions
diff --git a/sleekxmpp/plugins/xep_0047/ibb.py b/sleekxmpp/plugins/xep_0047/ibb.py
index c4f46e2f..85415f17 100644
--- a/sleekxmpp/plugins/xep_0047/ibb.py
+++ b/sleekxmpp/plugins/xep_0047/ibb.py
@@ -22,7 +22,7 @@ class xep_0047(base_plugin):
self.stanza = stanza
self.streams = {}
- self.pending_streams = {}
+ self.pending_streams = {3: 5}
self.pending_close_streams = {}
self._stream_lock = threading.Lock()
@@ -63,9 +63,6 @@ class xep_0047(base_plugin):
def open_stream(self, jid, block_size=4096, sid=None, window=1,
ifrom=None, block=True, timeout=None, callback=None):
- if not block and callback is not None:
- callback = lambda resp: self._handle_opened_stream(resp, callback)
-
if sid is None:
sid = str(uuid.uuid4())
@@ -77,29 +74,40 @@ class xep_0047(base_plugin):
iq['ibb_open']['sid'] = sid
iq['ibb_open']['stanza'] = 'iq'
- stream = IBBytestream(self.xmpp, sid, size,
+ stream = IBBytestream(self.xmpp, sid, block_size,
iq['to'], iq['from'], window)
-
+
with self._stream_lock:
self.pending_streams[iq['id']] = stream
-
- resp = iq.send(block=block, timeout=timeout, callback=callback)
+
+ self.pending_streams[iq['id']] = stream
+
if block:
+ resp = iq.send(timeout=timeout)
self._handle_opened_stream(resp)
return stream
-
- def _handle_opened_stream(self, iq, callback=None):
+ else:
+ cb = None
+ if callback is not None:
+ def chained(resp):
+ self._handle_opened_stream(resp)
+ callback(resp)
+ cb = chained
+ else:
+ cb = self._handle_opened_stream
+ return iq.send(block=block, timeout=timeout, callback=cb)
+
+
+ def _handle_opened_stream(self, iq):
if iq['type'] == 'result':
with self._stream_lock:
- stream = self.pending_streams[iq['id']]
- stream.sender = iq['to']
- stream.receiver = iq['from']
- stream.stream_started.set()
- self.streams[stream.sid] = stream
- self.xmpp.event('ibb_stream_start', stream)
-
- if callback is not None:
- callback(iq)
+ stream = self.pending_streams.get(iq['id'], None)
+ if stream is not None:
+ stream.sender = iq['to']
+ stream.receiver = iq['from']
+ stream.stream_started.set()
+ self.streams[stream.sid] = stream
+ self.xmpp.event('ibb_stream_start', stream)
with self._stream_lock:
if iq['id'] in self.pending_streams:
@@ -114,7 +122,7 @@ class xep_0047(base_plugin):
if size > self.max_block_size:
raise XMPPError('resource-constraint')
- stream = IBBytestream(self.xmpp, sid, size,
+ stream = IBBytestream(self.xmpp, sid, size,
iq['from'], iq['to'],
self.window_size)
stream.stream_started.set()
diff --git a/sleekxmpp/plugins/xep_0047/stanza.py b/sleekxmpp/plugins/xep_0047/stanza.py
index 2e4f8ccc..f5b77c0e 100644
--- a/sleekxmpp/plugins/xep_0047/stanza.py
+++ b/sleekxmpp/plugins/xep_0047/stanza.py
@@ -53,7 +53,7 @@ class Data(ElementBase):
raise XMPPError('not-acceptable')
def set_data(self, value):
- self.xml.text = to_64(value)
+ self.xml.text = to_b64(value)
def del_data(self):
self.xml.text = ''