Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/dax/jcl.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid Rousselie <dax@happycoders.org>2008-08-22 00:18:40 +0400
committerDavid Rousselie <dax@happycoders.org>2008-08-22 00:18:40 +0400
commit391ce083e077ef42a62af8170a820498a0839b4e (patch)
treebbfa6ba9227deded4b0a9d1721b102ca4a6d4d71 /src
parentaab567d4b80f058f48825fa6fe89c6c11b987a6d (diff)
check if stream is still open before using it
darcs-hash:20080821201840-86b55-4da2698f2916bf73c0f38166e542ada166d20a89.gz
Diffstat (limited to 'src')
-rw-r--r--src/jcl/jabber/component.py10
-rw-r--r--src/jcl/jabber/feeder.py5
-rw-r--r--src/jcl/jabber/tests/component.py4
-rw-r--r--src/jcl/jabber/tests/feeder.py8
4 files changed, 20 insertions, 7 deletions
diff --git a/src/jcl/jabber/component.py b/src/jcl/jabber/component.py
index 4fca3ea..a8ecd76 100644
--- a/src/jcl/jabber/component.py
+++ b/src/jcl/jabber/component.py
@@ -787,7 +787,7 @@ class JCLComponent(Component, object):
def send_stanzas(self, stanzas):
"""Send given stanza list"""
self.__logger.debug("Sending responses: " + str(stanzas))
- if stanzas is not None:
+ if stanzas is not None and self.stream is not None:
for stanza in stanzas:
self.stream.send(stanza)
@@ -892,7 +892,7 @@ class JCLComponent(Component, object):
query = info_query.new_query("jabber:iq:gateway")
query.newTextChild(query.ns(), "desc", lang_class.get_gateway_desc)
query.newTextChild(query.ns(), "prompt", lang_class.get_gateway_prompt)
- self.stream.send(info_query)
+ self.send_stanzas([info_query])
return 1
def handle_set_gateway(self, info_query):
@@ -910,7 +910,7 @@ class JCLComponent(Component, object):
query.newTextChild(query.ns(), "jid", jid)
# XEP-0100 - section 6: should be <jid> but PSI only work with <prompt>
query.newTextChild(query.ns(), "prompt", jid)
- self.stream.send(info_query)
+ self.send_stanzas([info_query])
return 1
def disco_get_info(self, node, info_query):
@@ -955,7 +955,7 @@ class JCLComponent(Component, object):
query = info_query.new_query("jabber:iq:version")
query.newTextChild(query.ns(), "name", self.name)
query.newTextChild(query.ns(), "version", self.version)
- self.stream.send(info_query)
+ self.send_stanzas([info_query])
return 1
def handle_get_register(self, info_query):
@@ -1053,7 +1053,7 @@ class JCLComponent(Component, object):
presence = Presence(from_jid=stanza.get_to(),
to_jid=stanza.get_from(),
stanza_type="unavailable")
- self.stream.send(presence)
+ self.send_stanzas([presence])
return 1
def handle_message(self, message):
diff --git a/src/jcl/jabber/feeder.py b/src/jcl/jabber/feeder.py
index 228945f..8204d2d 100644
--- a/src/jcl/jabber/feeder.py
+++ b/src/jcl/jabber/feeder.py
@@ -109,8 +109,9 @@ class MessageSender(Sender):
"""Implement abstract method from Sender class and send
data as Jabber message.
"""
- self.component.stream.send(self.create_message(to_account,
- data))
+ if self.component.stream is not None:
+ self.component.stream.send(self.create_message(to_account,
+ data))
class HeadlineSender(MessageSender):
"""Send data as Jabber Headline"""
diff --git a/src/jcl/jabber/tests/component.py b/src/jcl/jabber/tests/component.py
index 046cb9a..c199968 100644
--- a/src/jcl/jabber/tests/component.py
+++ b/src/jcl/jabber/tests/component.py
@@ -2689,6 +2689,10 @@ class JCLComponent_TestCase(JCLTestCase):
self.comp.send_stanzas(None)
self.assertEquals(len(self.comp.stream.sent), 0)
+ def test_send_stanzas_closed_connection(self):
+ self.comp.stream = None
+ self.comp.send_stanzas([Message()])
+
def test_get_motd(self):
config_file = tempfile.mktemp(".conf", "jcltest", jcl.tests.DB_DIR)
self.comp.config_file = config_file
diff --git a/src/jcl/jabber/tests/feeder.py b/src/jcl/jabber/tests/feeder.py
index b698da8..6f5c740 100644
--- a/src/jcl/jabber/tests/feeder.py
+++ b/src/jcl/jabber/tests/feeder.py
@@ -187,6 +187,14 @@ class MessageSender_TestCase(JCLTestCase):
self.assertEquals(message.get_type(), self.message_type)
model.db_disconnect()
+ def test_send_closed_connection(self):
+ self.comp.stream = None
+ model.db_connect()
+ account11 = Account(user=User(jid="user1@test.com"),
+ name="account11",
+ jid="account11@jcl.test.com")
+ self.sender.send(account11, ("subject", "Body message"))
+
class HeadlineSender_TestCase(MessageSender_TestCase):
def setUp(self):
MessageSender_TestCase.setUp(self)