summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften')
-rw-r--r--Swiften/Queries/Request.cpp5
-rw-r--r--Swiften/Queries/Request.h1
-rw-r--r--Swiften/Queries/UnitTest/RequestTest.cpp11
3 files changed, 15 insertions, 2 deletions
diff --git a/Swiften/Queries/Request.cpp b/Swiften/Queries/Request.cpp
index 609d67b..189bbaa 100644
--- a/Swiften/Queries/Request.cpp
+++ b/Swiften/Queries/Request.cpp
@@ -4,7 +4,7 @@
namespace Swift {
-Request::Request(IQ::Type type, const JID& receiver, boost::shared_ptr<Payload> payload, IQRouter* router, AutoDeleteBehavior autoDeleteBehavior) : IQHandler(router), type_(type), receiver_(receiver), payload_(payload), autoDeleteBehavior_(autoDeleteBehavior) {
+Request::Request(IQ::Type type, const JID& receiver, boost::shared_ptr<Payload> payload, IQRouter* router, AutoDeleteBehavior autoDeleteBehavior) : IQHandler(router), type_(type), receiver_(receiver), payload_(payload), autoDeleteBehavior_(autoDeleteBehavior), sent_(false) {
id_ = getRouter()->getNewIQID();
}
@@ -13,12 +13,13 @@ void Request::send() {
iq->setTo(receiver_);
iq->addPayload(payload_);
iq->setID(id_);
+ sent_ = true;
getRouter()->sendIQ(iq);
}
bool Request::handleIQ(boost::shared_ptr<IQ> iq) {
bool handled = false;
- if (iq->getID() == id_) {
+ if (sent_ && iq->getID() == id_) {
if (iq->getType() == IQ::Result) {
handleResponse(iq->getPayloadOfSameType(payload_), boost::optional<Error>());
}
diff --git a/Swiften/Queries/Request.h b/Swiften/Queries/Request.h
index f084303..d2bede6 100644
--- a/Swiften/Queries/Request.h
+++ b/Swiften/Queries/Request.h
@@ -40,6 +40,7 @@ namespace Swift {
boost::shared_ptr<Payload> payload_;
AutoDeleteBehavior autoDeleteBehavior_;
String id_;
+ bool sent_;
};
}
diff --git a/Swiften/Queries/UnitTest/RequestTest.cpp b/Swiften/Queries/UnitTest/RequestTest.cpp
index 31c0603..ea6dee6 100644
--- a/Swiften/Queries/UnitTest/RequestTest.cpp
+++ b/Swiften/Queries/UnitTest/RequestTest.cpp
@@ -18,6 +18,7 @@ class RequestTest : public CppUnit::TestFixture
CPPUNIT_TEST(testHandleIQ);
CPPUNIT_TEST(testHandleIQ_InvalidID);
CPPUNIT_TEST(testHandleIQ_Error);
+ CPPUNIT_TEST(testHandleIQ_BeforeSend);
CPPUNIT_TEST_SUITE_END();
public:
@@ -100,6 +101,16 @@ class RequestTest : public CppUnit::TestFixture
CPPUNIT_ASSERT_EQUAL(1, errorsReceived_);
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(channel_->iqs_.size()));
}
+
+ void testHandleIQ_BeforeSend() {
+ MyRequest testling(IQ::Get, JID("foo@bar.com/baz"), payload_, router_);
+ testling.onResponse.connect(boost::bind(&RequestTest::handleResponse, this, _1, _2));
+ channel_->onIQReceived(createResponse("test-id"));
+
+ CPPUNIT_ASSERT_EQUAL(0, responsesReceived_);
+ CPPUNIT_ASSERT_EQUAL(0, errorsReceived_);
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(channel_->iqs_.size()));
+ }
private:
void handleResponse(boost::shared_ptr<Payload> p, const boost::optional<Error>& e) {