summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Queries')
-rw-r--r--Swiften/Queries/DummyIQChannel.h30
-rw-r--r--Swiften/Queries/GenericRequest.h125
-rw-r--r--Swiften/Queries/GetResponder.h16
-rw-r--r--Swiften/Queries/IQChannel.h27
-rw-r--r--Swiften/Queries/IQHandler.cpp3
-rw-r--r--Swiften/Queries/IQHandler.h16
-rw-r--r--Swiften/Queries/IQRouter.cpp95
-rw-r--r--Swiften/Queries/IQRouter.h132
-rw-r--r--Swiften/Queries/PubSubRequest.h121
-rw-r--r--Swiften/Queries/RawRequest.h69
-rw-r--r--Swiften/Queries/Request.cpp121
-rw-r--r--Swiften/Queries/Request.h180
-rw-r--r--Swiften/Queries/Requests/EnableCarbonsRequest.h28
-rw-r--r--Swiften/Queries/Requests/GetInBandRegistrationFormRequest.cpp7
-rw-r--r--Swiften/Queries/Requests/GetInBandRegistrationFormRequest.h24
-rw-r--r--Swiften/Queries/Requests/GetPrivateStorageRequest.h64
-rw-r--r--Swiften/Queries/Requests/GetSecurityLabelsCatalogRequest.h35
-rw-r--r--Swiften/Queries/Requests/GetSoftwareVersionRequest.h36
-rw-r--r--Swiften/Queries/Requests/SetPrivateStorageRequest.h52
-rw-r--r--Swiften/Queries/Requests/SubmitInBandRegistrationFormRequest.cpp7
-rw-r--r--Swiften/Queries/Requests/SubmitInBandRegistrationFormRequest.h40
-rw-r--r--Swiften/Queries/Requests/UnitTest/GetPrivateStorageRequestTest.cpp187
-rw-r--r--Swiften/Queries/Responder.h246
-rw-r--r--Swiften/Queries/Responders/SoftwareVersionResponder.cpp19
-rw-r--r--Swiften/Queries/Responders/SoftwareVersionResponder.h28
-rw-r--r--Swiften/Queries/SetResponder.h16
-rw-r--r--Swiften/Queries/UnitTest/IQRouterTest.cpp285
-rw-r--r--Swiften/Queries/UnitTest/RequestTest.cpp699
-rw-r--r--Swiften/Queries/UnitTest/ResponderTest.cpp272
29 files changed, 1501 insertions, 1479 deletions
diff --git a/Swiften/Queries/DummyIQChannel.h b/Swiften/Queries/DummyIQChannel.h
index 11cc3dc..5ec68ca 100644
--- a/Swiften/Queries/DummyIQChannel.h
+++ b/Swiften/Queries/DummyIQChannel.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -11,22 +11,22 @@
#include <Swiften/Queries/IQChannel.h>
namespace Swift {
- class DummyIQChannel : public IQChannel {
- public:
- DummyIQChannel() {}
+ class DummyIQChannel : public IQChannel {
+ public:
+ DummyIQChannel() {}
- virtual void sendIQ(boost::shared_ptr<IQ> iq) {
- iqs_.push_back(iq);
- }
+ virtual void sendIQ(std::shared_ptr<IQ> iq) {
+ iqs_.push_back(iq);
+ }
- virtual std::string getNewIQID() {
- return "test-id";
- }
+ virtual std::string getNewIQID() {
+ return "test-id";
+ }
- virtual bool isAvailable() const {
- return true;
- }
+ virtual bool isAvailable() const {
+ return true;
+ }
- std::vector<boost::shared_ptr<IQ> > iqs_;
- };
+ std::vector<std::shared_ptr<IQ> > iqs_;
+ };
}
diff --git a/Swiften/Queries/GenericRequest.h b/Swiften/Queries/GenericRequest.h
index d6cca1c..312ecf2 100644
--- a/Swiften/Queries/GenericRequest.h
+++ b/Swiften/Queries/GenericRequest.h
@@ -1,79 +1,80 @@
/*
- * Copyright (c) 2010-2015 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#pragma once
+#include <boost/signals2.hpp>
+
#include <Swiften/Base/API.h>
-#include <Swiften/Base/boost_bsignals.h>
#include <Swiften/Queries/Request.h>
namespace Swift {
- /**
- * GenericRequest is used for managing the sending of, and handling of replies to, iq stanzas that do not have their own Request types.
- *
- * To create an iq stanza, call a constructor with the type of the iq that needs to be sent (either Set or Get), addressing information (clients should use the constructor that doesn't specify a sender), the payload that should be sent in the iq, and the IQRouter for the connection, obtained through the Client or CoreClient object.
- *
- * Having created a GenericRequest, connect to the onResponse signal to be told when a response (either a result or an error) has been received by Swiften.
- *
- * To send the iq, then call send() - onResponse will be called when a reply is received.
- */
- template<typename PAYLOAD_TYPE>
- class SWIFTEN_API GenericRequest : public Request {
- public:
- typedef boost::shared_ptr<GenericRequest<PAYLOAD_TYPE> > ref;
+ /**
+ * GenericRequest is used for managing the sending of, and handling of replies to, iq stanzas that do not have their own Request types.
+ *
+ * To create an iq stanza, call a constructor with the type of the iq that needs to be sent (either Set or Get), addressing information (clients should use the constructor that doesn't specify a sender), the payload that should be sent in the iq, and the IQRouter for the connection, obtained through the Client or CoreClient object.
+ *
+ * Having created a GenericRequest, connect to the onResponse signal to be told when a response (either a result or an error) has been received by Swiften.
+ *
+ * To send the iq, then call send() - onResponse will be called when a reply is received.
+ */
+ template<typename PAYLOAD_TYPE>
+ class SWIFTEN_API GenericRequest : public Request {
+ public:
+ typedef std::shared_ptr<GenericRequest<PAYLOAD_TYPE> > ref;
- public:
- /**
- * Create a request suitable for client use.
- * @param type Iq type - Get or Set.
- * @param receiver JID to send request to.
- * @param payload Payload to send in stanza.
- * @param router IQRouter instance for current connection.
- */
- GenericRequest(
- IQ::Type type,
- const JID& receiver,
- boost::shared_ptr<Payload> payload,
- IQRouter* router) :
- Request(type, receiver, payload, router) {
- }
+ public:
+ /**
+ * Create a request suitable for client use.
+ * @param type Iq type - Get or Set.
+ * @param receiver JID to send request to.
+ * @param payload Payload to send in stanza.
+ * @param router IQRouter instance for current connection.
+ */
+ GenericRequest(
+ IQ::Type type,
+ const JID& receiver,
+ std::shared_ptr<Payload> payload,
+ IQRouter* router) :
+ Request(type, receiver, payload, router) {
+ }
- /**
- * Create a request suitable for component or server use. As a client, use the other constructor instead.
- * @param type Iq type - Get or Set.
- * @param sender JID to use in "from" of stanza.
- * @param receiver JID to send request to.
- * @param payload Payload to send in stanza.
- * @param router IQRouter instance for current connection.
- */
- GenericRequest(
- IQ::Type type,
- const JID& sender,
- const JID& receiver,
- boost::shared_ptr<Payload> payload,
- IQRouter* router) :
- Request(type, sender, receiver, payload, router) {
- }
+ /**
+ * Create a request suitable for component or server use. As a client, use the other constructor instead.
+ * @param type Iq type - Get or Set.
+ * @param sender JID to use in "from" of stanza.
+ * @param receiver JID to send request to.
+ * @param payload Payload to send in stanza.
+ * @param router IQRouter instance for current connection.
+ */
+ GenericRequest(
+ IQ::Type type,
+ const JID& sender,
+ const JID& receiver,
+ std::shared_ptr<Payload> payload,
+ IQRouter* router) :
+ Request(type, sender, receiver, payload, router) {
+ }
- /**
- * Internal method, do not use.
- */
- virtual void handleResponse(boost::shared_ptr<Payload> payload, ErrorPayload::ref error) {
- onResponse(boost::dynamic_pointer_cast<PAYLOAD_TYPE>(payload), error);
- }
+ /**
+ * Internal method, do not use.
+ */
+ virtual void handleResponse(std::shared_ptr<Payload> payload, ErrorPayload::ref error) {
+ onResponse(std::dynamic_pointer_cast<PAYLOAD_TYPE>(payload), error);
+ }
- public:
- boost::shared_ptr<PAYLOAD_TYPE> getPayloadGeneric() const {
- return boost::dynamic_pointer_cast<PAYLOAD_TYPE>(getPayload());
- }
+ public:
+ std::shared_ptr<PAYLOAD_TYPE> getPayloadGeneric() const {
+ return std::dynamic_pointer_cast<PAYLOAD_TYPE>(getPayload());
+ }
- public:
- /**
- * Signal emitted when a reply to the iq has been received. Contains a payload if one was present, and an error if one was present.
- */
- boost::signal<void (boost::shared_ptr<PAYLOAD_TYPE>, ErrorPayload::ref)> onResponse;
- };
+ public:
+ /**
+ * Signal emitted when a reply to the iq has been received. Contains a payload if one was present, and an error if one was present.
+ */
+ boost::signals2::signal<void (std::shared_ptr<PAYLOAD_TYPE>, ErrorPayload::ref)> onResponse;
+ };
}
diff --git a/Swiften/Queries/GetResponder.h b/Swiften/Queries/GetResponder.h
index df08f30..18dd694 100644
--- a/Swiften/Queries/GetResponder.h
+++ b/Swiften/Queries/GetResponder.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -10,12 +10,12 @@
#include <Swiften/Queries/Responder.h>
namespace Swift {
- template<typename T>
- class SWIFTEN_API GetResponder : public Responder<T> {
- public:
- GetResponder(IQRouter* router) : Responder<T>(router) {}
+ template<typename T>
+ class SWIFTEN_API GetResponder : public Responder<T> {
+ public:
+ GetResponder(IQRouter* router) : Responder<T>(router) {}
- private:
- virtual bool handleSetRequest(const JID&, const JID&, const std::string&, boost::shared_ptr<T>) { return false; }
- };
+ private:
+ virtual bool handleSetRequest(const JID&, const JID&, const std::string&, std::shared_ptr<T>) { return false; }
+ };
}
diff --git a/Swiften/Queries/IQChannel.h b/Swiften/Queries/IQChannel.h
index 7f8e7dc..fe32d89 100644
--- a/Swiften/Queries/IQChannel.h
+++ b/Swiften/Queries/IQChannel.h
@@ -1,28 +1,29 @@
/*
- * Copyright (c) 2010 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#pragma once
-#include <Swiften/Base/boost_bsignals.h>
-#include <boost/shared_ptr.hpp>
-
+#include <memory>
#include <string>
+
+#include <boost/signals2.hpp>
+
#include <Swiften/Base/API.h>
#include <Swiften/Elements/IQ.h>
namespace Swift {
- class SWIFTEN_API IQChannel {
- public:
- virtual ~IQChannel();
+ class SWIFTEN_API IQChannel {
+ public:
+ virtual ~IQChannel();
+
+ virtual void sendIQ(std::shared_ptr<IQ>) = 0;
+ virtual std::string getNewIQID() = 0;
- virtual void sendIQ(boost::shared_ptr<IQ>) = 0;
- virtual std::string getNewIQID() = 0;
-
- virtual bool isAvailable() const = 0;
+ virtual bool isAvailable() const = 0;
- boost::signal<void (boost::shared_ptr<IQ>)> onIQReceived;
- };
+ boost::signals2::signal<void (std::shared_ptr<IQ>)> onIQReceived;
+ };
}
diff --git a/Swiften/Queries/IQHandler.cpp b/Swiften/Queries/IQHandler.cpp
index ec78ef6..bdfad30 100644
--- a/Swiften/Queries/IQHandler.cpp
+++ b/Swiften/Queries/IQHandler.cpp
@@ -1,10 +1,11 @@
/*
- * Copyright (c) 2010 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swiften/Queries/IQHandler.h>
+
#include <Swiften/Queries/IQRouter.h>
namespace Swift {
diff --git a/Swiften/Queries/IQHandler.h b/Swiften/Queries/IQHandler.h
index b45e1e6..1bfdf0f 100644
--- a/Swiften/Queries/IQHandler.h
+++ b/Swiften/Queries/IQHandler.h
@@ -1,23 +1,23 @@
/*
- * Copyright (c) 2010 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#pragma once
-#include <boost/shared_ptr.hpp>
+#include <memory>
#include <Swiften/Base/API.h>
#include <Swiften/Elements/IQ.h>
namespace Swift {
- class IQRouter;
+ class IQRouter;
- class SWIFTEN_API IQHandler {
- public:
- virtual ~IQHandler();
+ class SWIFTEN_API IQHandler {
+ public:
+ virtual ~IQHandler();
- virtual bool handleIQ(boost::shared_ptr<IQ>) = 0;
- };
+ virtual bool handleIQ(std::shared_ptr<IQ>) = 0;
+ };
}
diff --git a/Swiften/Queries/IQRouter.cpp b/Swiften/Queries/IQRouter.cpp
index b6b957e..286b65f 100644
--- a/Swiften/Queries/IQRouter.cpp
+++ b/Swiften/Queries/IQRouter.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -9,86 +9,85 @@
#include <boost/bind.hpp>
#include <Swiften/Base/Algorithm.h>
-#include <Swiften/Base/foreach.h>
-#include <Swiften/Queries/IQHandler.h>
-#include <Swiften/Queries/IQChannel.h>
#include <Swiften/Elements/ErrorPayload.h>
+#include <Swiften/Queries/IQChannel.h>
+#include <Swiften/Queries/IQHandler.h>
namespace Swift {
static void noop(IQHandler*) {}
IQRouter::IQRouter(IQChannel* channel) : channel_(channel), queueRemoves_(false) {
- channel->onIQReceived.connect(boost::bind(&IQRouter::handleIQ, this, _1));
+ channel->onIQReceived.connect(boost::bind(&IQRouter::handleIQ, this, _1));
}
IQRouter::~IQRouter() {
- channel_->onIQReceived.disconnect(boost::bind(&IQRouter::handleIQ, this, _1));
+ channel_->onIQReceived.disconnect(boost::bind(&IQRouter::handleIQ, this, _1));
}
bool IQRouter::isAvailable() {
- return channel_->isAvailable();
+ return channel_->isAvailable();
}
-void IQRouter::handleIQ(boost::shared_ptr<IQ> iq) {
- queueRemoves_ = true;
-
- bool handled = false;
- // Go through the handlers in reverse order, to give precedence to the last added handler
- std::vector<boost::shared_ptr<IQHandler> >::const_reverse_iterator i = handlers_.rbegin();
- std::vector<boost::shared_ptr<IQHandler> >::const_reverse_iterator rend = handlers_.rend();
- for (; i != rend; ++i) {
- handled |= (*i)->handleIQ(iq);
- if (handled) {
- break;
- }
- }
- if (!handled && (iq->getType() == IQ::Get || iq->getType() == IQ::Set) ) {
- sendIQ(IQ::createError(iq->getFrom(), iq->getID(), ErrorPayload::FeatureNotImplemented, ErrorPayload::Cancel));
- }
-
- processPendingRemoves();
-
- queueRemoves_ = false;
+void IQRouter::handleIQ(std::shared_ptr<IQ> iq) {
+ queueRemoves_ = true;
+
+ bool handled = false;
+ // Go through the handlers in reverse order, to give precedence to the last added handler
+ std::vector<std::shared_ptr<IQHandler> >::const_reverse_iterator i = handlers_.rbegin();
+ std::vector<std::shared_ptr<IQHandler> >::const_reverse_iterator rend = handlers_.rend();
+ for (; i != rend; ++i) {
+ handled |= (*i)->handleIQ(iq);
+ if (handled) {
+ break;
+ }
+ }
+ if (!handled && (iq->getType() == IQ::Get || iq->getType() == IQ::Set) ) {
+ sendIQ(IQ::createError(iq->getFrom(), iq->getID(), ErrorPayload::FeatureNotImplemented, ErrorPayload::Cancel));
+ }
+
+ processPendingRemoves();
+
+ queueRemoves_ = false;
}
void IQRouter::processPendingRemoves() {
- foreach(boost::shared_ptr<IQHandler> handler, queuedRemoves_) {
- erase(handlers_, handler);
- }
- queuedRemoves_.clear();
+ for (auto&& handler : queuedRemoves_) {
+ erase(handlers_, handler);
+ }
+ queuedRemoves_.clear();
}
void IQRouter::addHandler(IQHandler* handler) {
- addHandler(boost::shared_ptr<IQHandler>(handler, noop));
+ addHandler(std::shared_ptr<IQHandler>(handler, noop));
}
void IQRouter::removeHandler(IQHandler* handler) {
- removeHandler(boost::shared_ptr<IQHandler>(handler, noop));
+ removeHandler(std::shared_ptr<IQHandler>(handler, noop));
}
-void IQRouter::addHandler(boost::shared_ptr<IQHandler> handler) {
- handlers_.push_back(handler);
+void IQRouter::addHandler(std::shared_ptr<IQHandler> handler) {
+ handlers_.push_back(handler);
}
-void IQRouter::removeHandler(boost::shared_ptr<IQHandler> handler) {
- if (queueRemoves_) {
- queuedRemoves_.push_back(handler);
- }
- else {
- erase(handlers_, handler);
- }
+void IQRouter::removeHandler(std::shared_ptr<IQHandler> handler) {
+ if (queueRemoves_) {
+ queuedRemoves_.push_back(handler);
+ }
+ else {
+ erase(handlers_, handler);
+ }
}
-void IQRouter::sendIQ(boost::shared_ptr<IQ> iq) {
- if (from_.isValid() && !iq->getFrom().isValid()) {
- iq->setFrom(from_);
- }
- channel_->sendIQ(iq);
+void IQRouter::sendIQ(std::shared_ptr<IQ> iq) {
+ if (from_.isValid() && !iq->getFrom().isValid()) {
+ iq->setFrom(from_);
+ }
+ channel_->sendIQ(iq);
}
std::string IQRouter::getNewIQID() {
- return channel_->getNewIQID();
+ return channel_->getNewIQID();
}
}
diff --git a/Swiften/Queries/IQRouter.h b/Swiften/Queries/IQRouter.h
index ac1beaf..eda7cfb 100644
--- a/Swiften/Queries/IQRouter.h
+++ b/Swiften/Queries/IQRouter.h
@@ -1,89 +1,89 @@
/*
- * Copyright (c) 2010 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#pragma once
-#include <boost/shared_ptr.hpp>
-#include <vector>
+#include <memory>
#include <string>
+#include <vector>
#include <Swiften/Base/API.h>
#include <Swiften/Elements/IQ.h>
namespace Swift {
- class IQChannel;
- class IQHandler;
+ class IQChannel;
+ class IQHandler;
+
+ class SWIFTEN_API IQRouter {
+ public:
+ IQRouter(IQChannel* channel);
+ ~IQRouter();
- class SWIFTEN_API IQRouter {
- public:
- IQRouter(IQChannel* channel);
- ~IQRouter();
+ /**
+ * Sets the JID of this IQ router.
+ *
+ * This JID is used by requests to check whether incoming
+ * results are addressed correctly.
+ */
+ void setJID(const JID& jid) {
+ jid_ = jid;
+ }
- /**
- * Sets the JID of this IQ router.
- *
- * This JID is used by requests to check whether incoming
- * results are addressed correctly.
- */
- void setJID(const JID& jid) {
- jid_ = jid;
- }
+ const JID& getJID() const {
+ return jid_;
+ }
- const JID& getJID() const {
- return jid_;
- }
+ /**
+ * Sets the 'from' JID for all outgoing IQ stanzas.
+ *
+ * By default, IQRouter does not add a from to IQ stanzas, since
+ * this is automatically added by the server. This overrides this
+ * default behavior, which is necessary for e.g. components.
+ */
+ void setFrom(const JID& from) {
+ from_ = from;
+ }
- /**
- * Sets the 'from' JID for all outgoing IQ stanzas.
- *
- * By default, IQRouter does not add a from to IQ stanzas, since
- * this is automatically added by the server. This overrides this
- * default behavior, which is necessary for e.g. components.
- */
- void setFrom(const JID& from) {
- from_ = from;
- }
+ void addHandler(IQHandler* handler);
+ void removeHandler(IQHandler* handler);
+ void addHandler(std::shared_ptr<IQHandler> handler);
+ void removeHandler(std::shared_ptr<IQHandler> handler);
- void addHandler(IQHandler* handler);
- void removeHandler(IQHandler* handler);
- void addHandler(boost::shared_ptr<IQHandler> handler);
- void removeHandler(boost::shared_ptr<IQHandler> handler);
+ /**
+ * Sends an IQ stanza.
+ *
+ * If a JID was specified using setFrom, the JID will
+ * be set as the 'from' address on iq before sending
+ * it.
+ */
+ void sendIQ(std::shared_ptr<IQ> iq);
+ std::string getNewIQID();
- /**
- * Sends an IQ stanza.
- *
- * If a JID was specified using setFrom, the JID will
- * be set as the 'from' address on iq before sending
- * it.
- */
- void sendIQ(boost::shared_ptr<IQ> iq);
- std::string getNewIQID();
-
- bool isAvailable();
+ bool isAvailable();
- /**
- * Checks whether the given jid is the account JID (i.e. it is either
- * the bare JID, or it is the empty JID).
- * Can be used to check whether a stanza is sent by the server on behalf
- * of the user's account.
- */
- bool isAccountJID(const JID& jid) {
- return jid.isValid() ? jid_.toBare().equals(jid, JID::WithResource) : true;
- }
+ /**
+ * Checks whether the given jid is the account JID (i.e. it is either
+ * the bare JID, or it is the empty JID).
+ * Can be used to check whether a stanza is sent by the server on behalf
+ * of the user's account.
+ */
+ bool isAccountJID(const JID& jid) {
+ return jid.isValid() ? jid_.toBare().equals(jid, JID::WithResource) : true;
+ }
- private:
- void handleIQ(boost::shared_ptr<IQ> iq);
- void processPendingRemoves();
+ private:
+ void handleIQ(std::shared_ptr<IQ> iq);
+ void processPendingRemoves();
- private:
- IQChannel* channel_;
- JID jid_;
- JID from_;
- std::vector< boost::shared_ptr<IQHandler> > handlers_;
- std::vector< boost::shared_ptr<IQHandler> > queuedRemoves_;
- bool queueRemoves_;
- };
+ private:
+ IQChannel* channel_;
+ JID jid_;
+ JID from_;
+ std::vector< std::shared_ptr<IQHandler> > handlers_;
+ std::vector< std::shared_ptr<IQHandler> > queuedRemoves_;
+ bool queueRemoves_;
+ };
}
diff --git a/Swiften/Queries/PubSubRequest.h b/Swiften/Queries/PubSubRequest.h
index 9cf4404..b439748 100644
--- a/Swiften/Queries/PubSubRequest.h
+++ b/Swiften/Queries/PubSubRequest.h
@@ -1,91 +1,92 @@
/*
- * Copyright (c) 2013-2015 Isode Limited.
+ * Copyright (c) 2013-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#pragma once
-#include <boost/smart_ptr/make_shared.hpp>
+#include <memory>
+
+#include <boost/signals2.hpp>
#include <Swiften/Base/API.h>
-#include <Swiften/Base/boost_bsignals.h>
-#include <Swiften/Queries/Request.h>
#include <Swiften/Elements/ContainerPayload.h>
-#include <Swiften/PubSub/PubSubUtil.h>
#include <Swiften/Elements/PubSub.h>
-#include <Swiften/Elements/PubSubOwnerPubSub.h>
-#include <Swiften/Elements/PubSubCreate.h>
-#include <Swiften/Elements/PubSubSubscribe.h>
#include <Swiften/Elements/PubSubAffiliations.h>
+#include <Swiften/Elements/PubSubCreate.h>
#include <Swiften/Elements/PubSubDefault.h>
#include <Swiften/Elements/PubSubItems.h>
-#include <Swiften/Elements/PubSubPublish.h>
-#include <Swiften/Elements/PubSubRetract.h>
-#include <Swiften/Elements/PubSubSubscription.h>
-#include <Swiften/Elements/PubSubSubscriptions.h>
-#include <Swiften/Elements/PubSubUnsubscribe.h>
#include <Swiften/Elements/PubSubOwnerAffiliations.h>
#include <Swiften/Elements/PubSubOwnerConfigure.h>
#include <Swiften/Elements/PubSubOwnerDefault.h>
#include <Swiften/Elements/PubSubOwnerDelete.h>
+#include <Swiften/Elements/PubSubOwnerPubSub.h>
#include <Swiften/Elements/PubSubOwnerPurge.h>
#include <Swiften/Elements/PubSubOwnerSubscriptions.h>
+#include <Swiften/Elements/PubSubPublish.h>
+#include <Swiften/Elements/PubSubRetract.h>
+#include <Swiften/Elements/PubSubSubscribe.h>
+#include <Swiften/Elements/PubSubSubscription.h>
+#include <Swiften/Elements/PubSubSubscriptions.h>
+#include <Swiften/Elements/PubSubUnsubscribe.h>
+#include <Swiften/PubSub/PubSubUtil.h>
+#include <Swiften/Queries/Request.h>
namespace Swift {
- namespace Detail {
- template<typename T>
- struct PubSubPayloadTraits;
+ namespace Detail {
+ template<typename T>
+ struct PubSubPayloadTraits;
#define SWIFTEN_PUBSUB_DECLARE_PAYLOAD_TRAITS(PAYLOAD, CONTAINER, RESPONSE) \
- template<> struct PubSubPayloadTraits< PAYLOAD > { \
- typedef CONTAINER ContainerType; \
- typedef RESPONSE ResponseType; \
- };
+ template<> struct PubSubPayloadTraits< PAYLOAD > { \
+ typedef CONTAINER ContainerType; \
+ typedef RESPONSE ResponseType; \
+ };
- SWIFTEN_PUBSUB_FOREACH_PUBSUB_PAYLOAD_TYPE(
- SWIFTEN_PUBSUB_DECLARE_PAYLOAD_TRAITS)
- }
+ SWIFTEN_PUBSUB_FOREACH_PUBSUB_PAYLOAD_TYPE(
+ SWIFTEN_PUBSUB_DECLARE_PAYLOAD_TRAITS)
+ }
- template<typename T>
- class SWIFTEN_API PubSubRequest : public Request {
- typedef typename Detail::PubSubPayloadTraits<T>::ContainerType ContainerType;
- typedef typename Detail::PubSubPayloadTraits<T>::ResponseType ResponseType;
+ template<typename T>
+ class SWIFTEN_API PubSubRequest : public Request {
+ typedef typename Detail::PubSubPayloadTraits<T>::ContainerType ContainerType;
+ typedef typename Detail::PubSubPayloadTraits<T>::ResponseType ResponseType;
- public:
- PubSubRequest(
- IQ::Type type,
- const JID& receiver,
- boost::shared_ptr<T> payload,
- IQRouter* router) :
- Request(type, receiver, router) {
- boost::shared_ptr<ContainerType> wrapper = boost::make_shared<ContainerType>();
- wrapper->setPayload(payload);
- setPayload(wrapper);
- }
+ public:
+ PubSubRequest(
+ IQ::Type type,
+ const JID& receiver,
+ std::shared_ptr<T> payload,
+ IQRouter* router) :
+ Request(type, receiver, router) {
+ std::shared_ptr<ContainerType> wrapper = std::make_shared<ContainerType>();
+ wrapper->setPayload(payload);
+ setPayload(wrapper);
+ }
- PubSubRequest(
- IQ::Type type,
- const JID& sender,
- const JID& receiver,
- boost::shared_ptr<T> payload,
- IQRouter* router) :
- Request(type, sender, receiver, router) {
- boost::shared_ptr<ContainerType> wrapper = boost::make_shared<ContainerType>();
- wrapper->setPayload(payload);
- setPayload(wrapper);
- }
+ PubSubRequest(
+ IQ::Type type,
+ const JID& sender,
+ const JID& receiver,
+ std::shared_ptr<T> payload,
+ IQRouter* router) :
+ Request(type, sender, receiver, router) {
+ std::shared_ptr<ContainerType> wrapper = std::make_shared<ContainerType>();
+ wrapper->setPayload(payload);
+ setPayload(wrapper);
+ }
- virtual void handleResponse(
- boost::shared_ptr<Payload> payload, ErrorPayload::ref error) {
- boost::shared_ptr<ResponseType> result;
- if (boost::shared_ptr<ContainerType> container = boost::dynamic_pointer_cast<ContainerType>(payload)) {
- result = boost::dynamic_pointer_cast<ResponseType>(container->getPayload());
- }
- onResponse(result, error);
- }
+ virtual void handleResponse(
+ std::shared_ptr<Payload> payload, ErrorPayload::ref error) {
+ std::shared_ptr<ResponseType> result;
+ if (std::shared_ptr<ContainerType> container = std::dynamic_pointer_cast<ContainerType>(payload)) {
+ result = std::dynamic_pointer_cast<ResponseType>(container->getPayload());
+ }
+ onResponse(result, error);
+ }
- public:
- boost::signal<void (boost::shared_ptr<ResponseType>, ErrorPayload::ref)> onResponse;
- };
+ public:
+ boost::signals2::signal<void (std::shared_ptr<ResponseType>, ErrorPayload::ref)> onResponse;
+ };
}
diff --git a/Swiften/Queries/RawRequest.h b/Swiften/Queries/RawRequest.h
index 0d0336e..76c84f9 100644
--- a/Swiften/Queries/RawRequest.h
+++ b/Swiften/Queries/RawRequest.h
@@ -1,51 +1,52 @@
/*
- * Copyright (c) 2011-2015 Isode Limited.
+ * Copyright (c) 2011-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#pragma once
-#include <boost/smart_ptr/make_shared.hpp>
+#include <memory>
#include <typeinfo>
+#include <boost/signals2.hpp>
+
#include <Swiften/Base/API.h>
-#include <Swiften/Base/boost_bsignals.h>
-#include <Swiften/Queries/Request.h>
-#include <Swiften/Elements/RawXMLPayload.h>
#include <Swiften/Elements/ErrorPayload.h>
+#include <Swiften/Elements/RawXMLPayload.h>
+#include <Swiften/Queries/Request.h>
#include <Swiften/Serializer/PayloadSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/ErrorSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h>
namespace Swift {
- class SWIFTEN_API RawRequest : public Request {
- public:
- typedef boost::shared_ptr<RawRequest> ref;
-
- static ref create(IQ::Type type, const JID& recipient, const std::string& data, IQRouter* router) {
- return ref(new RawRequest(type, recipient, data, router));
- }
-
- boost::signal<void (const std::string&)> onResponse;
-
- private:
- RawRequest(IQ::Type type, const JID& receiver, const std::string& data, IQRouter* router) : Request(type, receiver, boost::make_shared<RawXMLPayload>(data), router) {
- }
-
- virtual void handleResponse(boost::shared_ptr<Payload> payload, ErrorPayload::ref error) {
- if (error) {
- onResponse(ErrorSerializer(&serializers).serializePayload(error));
- }
- else {
- assert(payload);
- PayloadSerializer* serializer = serializers.getPayloadSerializer(payload);
- assert(serializer);
- onResponse(serializer->serialize(payload));
- }
- }
-
- private:
- FullPayloadSerializerCollection serializers;
- };
+ class SWIFTEN_API RawRequest : public Request {
+ public:
+ typedef std::shared_ptr<RawRequest> ref;
+
+ static ref create(IQ::Type type, const JID& recipient, const std::string& data, IQRouter* router) {
+ return ref(new RawRequest(type, recipient, data, router));
+ }
+
+ boost::signals2::signal<void (const std::string&)> onResponse;
+
+ private:
+ RawRequest(IQ::Type type, const JID& receiver, const std::string& data, IQRouter* router) : Request(type, receiver, std::make_shared<RawXMLPayload>(data), router) {
+ }
+
+ virtual void handleResponse(std::shared_ptr<Payload> payload, ErrorPayload::ref error) {
+ if (error) {
+ onResponse(ErrorSerializer(&serializers).serializePayload(error));
+ }
+ else {
+ assert(payload);
+ PayloadSerializer* serializer = serializers.getPayloadSerializer(payload);
+ assert(serializer);
+ onResponse(serializer->serialize(payload));
+ }
+ }
+
+ private:
+ FullPayloadSerializerCollection serializers;
+ };
}
diff --git a/Swiften/Queries/Request.cpp b/Swiften/Queries/Request.cpp
index dec1dfa..12eaae5 100644
--- a/Swiften/Queries/Request.cpp
+++ b/Swiften/Queries/Request.cpp
@@ -1,92 +1,93 @@
/*
- * Copyright (c) 2010 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swiften/Queries/Request.h>
-#include <Swiften/Queries/IQRouter.h>
-#include <Swiften/Elements/RawXMLPayload.h>
+
#include <Swiften/Base/Log.h>
+#include <Swiften/Elements/RawXMLPayload.h>
+#include <Swiften/Queries/IQRouter.h>
namespace Swift {
-Request::Request(IQ::Type type, const JID& receiver, boost::shared_ptr<Payload> payload, IQRouter* router) : router_(router), type_(type), receiver_(receiver), payload_(payload), sent_(false) {
+Request::Request(IQ::Type type, const JID& receiver, std::shared_ptr<Payload> payload, IQRouter* router) : router_(router), type_(type), receiver_(receiver), payload_(payload), sent_(false) {
}
Request::Request(IQ::Type type, const JID& receiver, IQRouter* router) : router_(router), type_(type), receiver_(receiver), sent_(false) {
}
-Request::Request(IQ::Type type, const JID& sender, const JID& receiver, boost::shared_ptr<Payload> payload, IQRouter* router) : router_(router), type_(type), sender_(sender), receiver_(receiver), payload_(payload), sent_(false) {
+Request::Request(IQ::Type type, const JID& sender, const JID& receiver, std::shared_ptr<Payload> payload, IQRouter* router) : router_(router), type_(type), sender_(sender), receiver_(receiver), payload_(payload), sent_(false) {
}
Request::Request(IQ::Type type, const JID& sender, const JID& receiver, IQRouter* router) : router_(router), type_(type), sender_(sender), receiver_(receiver), sent_(false) {
}
std::string Request::send() {
- assert(payload_);
- assert(!sent_);
- sent_ = true;
+ assert(payload_);
+ assert(!sent_);
+ sent_ = true;
- boost::shared_ptr<IQ> iq(new IQ(type_));
- iq->setTo(receiver_);
- iq->setFrom(sender_);
- iq->addPayload(payload_);
- id_ = router_->getNewIQID();
- iq->setID(id_);
+ std::shared_ptr<IQ> iq(new IQ(type_));
+ iq->setTo(receiver_);
+ iq->setFrom(sender_);
+ iq->addPayload(payload_);
+ id_ = router_->getNewIQID();
+ iq->setID(id_);
- try {
- router_->addHandler(shared_from_this());
- }
- catch (const std::exception&) {
- router_->addHandler(this);
- }
+ try {
+ router_->addHandler(shared_from_this());
+ }
+ catch (const std::exception&) {
+ router_->addHandler(this);
+ }
- router_->sendIQ(iq);
- return id_;
+ router_->sendIQ(iq);
+ return id_;
}
-bool Request::handleIQ(boost::shared_ptr<IQ> iq) {
- bool handled = false;
- if (iq->getType() == IQ::Result || iq->getType() == IQ::Error) {
- if (sent_ && iq->getID() == id_) {
- if (isCorrectSender(iq->getFrom())) {
- if (iq->getType() == IQ::Result) {
- boost::shared_ptr<Payload> payload = iq->getPayloadOfSameType(payload_);
- if (!payload && boost::dynamic_pointer_cast<RawXMLPayload>(payload_) && !iq->getPayloads().empty()) {
- payload = iq->getPayloads().front();
- }
- handleResponse(payload, ErrorPayload::ref());
- }
- else {
- ErrorPayload::ref errorPayload = iq->getPayload<ErrorPayload>();
- if (errorPayload) {
- handleResponse(boost::shared_ptr<Payload>(), errorPayload);
- }
- else {
- handleResponse(boost::shared_ptr<Payload>(), ErrorPayload::ref(new ErrorPayload(ErrorPayload::UndefinedCondition)));
- }
- }
- router_->removeHandler(this);
- handled = true;
- }
- }
- }
- return handled;
+bool Request::handleIQ(std::shared_ptr<IQ> iq) {
+ bool handled = false;
+ if (iq->getType() == IQ::Result || iq->getType() == IQ::Error) {
+ if (sent_ && iq->getID() == id_) {
+ if (isCorrectSender(iq->getFrom())) {
+ if (iq->getType() == IQ::Result) {
+ std::shared_ptr<Payload> payload = iq->getPayloadOfSameType(payload_);
+ if (!payload && std::dynamic_pointer_cast<RawXMLPayload>(payload_) && !iq->getPayloads().empty()) {
+ payload = iq->getPayloads().front();
+ }
+ handleResponse(payload, ErrorPayload::ref());
+ }
+ else {
+ ErrorPayload::ref errorPayload = iq->getPayload<ErrorPayload>();
+ if (errorPayload) {
+ handleResponse(std::shared_ptr<Payload>(), errorPayload);
+ }
+ else {
+ handleResponse(std::shared_ptr<Payload>(), ErrorPayload::ref(new ErrorPayload(ErrorPayload::UndefinedCondition)));
+ }
+ }
+ router_->removeHandler(this);
+ handled = true;
+ }
+ }
+ }
+ return handled;
}
bool Request::isCorrectSender(const JID& jid) {
- if (router_->isAccountJID(receiver_)) {
- if (jid.isValid() && jid.equals(router_->getJID(), JID::WithResource)) {
- // This unspecified behavior seems to happen in ejabberd versions (e.g. 2.0.5)
- SWIFT_LOG(warning) << "Server responded to an account request with a full JID, which is not allowed. Handling it anyway.";
- return true;
- }
- return router_->isAccountJID(jid);
- }
- else {
- return jid.equals(receiver_, JID::WithResource);
- }
+ if (router_->isAccountJID(receiver_)) {
+ if (jid.isValid() && jid.equals(router_->getJID(), JID::WithResource)) {
+ // This unspecified behavior seems to happen in ejabberd versions (e.g. 2.0.5)
+ SWIFT_LOG(warning) << "Server responded to an account request with a full JID, which is not allowed. Handling it anyway.";
+ return true;
+ }
+ return router_->isAccountJID(jid);
+ }
+ else {
+ return jid.equals(receiver_, JID::WithResource);
+ }
}
diff --git a/Swiften/Queries/Request.h b/Swiften/Queries/Request.h
index 707f81e..a62c103 100644
--- a/Swiften/Queries/Request.h
+++ b/Swiften/Queries/Request.h
@@ -1,106 +1,106 @@
/*
- * Copyright (c) 2010 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#pragma once
-#include <boost/shared_ptr.hpp>
-#include <boost/optional.hpp>
-#include <boost/enable_shared_from_this.hpp>
+#include <memory>
#include <string>
+#include <boost/optional.hpp>
+
#include <Swiften/Base/API.h>
-#include <Swiften/Queries/IQHandler.h>
+#include <Swiften/Elements/ErrorPayload.h>
#include <Swiften/Elements/IQ.h>
#include <Swiften/Elements/Payload.h>
-#include <Swiften/Elements/ErrorPayload.h>
#include <Swiften/JID/JID.h>
+#include <Swiften/Queries/IQHandler.h>
namespace Swift {
- /**
- * An IQ get/set request query.
- */
- class SWIFTEN_API Request : public IQHandler, public boost::enable_shared_from_this<Request> {
- public:
- std::string send();
-
- const JID& getReceiver() const {
- return receiver_;
- }
-
- /**
- * Returns the ID of this request.
- * This will only be set after send() is called.
- */
- const std::string& getID() const {
- return id_;
- }
-
-
- protected:
- /**
- * Constructs a request of a certain type to a specific receiver, and attaches the given
- * payload.
- */
- Request(
- IQ::Type type,
- const JID& receiver,
- boost::shared_ptr<Payload> payload,
- IQRouter* router);
-
- /**
- * Constructs a request of a certain type to a specific receiver from a specific sender, and attaches the given
- * payload.
- */
- Request(
- IQ::Type type,
- const JID& sender,
- const JID& receiver,
- boost::shared_ptr<Payload> payload,
- IQRouter* router);
-
-
- /**
- * Constructs a request of a certain type to a specific receiver.
- */
- Request(
- IQ::Type type,
- const JID& receiver,
- IQRouter* router);
-
- /**
- * Constructs a request of a certain type to a specific receiver from a specific sender.
- */
- Request(
- IQ::Type type,
- const JID& sender,
- const JID& receiver,
- IQRouter* router);
-
-
- virtual void setPayload(boost::shared_ptr<Payload> payload) {
- payload_ = payload;
- }
-
- boost::shared_ptr<Payload> getPayload() const {
- return payload_;
- }
-
- virtual void handleResponse(boost::shared_ptr<Payload>, boost::shared_ptr<ErrorPayload>) = 0;
-
- private:
- bool handleIQ(boost::shared_ptr<IQ>);
- bool isCorrectSender(const JID& jid);
-
- private:
- IQRouter* router_;
- IQ::Type type_;
- JID sender_;
- JID receiver_;
- boost::shared_ptr<Payload> payload_;
- std::string id_;
- bool sent_;
- };
+ /**
+ * An IQ get/set request query.
+ */
+ class SWIFTEN_API Request : public IQHandler, public std::enable_shared_from_this<Request> {
+ public:
+ std::string send();
+
+ const JID& getReceiver() const {
+ return receiver_;
+ }
+
+ /**
+ * Returns the ID of this request.
+ * This will only be set after send() is called.
+ */
+ const std::string& getID() const {
+ return id_;
+ }
+
+
+ protected:
+ /**
+ * Constructs a request of a certain type to a specific receiver, and attaches the given
+ * payload.
+ */
+ Request(
+ IQ::Type type,
+ const JID& receiver,
+ std::shared_ptr<Payload> payload,
+ IQRouter* router);
+
+ /**
+ * Constructs a request of a certain type to a specific receiver from a specific sender, and attaches the given
+ * payload.
+ */
+ Request(
+ IQ::Type type,
+ const JID& sender,
+ const JID& receiver,
+ std::shared_ptr<Payload> payload,
+ IQRouter* router);
+
+
+ /**
+ * Constructs a request of a certain type to a specific receiver.
+ */
+ Request(
+ IQ::Type type,
+ const JID& receiver,
+ IQRouter* router);
+
+ /**
+ * Constructs a request of a certain type to a specific receiver from a specific sender.
+ */
+ Request(
+ IQ::Type type,
+ const JID& sender,
+ const JID& receiver,
+ IQRouter* router);
+
+
+ virtual void setPayload(std::shared_ptr<Payload> payload) {
+ payload_ = payload;
+ }
+
+ std::shared_ptr<Payload> getPayload() const {
+ return payload_;
+ }
+
+ virtual void handleResponse(std::shared_ptr<Payload>, std::shared_ptr<ErrorPayload>) = 0;
+
+ private:
+ bool handleIQ(std::shared_ptr<IQ>);
+ bool isCorrectSender(const JID& jid);
+
+ private:
+ IQRouter* router_;
+ IQ::Type type_;
+ JID sender_;
+ JID receiver_;
+ std::shared_ptr<Payload> payload_;
+ std::string id_;
+ bool sent_;
+ };
}
diff --git a/Swiften/Queries/Requests/EnableCarbonsRequest.h b/Swiften/Queries/Requests/EnableCarbonsRequest.h
new file mode 100644
index 0000000..7762e68
--- /dev/null
+++ b/Swiften/Queries/Requests/EnableCarbonsRequest.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2016 Isode Limited.
+ * All rights reserved.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <memory>
+
+#include <Swiften/Base/API.h>
+#include <Swiften/Elements/CarbonsEnable.h>
+#include <Swiften/Queries/GenericRequest.h>
+
+namespace Swift {
+ class SWIFTEN_API EnableCarbonsRequest : public GenericRequest<CarbonsEnable> {
+ public:
+ typedef std::shared_ptr<EnableCarbonsRequest> ref;
+
+ static ref create(IQRouter* router) {
+ return ref(new EnableCarbonsRequest(router));
+ }
+
+ private:
+ EnableCarbonsRequest(IQRouter* router) : GenericRequest<CarbonsEnable>(IQ::Set, JID(), std::make_shared<CarbonsEnable>(), router) {
+ }
+ };
+}
diff --git a/Swiften/Queries/Requests/GetInBandRegistrationFormRequest.cpp b/Swiften/Queries/Requests/GetInBandRegistrationFormRequest.cpp
deleted file mode 100644
index d04e5c7..0000000
--- a/Swiften/Queries/Requests/GetInBandRegistrationFormRequest.cpp
+++ /dev/null
@@ -1,7 +0,0 @@
-/*
- * Copyright (c) 2010 Isode Limited.
- * All rights reserved.
- * See the COPYING file for more information.
- */
-
-#include <Swiften/Queries/Requests/GetInBandRegistrationFormRequest.h>
diff --git a/Swiften/Queries/Requests/GetInBandRegistrationFormRequest.h b/Swiften/Queries/Requests/GetInBandRegistrationFormRequest.h
index b952875..b187fa5 100644
--- a/Swiften/Queries/Requests/GetInBandRegistrationFormRequest.h
+++ b/Swiften/Queries/Requests/GetInBandRegistrationFormRequest.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010-2015 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -7,20 +7,20 @@
#pragma once
#include <Swiften/Base/API.h>
-#include <Swiften/Queries/GenericRequest.h>
#include <Swiften/Elements/InBandRegistrationPayload.h>
+#include <Swiften/Queries/GenericRequest.h>
namespace Swift {
- class SWIFTEN_API GetInBandRegistrationFormRequest : public GenericRequest<InBandRegistrationPayload> {
- public:
- typedef boost::shared_ptr<GetInBandRegistrationFormRequest> ref;
+ class SWIFTEN_API GetInBandRegistrationFormRequest : public GenericRequest<InBandRegistrationPayload> {
+ public:
+ typedef std::shared_ptr<GetInBandRegistrationFormRequest> ref;
- static ref create(const JID& to, IQRouter* router) {
- return ref(new GetInBandRegistrationFormRequest(to, router));
- }
+ static ref create(const JID& to, IQRouter* router) {
+ return ref(new GetInBandRegistrationFormRequest(to, router));
+ }
- private:
- GetInBandRegistrationFormRequest(const JID& to, IQRouter* router) : GenericRequest<InBandRegistrationPayload>(IQ::Get, to, InBandRegistrationPayload::ref(new InBandRegistrationPayload()), router) {
- }
- };
+ private:
+ GetInBandRegistrationFormRequest(const JID& to, IQRouter* router) : GenericRequest<InBandRegistrationPayload>(IQ::Get, to, InBandRegistrationPayload::ref(new InBandRegistrationPayload()), router) {
+ }
+ };
}
diff --git a/Swiften/Queries/Requests/GetPrivateStorageRequest.h b/Swiften/Queries/Requests/GetPrivateStorageRequest.h
index 97711a6..5fb0de5 100644
--- a/Swiften/Queries/Requests/GetPrivateStorageRequest.h
+++ b/Swiften/Queries/Requests/GetPrivateStorageRequest.h
@@ -1,45 +1,45 @@
/*
- * Copyright (c) 2010-2015 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#pragma once
-#include <Swiften/Base/boost_bsignals.h>
-#include <boost/shared_ptr.hpp>
-#include <boost/smart_ptr/make_shared.hpp>
+#include <memory>
+
+#include <boost/signals2.hpp>
#include <Swiften/Base/API.h>
-#include <Swiften/Queries/Request.h>
-#include <Swiften/Elements/PrivateStorage.h>
#include <Swiften/Elements/ErrorPayload.h>
+#include <Swiften/Elements/PrivateStorage.h>
+#include <Swiften/Queries/Request.h>
namespace Swift {
- template<typename PAYLOAD_TYPE>
- class SWIFTEN_API GetPrivateStorageRequest : public Request {
- public:
- typedef boost::shared_ptr<GetPrivateStorageRequest<PAYLOAD_TYPE> > ref;
-
- static ref create(IQRouter* router) {
- return ref(new GetPrivateStorageRequest(router));
- }
-
- private:
- GetPrivateStorageRequest(IQRouter* router) : Request(IQ::Get, JID(), boost::make_shared<PrivateStorage>(boost::shared_ptr<Payload>(new PAYLOAD_TYPE())), router) {
- }
-
- virtual void handleResponse(boost::shared_ptr<Payload> payload, ErrorPayload::ref error) {
- boost::shared_ptr<PrivateStorage> storage = boost::dynamic_pointer_cast<PrivateStorage>(payload);
- if (storage) {
- onResponse(boost::dynamic_pointer_cast<PAYLOAD_TYPE>(storage->getPayload()), error);
- }
- else {
- onResponse(boost::shared_ptr<PAYLOAD_TYPE>(), error);
- }
- }
-
- public:
- boost::signal<void (boost::shared_ptr<PAYLOAD_TYPE>, ErrorPayload::ref)> onResponse;
- };
+ template<typename PAYLOAD_TYPE>
+ class SWIFTEN_API GetPrivateStorageRequest : public Request {
+ public:
+ typedef std::shared_ptr<GetPrivateStorageRequest<PAYLOAD_TYPE> > ref;
+
+ static ref create(IQRouter* router) {
+ return ref(new GetPrivateStorageRequest(router));
+ }
+
+ private:
+ GetPrivateStorageRequest(IQRouter* router) : Request(IQ::Get, JID(), std::make_shared<PrivateStorage>(std::make_shared<PAYLOAD_TYPE>()), router) {
+ }
+
+ virtual void handleResponse(std::shared_ptr<Payload> payload, ErrorPayload::ref error) {
+ std::shared_ptr<PrivateStorage> storage = std::dynamic_pointer_cast<PrivateStorage>(payload);
+ if (storage) {
+ onResponse(std::dynamic_pointer_cast<PAYLOAD_TYPE>(storage->getPayload()), error);
+ }
+ else {
+ onResponse(std::shared_ptr<PAYLOAD_TYPE>(), error);
+ }
+ }
+
+ public:
+ boost::signals2::signal<void (std::shared_ptr<PAYLOAD_TYPE>, ErrorPayload::ref)> onResponse;
+ };
}
diff --git a/Swiften/Queries/Requests/GetSecurityLabelsCatalogRequest.h b/Swiften/Queries/Requests/GetSecurityLabelsCatalogRequest.h
index 7a76fcc..0a3502f 100644
--- a/Swiften/Queries/Requests/GetSecurityLabelsCatalogRequest.h
+++ b/Swiften/Queries/Requests/GetSecurityLabelsCatalogRequest.h
@@ -1,33 +1,32 @@
/*
- * Copyright (c) 2010-2015 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#pragma once
-#include <boost/smart_ptr/make_shared.hpp>
+#include <memory>
#include <Swiften/Base/API.h>
-#include <Swiften/Queries/GenericRequest.h>
#include <Swiften/Elements/SecurityLabelsCatalog.h>
-
+#include <Swiften/Queries/GenericRequest.h>
namespace Swift {
- class SWIFTEN_API GetSecurityLabelsCatalogRequest : public GenericRequest<SecurityLabelsCatalog> {
- public:
- typedef boost::shared_ptr<GetSecurityLabelsCatalogRequest> ref;
+ class SWIFTEN_API GetSecurityLabelsCatalogRequest : public GenericRequest<SecurityLabelsCatalog> {
+ public:
+ typedef std::shared_ptr<GetSecurityLabelsCatalogRequest> ref;
- static ref create(const JID& recipient, IQRouter* router) {
- return ref(new GetSecurityLabelsCatalogRequest(recipient, router));
- }
+ static ref create(const JID& recipient, IQRouter* router) {
+ return ref(new GetSecurityLabelsCatalogRequest(recipient, router));
+ }
- private:
- GetSecurityLabelsCatalogRequest(
- const JID& recipient,
- IQRouter* router) :
- GenericRequest<SecurityLabelsCatalog>(
- IQ::Get, JID(), boost::make_shared<SecurityLabelsCatalog>(recipient), router) {
- }
- };
+ private:
+ GetSecurityLabelsCatalogRequest(
+ const JID& recipient,
+ IQRouter* router) :
+ GenericRequest<SecurityLabelsCatalog>(
+ IQ::Get, JID(), std::make_shared<SecurityLabelsCatalog>(recipient), router) {
+ }
+ };
}
diff --git a/Swiften/Queries/Requests/GetSoftwareVersionRequest.h b/Swiften/Queries/Requests/GetSoftwareVersionRequest.h
index 1084a0b..5660dd8 100644
--- a/Swiften/Queries/Requests/GetSoftwareVersionRequest.h
+++ b/Swiften/Queries/Requests/GetSoftwareVersionRequest.h
@@ -1,32 +1,32 @@
/*
- * Copyright (c) 2010-2015 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#pragma once
+#include <memory>
+
#include <Swiften/Base/API.h>
-#include <Swiften/Queries/GenericRequest.h>
#include <Swiften/Elements/SoftwareVersion.h>
-#include <boost/smart_ptr/make_shared.hpp>
-
+#include <Swiften/Queries/GenericRequest.h>
namespace Swift {
- class SWIFTEN_API GetSoftwareVersionRequest : public GenericRequest<SoftwareVersion> {
- public:
- typedef boost::shared_ptr<GetSoftwareVersionRequest> ref;
+ class SWIFTEN_API GetSoftwareVersionRequest : public GenericRequest<SoftwareVersion> {
+ public:
+ typedef std::shared_ptr<GetSoftwareVersionRequest> ref;
- static ref create(const JID& recipient, IQRouter* router) {
- return ref(new GetSoftwareVersionRequest(recipient, router));
- }
+ static ref create(const JID& recipient, IQRouter* router) {
+ return ref(new GetSoftwareVersionRequest(recipient, router));
+ }
- private:
- GetSoftwareVersionRequest(
- const JID& recipient,
- IQRouter* router) :
- GenericRequest<SoftwareVersion>(
- IQ::Get, recipient, boost::make_shared<SoftwareVersion>(), router) {
- }
- };
+ private:
+ GetSoftwareVersionRequest(
+ const JID& recipient,
+ IQRouter* router) :
+ GenericRequest<SoftwareVersion>(
+ IQ::Get, recipient, std::make_shared<SoftwareVersion>(), router) {
+ }
+ };
}
diff --git a/Swiften/Queries/Requests/SetPrivateStorageRequest.h b/Swiften/Queries/Requests/SetPrivateStorageRequest.h
index 9ab65f7..f1dc77a 100644
--- a/Swiften/Queries/Requests/SetPrivateStorageRequest.h
+++ b/Swiften/Queries/Requests/SetPrivateStorageRequest.h
@@ -1,39 +1,39 @@
/*
- * Copyright (c) 2010-2015 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#pragma once
-#include <Swiften/Base/boost_bsignals.h>
-#include <boost/shared_ptr.hpp>
-#include <boost/smart_ptr/make_shared.hpp>
+#include <memory>
+
+#include <boost/signals2.hpp>
#include <Swiften/Base/API.h>
-#include <Swiften/Queries/Request.h>
-#include <Swiften/Elements/PrivateStorage.h>
#include <Swiften/Elements/ErrorPayload.h>
+#include <Swiften/Elements/PrivateStorage.h>
+#include <Swiften/Queries/Request.h>
namespace Swift {
- template<typename PAYLOAD_TYPE>
- class SWIFTEN_API SetPrivateStorageRequest : public Request {
- public:
- typedef boost::shared_ptr<SetPrivateStorageRequest<PAYLOAD_TYPE> > ref;
-
- static ref create(boost::shared_ptr<PAYLOAD_TYPE> payload, IQRouter* router) {
- return ref(new SetPrivateStorageRequest<PAYLOAD_TYPE>(payload, router));
- }
-
- private:
- SetPrivateStorageRequest(boost::shared_ptr<PAYLOAD_TYPE> payload, IQRouter* router) : Request(IQ::Set, JID(), boost::make_shared<PrivateStorage>(payload), router) {
- }
-
- virtual void handleResponse(boost::shared_ptr<Payload>, ErrorPayload::ref error) {
- onResponse(error);
- }
-
- public:
- boost::signal<void (ErrorPayload::ref)> onResponse;
- };
+ template<typename PAYLOAD_TYPE>
+ class SWIFTEN_API SetPrivateStorageRequest : public Request {
+ public:
+ typedef std::shared_ptr<SetPrivateStorageRequest<PAYLOAD_TYPE> > ref;
+
+ static ref create(std::shared_ptr<PAYLOAD_TYPE> payload, IQRouter* router) {
+ return ref(new SetPrivateStorageRequest<PAYLOAD_TYPE>(payload, router));
+ }
+
+ private:
+ SetPrivateStorageRequest(std::shared_ptr<PAYLOAD_TYPE> payload, IQRouter* router) : Request(IQ::Set, JID(), std::make_shared<PrivateStorage>(payload), router) {
+ }
+
+ virtual void handleResponse(std::shared_ptr<Payload>, ErrorPayload::ref error) {
+ onResponse(error);
+ }
+
+ public:
+ boost::signals2::signal<void (ErrorPayload::ref)> onResponse;
+ };
}
diff --git a/Swiften/Queries/Requests/SubmitInBandRegistrationFormRequest.cpp b/Swiften/Queries/Requests/SubmitInBandRegistrationFormRequest.cpp
deleted file mode 100644
index d99ddca..0000000
--- a/Swiften/Queries/Requests/SubmitInBandRegistrationFormRequest.cpp
+++ /dev/null
@@ -1,7 +0,0 @@
-/*
- * Copyright (c) 2010 Isode Limited.
- * All rights reserved.
- * See the COPYING file for more information.
- */
-
-#include <Swiften/Queries/Requests/SubmitInBandRegistrationFormRequest.h>
diff --git a/Swiften/Queries/Requests/SubmitInBandRegistrationFormRequest.h b/Swiften/Queries/Requests/SubmitInBandRegistrationFormRequest.h
index e79562a..1cf28c5 100644
--- a/Swiften/Queries/Requests/SubmitInBandRegistrationFormRequest.h
+++ b/Swiften/Queries/Requests/SubmitInBandRegistrationFormRequest.h
@@ -1,37 +1,37 @@
/*
- * Copyright (c) 2010-2015 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#pragma once
-#include <Swiften/Base/boost_bsignals.h>
-#include <boost/shared_ptr.hpp>
+#include <memory>
+
+#include <boost/signals2.hpp>
#include <Swiften/Base/API.h>
-#include <Swiften/Queries/Request.h>
#include <Swiften/Elements/InBandRegistrationPayload.h>
-
+#include <Swiften/Queries/Request.h>
namespace Swift {
- class SWIFTEN_API SetInBandRegistrationRequest : public Request {
- public:
- typedef boost::shared_ptr<SetInBandRegistrationRequest> ref;
+ class SWIFTEN_API SetInBandRegistrationRequest : public Request {
+ public:
+ typedef std::shared_ptr<SetInBandRegistrationRequest> ref;
- static ref create(const JID& to, InBandRegistrationPayload::ref payload, IQRouter* router) {
- return ref(new SetInBandRegistrationRequest(to, payload, router));
- }
+ static ref create(const JID& to, InBandRegistrationPayload::ref payload, IQRouter* router) {
+ return ref(new SetInBandRegistrationRequest(to, payload, router));
+ }
- private:
- SetInBandRegistrationRequest(const JID& to, InBandRegistrationPayload::ref payload, IQRouter* router) : Request(IQ::Set, to, InBandRegistrationPayload::ref(payload), router) {
- }
+ private:
+ SetInBandRegistrationRequest(const JID& to, InBandRegistrationPayload::ref payload, IQRouter* router) : Request(IQ::Set, to, InBandRegistrationPayload::ref(payload), router) {
+ }
- virtual void handleResponse(boost::shared_ptr<Payload> payload, ErrorPayload::ref error) {
- onResponse(payload, error);
- }
+ virtual void handleResponse(std::shared_ptr<Payload> payload, ErrorPayload::ref error) {
+ onResponse(payload, error);
+ }
- public:
- boost::signal<void (boost::shared_ptr<Payload>, ErrorPayload::ref)> onResponse;
- };
+ public:
+ boost::signals2::signal<void (std::shared_ptr<Payload>, ErrorPayload::ref)> onResponse;
+ };
}
diff --git a/Swiften/Queries/Requests/UnitTest/GetPrivateStorageRequestTest.cpp b/Swiften/Queries/Requests/UnitTest/GetPrivateStorageRequestTest.cpp
index 5b0a704..8a4b9fc 100644
--- a/Swiften/Queries/Requests/UnitTest/GetPrivateStorageRequestTest.cpp
+++ b/Swiften/Queries/Requests/UnitTest/GetPrivateStorageRequestTest.cpp
@@ -1,109 +1,110 @@
/*
- * Copyright (c) 2010 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
+#include <memory>
+
+#include <boost/bind.hpp>
+
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
-#include <boost/shared_ptr.hpp>
-#include <boost/bind.hpp>
-#include <Swiften/Queries/Requests/GetPrivateStorageRequest.h>
-#include <Swiften/Queries/IQRouter.h>
-#include <Swiften/Queries/DummyIQChannel.h>
#include <Swiften/Elements/Payload.h>
+#include <Swiften/Queries/DummyIQChannel.h>
+#include <Swiften/Queries/IQRouter.h>
+#include <Swiften/Queries/Requests/GetPrivateStorageRequest.h>
using namespace Swift;
class GetPrivateStorageRequestTest : public CppUnit::TestFixture {
- CPPUNIT_TEST_SUITE(GetPrivateStorageRequestTest);
- CPPUNIT_TEST(testSend);
- CPPUNIT_TEST(testHandleResponse);
- CPPUNIT_TEST(testHandleResponse_Error);
- CPPUNIT_TEST_SUITE_END();
-
- public:
- class MyPayload : public Payload {
- public:
- MyPayload(const std::string& text = "") : text(text) {}
- std::string text;
- };
-
- public:
- void setUp() {
- channel = new DummyIQChannel();
- router = new IQRouter(channel);
- }
-
- void tearDown() {
- delete router;
- delete channel;
- }
-
- void testSend() {
- GetPrivateStorageRequest<MyPayload>::ref request = GetPrivateStorageRequest<MyPayload>::create(router);
- request->send();
-
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(channel->iqs_.size()));
- CPPUNIT_ASSERT_EQUAL(JID(), channel->iqs_[0]->getTo());
- CPPUNIT_ASSERT_EQUAL(IQ::Get, channel->iqs_[0]->getType());
- boost::shared_ptr<PrivateStorage> storage = channel->iqs_[0]->getPayload<PrivateStorage>();
- CPPUNIT_ASSERT(storage);
- boost::shared_ptr<MyPayload> payload = boost::dynamic_pointer_cast<MyPayload>(storage->getPayload());
- CPPUNIT_ASSERT(payload);
- }
-
- void testHandleResponse() {
- GetPrivateStorageRequest<MyPayload>::ref testling = GetPrivateStorageRequest<MyPayload>::create(router);
- testling->onResponse.connect(boost::bind(&GetPrivateStorageRequestTest::handleResponse, this, _1, _2));
- testling->send();
- channel->onIQReceived(createResponse("test-id", "foo"));
-
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(responses.size()));
- CPPUNIT_ASSERT_EQUAL(std::string("foo"), boost::dynamic_pointer_cast<MyPayload>(responses[0])->text);
- }
-
- void testHandleResponse_Error() {
- GetPrivateStorageRequest<MyPayload>::ref testling = GetPrivateStorageRequest<MyPayload>::create(router);
- testling->onResponse.connect(boost::bind(&GetPrivateStorageRequestTest::handleResponse, this, _1, _2));
- testling->send();
- channel->onIQReceived(createError("test-id"));
-
- CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(responses.size()));
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(errors.size()));
- }
-
- private:
- void handleResponse(boost::shared_ptr<Payload> p, ErrorPayload::ref e) {
- if (e) {
- errors.push_back(*e);
- }
- else {
- responses.push_back(p);
- }
- }
-
- boost::shared_ptr<IQ> createResponse(const std::string& id, const std::string& text) {
- boost::shared_ptr<IQ> iq(new IQ(IQ::Result));
- boost::shared_ptr<PrivateStorage> storage(new PrivateStorage());
- storage->setPayload(boost::shared_ptr<Payload>(new MyPayload(text)));
- iq->addPayload(storage);
- iq->setID(id);
- return iq;
- }
-
- boost::shared_ptr<IQ> createError(const std::string& id) {
- boost::shared_ptr<IQ> iq(new IQ(IQ::Error));
- iq->setID(id);
- return iq;
- }
-
- private:
- IQRouter* router;
- DummyIQChannel* channel;
- std::vector< ErrorPayload > errors;
- std::vector< boost::shared_ptr<Payload> > responses;
+ CPPUNIT_TEST_SUITE(GetPrivateStorageRequestTest);
+ CPPUNIT_TEST(testSend);
+ CPPUNIT_TEST(testHandleResponse);
+ CPPUNIT_TEST(testHandleResponse_Error);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ class MyPayload : public Payload {
+ public:
+ MyPayload(const std::string& text = "") : text(text) {}
+ std::string text;
+ };
+
+ public:
+ void setUp() {
+ channel = std::unique_ptr<DummyIQChannel>(new DummyIQChannel());
+ router = std::unique_ptr<IQRouter>(new IQRouter(channel.get()));
+ }
+
+ void tearDown() {
+ router.reset();
+ }
+
+ void testSend() {
+ GetPrivateStorageRequest<MyPayload>::ref request = GetPrivateStorageRequest<MyPayload>::create(router.get());
+ request->send();
+
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(channel->iqs_.size()));
+ CPPUNIT_ASSERT_EQUAL(JID(), channel->iqs_[0]->getTo());
+ CPPUNIT_ASSERT_EQUAL(IQ::Get, channel->iqs_[0]->getType());
+ std::shared_ptr<PrivateStorage> storage = channel->iqs_[0]->getPayload<PrivateStorage>();
+ CPPUNIT_ASSERT(storage);
+ std::shared_ptr<MyPayload> payload = std::dynamic_pointer_cast<MyPayload>(storage->getPayload());
+ CPPUNIT_ASSERT(payload);
+ }
+
+ void testHandleResponse() {
+ GetPrivateStorageRequest<MyPayload>::ref testling = GetPrivateStorageRequest<MyPayload>::create(router.get());
+ testling->onResponse.connect(boost::bind(&GetPrivateStorageRequestTest::handleResponse, this, _1, _2));
+ testling->send();
+ channel->onIQReceived(createResponse("test-id", "foo"));
+
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(responses.size()));
+ CPPUNIT_ASSERT_EQUAL(std::string("foo"), std::dynamic_pointer_cast<MyPayload>(responses[0])->text);
+ }
+
+ void testHandleResponse_Error() {
+ GetPrivateStorageRequest<MyPayload>::ref testling = GetPrivateStorageRequest<MyPayload>::create(router.get());
+ testling->onResponse.connect(boost::bind(&GetPrivateStorageRequestTest::handleResponse, this, _1, _2));
+ testling->send();
+ channel->onIQReceived(createError("test-id"));
+
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(responses.size()));
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(errors.size()));
+ }
+
+ private:
+ void handleResponse(std::shared_ptr<Payload> p, ErrorPayload::ref e) {
+ if (e) {
+ errors.push_back(*e);
+ }
+ else {
+ responses.push_back(p);
+ }
+ }
+
+ std::shared_ptr<IQ> createResponse(const std::string& id, const std::string& text) {
+ std::shared_ptr<IQ> iq(new IQ(IQ::Result));
+ std::shared_ptr<PrivateStorage> storage(new PrivateStorage());
+ storage->setPayload(std::make_shared<MyPayload>(text));
+ iq->addPayload(storage);
+ iq->setID(id);
+ return iq;
+ }
+
+ std::shared_ptr<IQ> createError(const std::string& id) {
+ std::shared_ptr<IQ> iq(new IQ(IQ::Error));
+ iq->setID(id);
+ return iq;
+ }
+
+ private:
+ std::unique_ptr<IQRouter> router;
+ std::unique_ptr<DummyIQChannel> channel;
+ std::vector< ErrorPayload > errors;
+ std::vector< std::shared_ptr<Payload> > responses;
};
CPPUNIT_TEST_SUITE_REGISTRATION(GetPrivateStorageRequestTest);
diff --git a/Swiften/Queries/Responder.h b/Swiften/Queries/Responder.h
index 8a201e6..0974adf 100644
--- a/Swiften/Queries/Responder.h
+++ b/Swiften/Queries/Responder.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010-2015 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -7,130 +7,130 @@
#pragma once
#include <Swiften/Base/API.h>
+#include <Swiften/Elements/ErrorPayload.h>
#include <Swiften/Queries/IQHandler.h>
#include <Swiften/Queries/IQRouter.h>
-#include <Swiften/Elements/ErrorPayload.h>
namespace Swift {
- /**
- * A class for handling incoming IQ Get and Set requests of a specific payload type.
- *
- * Concrete subclasses of this class need to implement handleGetRequest() and handleSetRequest() to
- * implement the behavior of the responder.
- *
- * \tparam PAYLOAD_TYPE The type of payload this Responder handles. Only IQ requests containing this
- * payload type will be passed to handleGetRequest() and handleSetRequest()
- */
- template<typename PAYLOAD_TYPE>
- class SWIFTEN_API Responder : public IQHandler {
- public:
- Responder(IQRouter* router) : router_(router), isFinalResonder_(true) {
- }
-
- ~Responder() {
- }
-
- /**
- * Starts the responder.
- *
- * After the responder has started, it will start receiving and responding to requests.
- *
- * \see stop()
- */
- void start() {
- router_->addHandler(this);
- }
-
- /**
- * Stops the responder.
- *
- * When the responder is stopped, it will no longer receive incoming requests.
- *
- * \see start()
- */
- void stop() {
- router_->removeHandler(this);
- }
-
- protected:
- /**
- * Handle an incoming IQ-Get request containing a payload of class PAYLOAD_TYPE.
- *
- * This method is implemented in the concrete subclasses.
- */
- virtual bool handleGetRequest(const JID& from, const JID& to, const std::string& id, boost::shared_ptr<PAYLOAD_TYPE> payload) = 0;
-
- /**
- * Handle an incoming IQ-Set request containing a payload of class PAYLOAD_TYPE.
- *
- * This method is implemented in the concrete subclasses.
- */
- virtual bool handleSetRequest(const JID& from, const JID& to, const std::string& id, boost::shared_ptr<PAYLOAD_TYPE> payload) = 0;
-
- /**
- * Convenience function for sending an IQ response.
- */
- void sendResponse(const JID& to, const std::string& id, boost::shared_ptr<PAYLOAD_TYPE> payload) {
- router_->sendIQ(IQ::createResult(to, id, payload));
- }
-
- /**
- * Convenience function for sending an IQ response, with a specific from address.
- */
- void sendResponse(const JID& to, const JID& from, const std::string& id, boost::shared_ptr<PAYLOAD_TYPE> payload) {
- router_->sendIQ(IQ::createResult(to, from, id, payload));
- }
-
- /**
- * Convenience function for responding with an error.
- */
- void sendError(const JID& to, const std::string& id, ErrorPayload::Condition condition, ErrorPayload::Type type, Payload::ref payload = Payload::ref()) {
- router_->sendIQ(IQ::createError(to, id, condition, type, payload));
- }
-
- /**
- * Convenience function for responding with an error from a specific from address.
- */
- void sendError(const JID& to, const JID& from, const std::string& id, ErrorPayload::Condition condition, ErrorPayload::Type type, Payload::ref payload = Payload::ref()) {
- router_->sendIQ(IQ::createError(to, from, id, condition, type, payload));
- }
-
- IQRouter* getIQRouter() const {
- return router_;
- }
-
- void setFinal(bool isFinal) {
- isFinalResonder_ = isFinal;
- }
-
- private:
- virtual bool handleIQ(boost::shared_ptr<IQ> iq) {
- if (iq->getType() == IQ::Set || iq->getType() == IQ::Get) {
- boost::shared_ptr<PAYLOAD_TYPE> payload(iq->getPayload<PAYLOAD_TYPE>());
- if (payload) {
- bool result;
- if (iq->getType() == IQ::Set) {
- result = handleSetRequest(iq->getFrom(), iq->getTo(), iq->getID(), payload);
- }
- else {
- result = handleGetRequest(iq->getFrom(), iq->getTo(), iq->getID(), payload);
- }
- if (!result) {
- if (isFinalResonder_) {
- router_->sendIQ(IQ::createError(iq->getFrom(), iq->getID(), ErrorPayload::NotAllowed, ErrorPayload::Cancel));
- }
- else {
- return false;
- }
- }
- return true;
- }
- }
- return false;
- }
-
- private:
- IQRouter* router_;
- bool isFinalResonder_;
- };
+ /**
+ * A class for handling incoming IQ Get and Set requests of a specific payload type.
+ *
+ * Concrete subclasses of this class need to implement handleGetRequest() and handleSetRequest() to
+ * implement the behavior of the responder.
+ *
+ * \tparam PAYLOAD_TYPE The type of payload this Responder handles. Only IQ requests containing this
+ * payload type will be passed to handleGetRequest() and handleSetRequest()
+ */
+ template<typename PAYLOAD_TYPE>
+ class SWIFTEN_API Responder : public IQHandler {
+ public:
+ Responder(IQRouter* router) : router_(router), isFinalResonder_(true) {
+ }
+
+ ~Responder() {
+ }
+
+ /**
+ * Starts the responder.
+ *
+ * After the responder has started, it will start receiving and responding to requests.
+ *
+ * \see stop()
+ */
+ void start() {
+ router_->addHandler(this);
+ }
+
+ /**
+ * Stops the responder.
+ *
+ * When the responder is stopped, it will no longer receive incoming requests.
+ *
+ * \see start()
+ */
+ void stop() {
+ router_->removeHandler(this);
+ }
+
+ protected:
+ /**
+ * Handle an incoming IQ-Get request containing a payload of class PAYLOAD_TYPE.
+ *
+ * This method is implemented in the concrete subclasses.
+ */
+ virtual bool handleGetRequest(const JID& from, const JID& to, const std::string& id, std::shared_ptr<PAYLOAD_TYPE> payload) = 0;
+
+ /**
+ * Handle an incoming IQ-Set request containing a payload of class PAYLOAD_TYPE.
+ *
+ * This method is implemented in the concrete subclasses.
+ */
+ virtual bool handleSetRequest(const JID& from, const JID& to, const std::string& id, std::shared_ptr<PAYLOAD_TYPE> payload) = 0;
+
+ /**
+ * Convenience function for sending an IQ response.
+ */
+ void sendResponse(const JID& to, const std::string& id, std::shared_ptr<PAYLOAD_TYPE> payload) {
+ router_->sendIQ(IQ::createResult(to, id, payload));
+ }
+
+ /**
+ * Convenience function for sending an IQ response, with a specific from address.
+ */
+ void sendResponse(const JID& to, const JID& from, const std::string& id, std::shared_ptr<PAYLOAD_TYPE> payload) {
+ router_->sendIQ(IQ::createResult(to, from, id, payload));
+ }
+
+ /**
+ * Convenience function for responding with an error.
+ */
+ void sendError(const JID& to, const std::string& id, ErrorPayload::Condition condition, ErrorPayload::Type type, Payload::ref payload = Payload::ref()) {
+ router_->sendIQ(IQ::createError(to, id, condition, type, payload));
+ }
+
+ /**
+ * Convenience function for responding with an error from a specific from address.
+ */
+ void sendError(const JID& to, const JID& from, const std::string& id, ErrorPayload::Condition condition, ErrorPayload::Type type, Payload::ref payload = Payload::ref()) {
+ router_->sendIQ(IQ::createError(to, from, id, condition, type, payload));
+ }
+
+ IQRouter* getIQRouter() const {
+ return router_;
+ }
+
+ void setFinal(bool isFinal) {
+ isFinalResonder_ = isFinal;
+ }
+
+ private:
+ virtual bool handleIQ(std::shared_ptr<IQ> iq) {
+ if (iq->getType() == IQ::Set || iq->getType() == IQ::Get) {
+ std::shared_ptr<PAYLOAD_TYPE> payload(iq->getPayload<PAYLOAD_TYPE>());
+ if (payload) {
+ bool result;
+ if (iq->getType() == IQ::Set) {
+ result = handleSetRequest(iq->getFrom(), iq->getTo(), iq->getID(), payload);
+ }
+ else {
+ result = handleGetRequest(iq->getFrom(), iq->getTo(), iq->getID(), payload);
+ }
+ if (!result) {
+ if (isFinalResonder_) {
+ router_->sendIQ(IQ::createError(iq->getFrom(), iq->getID(), ErrorPayload::NotAllowed, ErrorPayload::Cancel));
+ }
+ else {
+ return false;
+ }
+ }
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private:
+ IQRouter* router_;
+ bool isFinalResonder_;
+ };
}
diff --git a/Swiften/Queries/Responders/SoftwareVersionResponder.cpp b/Swiften/Queries/Responders/SoftwareVersionResponder.cpp
index 6c10a2b..5071f6e 100644
--- a/Swiften/Queries/Responders/SoftwareVersionResponder.cpp
+++ b/Swiften/Queries/Responders/SoftwareVersionResponder.cpp
@@ -1,12 +1,13 @@
/*
- * Copyright (c) 2010 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
-#include <boost/smart_ptr/make_shared.hpp>
-
#include <Swiften/Queries/Responders/SoftwareVersionResponder.h>
+
+#include <memory>
+
#include <Swiften/Queries/IQRouter.h>
namespace Swift {
@@ -15,14 +16,14 @@ SoftwareVersionResponder::SoftwareVersionResponder(IQRouter* router) : GetRespon
}
void SoftwareVersionResponder::setVersion(const std::string& client, const std::string& version, const std::string& os) {
- this->client = client;
- this->version = version;
- this->os = os;
+ this->client = client;
+ this->version = version;
+ this->os = os;
}
-bool SoftwareVersionResponder::handleGetRequest(const JID& from, const JID&, const std::string& id, boost::shared_ptr<SoftwareVersion>) {
- sendResponse(from, id, boost::make_shared<SoftwareVersion>(client, version, os));
- return true;
+bool SoftwareVersionResponder::handleGetRequest(const JID& from, const JID&, const std::string& id, std::shared_ptr<SoftwareVersion>) {
+ sendResponse(from, id, std::make_shared<SoftwareVersion>(client, version, os));
+ return true;
}
}
diff --git a/Swiften/Queries/Responders/SoftwareVersionResponder.h b/Swiften/Queries/Responders/SoftwareVersionResponder.h
index 4418333..4bb3425 100644
--- a/Swiften/Queries/Responders/SoftwareVersionResponder.h
+++ b/Swiften/Queries/Responders/SoftwareVersionResponder.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -7,24 +7,24 @@
#pragma once
#include <Swiften/Base/API.h>
-#include <Swiften/Queries/GetResponder.h>
#include <Swiften/Elements/SoftwareVersion.h>
+#include <Swiften/Queries/GetResponder.h>
namespace Swift {
- class IQRouter;
+ class IQRouter;
- class SWIFTEN_API SoftwareVersionResponder : public GetResponder<SoftwareVersion> {
- public:
- SoftwareVersionResponder(IQRouter* router);
+ class SWIFTEN_API SoftwareVersionResponder : public GetResponder<SoftwareVersion> {
+ public:
+ SoftwareVersionResponder(IQRouter* router);
- void setVersion(const std::string& client, const std::string& version, const std::string& os = "");
+ void setVersion(const std::string& client, const std::string& version, const std::string& os = "");
- private:
- virtual bool handleGetRequest(const JID& from, const JID& to, const std::string& id, boost::shared_ptr<SoftwareVersion> payload);
+ private:
+ virtual bool handleGetRequest(const JID& from, const JID& to, const std::string& id, std::shared_ptr<SoftwareVersion> payload);
- private:
- std::string client;
- std::string version;
- std::string os;
- };
+ private:
+ std::string client;
+ std::string version;
+ std::string os;
+ };
}
diff --git a/Swiften/Queries/SetResponder.h b/Swiften/Queries/SetResponder.h
index 5e7d42d..e2842f4 100644
--- a/Swiften/Queries/SetResponder.h
+++ b/Swiften/Queries/SetResponder.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010-2015 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -10,12 +10,12 @@
#include <Swiften/Queries/Responder.h>
namespace Swift {
- template<typename T>
- class SWIFTEN_API SetResponder : public Responder<T> {
- public:
- SetResponder(IQRouter* router) : Responder<T>(router) {}
+ template<typename T>
+ class SWIFTEN_API SetResponder : public Responder<T> {
+ public:
+ SetResponder(IQRouter* router) : Responder<T>(router) {}
- private:
- virtual bool handleGetRequest(const JID&, const JID&, const std::string&, boost::shared_ptr<T>) { return false; }
- };
+ private:
+ virtual bool handleGetRequest(const JID&, const JID&, const std::string&, std::shared_ptr<T>) { return false; }
+ };
}
diff --git a/Swiften/Queries/UnitTest/IQRouterTest.cpp b/Swiften/Queries/UnitTest/IQRouterTest.cpp
index 660e632..0acb87b 100644
--- a/Swiften/Queries/UnitTest/IQRouterTest.cpp
+++ b/Swiften/Queries/UnitTest/IQRouterTest.cpp
@@ -1,177 +1,178 @@
/*
- * Copyright (c) 2010 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
+#include <memory>
+
+#include <boost/bind.hpp>
+
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
-#include <boost/shared_ptr.hpp>
-#include <boost/smart_ptr/make_shared.hpp>
-#include <boost/bind.hpp>
+#include <Swiften/Queries/DummyIQChannel.h>
#include <Swiften/Queries/IQHandler.h>
#include <Swiften/Queries/IQRouter.h>
-#include <Swiften/Queries/DummyIQChannel.h>
using namespace Swift;
class IQRouterTest : public CppUnit::TestFixture {
- CPPUNIT_TEST_SUITE(IQRouterTest);
- CPPUNIT_TEST(testRemoveHandler);
- CPPUNIT_TEST(testRemoveHandler_AfterHandleIQ);
- CPPUNIT_TEST(testHandleIQ_SuccesfulHandlerFirst);
- CPPUNIT_TEST(testHandleIQ_SuccesfulHandlerLast);
- CPPUNIT_TEST(testHandleIQ_NoSuccesfulHandler);
- CPPUNIT_TEST(testHandleIQ_HandlerRemovedDuringHandle);
- CPPUNIT_TEST(testSendIQ_WithFrom);
- CPPUNIT_TEST(testSendIQ_WithoutFrom);
- CPPUNIT_TEST(testHandleIQ_WithFrom);
- CPPUNIT_TEST_SUITE_END();
+ CPPUNIT_TEST_SUITE(IQRouterTest);
+ CPPUNIT_TEST(testRemoveHandler);
+ CPPUNIT_TEST(testRemoveHandler_AfterHandleIQ);
+ CPPUNIT_TEST(testHandleIQ_SuccesfulHandlerFirst);
+ CPPUNIT_TEST(testHandleIQ_SuccesfulHandlerLast);
+ CPPUNIT_TEST(testHandleIQ_NoSuccesfulHandler);
+ CPPUNIT_TEST(testHandleIQ_HandlerRemovedDuringHandle);
+ CPPUNIT_TEST(testSendIQ_WithFrom);
+ CPPUNIT_TEST(testSendIQ_WithoutFrom);
+ CPPUNIT_TEST(testHandleIQ_WithFrom);
+ CPPUNIT_TEST_SUITE_END();
- public:
- void setUp() {
- channel_ = new DummyIQChannel();
- }
+ public:
+ void setUp() {
+ channel_ = new DummyIQChannel();
+ }
- void tearDown() {
- delete channel_;
- }
+ void tearDown() {
+ delete channel_;
+ }
- void testRemoveHandler() {
- IQRouter testling(channel_);
- DummyIQHandler handler1(true, &testling);
- DummyIQHandler handler2(true, &testling);
- testling.removeHandler(&handler1);
+ void testRemoveHandler() {
+ IQRouter testling(channel_);
+ DummyIQHandler handler1(true, &testling);
+ DummyIQHandler handler2(true, &testling);
+ testling.removeHandler(&handler1);
- channel_->onIQReceived(boost::make_shared<IQ>());
+ channel_->onIQReceived(std::make_shared<IQ>());
- CPPUNIT_ASSERT_EQUAL(0, handler1.called);
- CPPUNIT_ASSERT_EQUAL(1, handler2.called);
- }
+ CPPUNIT_ASSERT_EQUAL(0, handler1.called);
+ CPPUNIT_ASSERT_EQUAL(1, handler2.called);
+ }
- void testRemoveHandler_AfterHandleIQ() {
- IQRouter testling(channel_);
- DummyIQHandler handler2(true, &testling);
- DummyIQHandler handler1(true, &testling);
-
- channel_->onIQReceived(boost::make_shared<IQ>());
- testling.removeHandler(&handler1);
- channel_->onIQReceived(boost::make_shared<IQ>());
-
- CPPUNIT_ASSERT_EQUAL(1, handler1.called);
- CPPUNIT_ASSERT_EQUAL(1, handler2.called);
- }
-
- void testHandleIQ_SuccesfulHandlerFirst() {
- IQRouter testling(channel_);
- DummyIQHandler handler2(false, &testling);
- DummyIQHandler handler1(true, &testling);
-
- channel_->onIQReceived(boost::make_shared<IQ>());
-
- CPPUNIT_ASSERT_EQUAL(1, handler1.called);
- CPPUNIT_ASSERT_EQUAL(0, handler2.called);
- CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(channel_->iqs_.size()));
- }
-
- void testHandleIQ_SuccesfulHandlerLast() {
- IQRouter testling(channel_);
- DummyIQHandler handler2(true, &testling);
- DummyIQHandler handler1(false, &testling);
-
- channel_->onIQReceived(boost::make_shared<IQ>());
-
- CPPUNIT_ASSERT_EQUAL(1, handler1.called);
- CPPUNIT_ASSERT_EQUAL(1, handler2.called);
- CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(channel_->iqs_.size()));
- }
-
- void testHandleIQ_NoSuccesfulHandler() {
- IQRouter testling(channel_);
- DummyIQHandler handler(false, &testling);
-
- channel_->onIQReceived(boost::make_shared<IQ>());
-
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(channel_->iqs_.size()));
- CPPUNIT_ASSERT(channel_->iqs_[0]->getPayload<ErrorPayload>());
- }
-
-
- void testHandleIQ_HandlerRemovedDuringHandle() {
- IQRouter testling(channel_);
- DummyIQHandler handler2(true, &testling);
- RemovingIQHandler handler1(&testling);
-
- channel_->onIQReceived(boost::make_shared<IQ>());
- channel_->onIQReceived(boost::make_shared<IQ>());
-
- CPPUNIT_ASSERT_EQUAL(1, handler1.called);
- CPPUNIT_ASSERT_EQUAL(2, handler2.called);
- }
-
- void testSendIQ_WithFrom() {
- IQRouter testling(channel_);
- testling.setFrom(JID("foo@bar.com/baz"));
-
- testling.sendIQ(boost::make_shared<IQ>());
-
- CPPUNIT_ASSERT_EQUAL(JID("foo@bar.com/baz"), channel_->iqs_[0]->getFrom());
- }
-
- void testSendIQ_WithoutFrom() {
- IQRouter testling(channel_);
+ void testRemoveHandler_AfterHandleIQ() {
+ IQRouter testling(channel_);
+ DummyIQHandler handler2(true, &testling);
+ DummyIQHandler handler1(true, &testling);
+
+ channel_->onIQReceived(std::make_shared<IQ>());
+ testling.removeHandler(&handler1);
+ channel_->onIQReceived(std::make_shared<IQ>());
+
+ CPPUNIT_ASSERT_EQUAL(1, handler1.called);
+ CPPUNIT_ASSERT_EQUAL(1, handler2.called);
+ }
+
+ void testHandleIQ_SuccesfulHandlerFirst() {
+ IQRouter testling(channel_);
+ DummyIQHandler handler2(false, &testling);
+ DummyIQHandler handler1(true, &testling);
+
+ channel_->onIQReceived(std::make_shared<IQ>());
+
+ CPPUNIT_ASSERT_EQUAL(1, handler1.called);
+ CPPUNIT_ASSERT_EQUAL(0, handler2.called);
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(channel_->iqs_.size()));
+ }
+
+ void testHandleIQ_SuccesfulHandlerLast() {
+ IQRouter testling(channel_);
+ DummyIQHandler handler2(true, &testling);
+ DummyIQHandler handler1(false, &testling);
+
+ channel_->onIQReceived(std::make_shared<IQ>());
+
+ CPPUNIT_ASSERT_EQUAL(1, handler1.called);
+ CPPUNIT_ASSERT_EQUAL(1, handler2.called);
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(channel_->iqs_.size()));
+ }
+
+ void testHandleIQ_NoSuccesfulHandler() {
+ IQRouter testling(channel_);
+ DummyIQHandler handler(false, &testling);
+
+ channel_->onIQReceived(std::make_shared<IQ>());
+
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(channel_->iqs_.size()));
+ CPPUNIT_ASSERT(channel_->iqs_[0]->getPayload<ErrorPayload>());
+ }
+
+
+ void testHandleIQ_HandlerRemovedDuringHandle() {
+ IQRouter testling(channel_);
+ DummyIQHandler handler2(true, &testling);
+ RemovingIQHandler handler1(&testling);
+
+ channel_->onIQReceived(std::make_shared<IQ>());
+ channel_->onIQReceived(std::make_shared<IQ>());
+
+ CPPUNIT_ASSERT_EQUAL(1, handler1.called);
+ CPPUNIT_ASSERT_EQUAL(2, handler2.called);
+ }
+
+ void testSendIQ_WithFrom() {
+ IQRouter testling(channel_);
+ testling.setFrom(JID("foo@bar.com/baz"));
+
+ testling.sendIQ(std::make_shared<IQ>());
+
+ CPPUNIT_ASSERT_EQUAL(JID("foo@bar.com/baz"), channel_->iqs_[0]->getFrom());
+ }
+
+ void testSendIQ_WithoutFrom() {
+ IQRouter testling(channel_);
- testling.sendIQ(boost::make_shared<IQ>());
+ testling.sendIQ(std::make_shared<IQ>());
- CPPUNIT_ASSERT_EQUAL(JID(), channel_->iqs_[0]->getFrom());
- }
+ CPPUNIT_ASSERT_EQUAL(JID(), channel_->iqs_[0]->getFrom());
+ }
- void testHandleIQ_WithFrom() {
- IQRouter testling(channel_);
- testling.setFrom(JID("foo@bar.com/baz"));
- DummyIQHandler handler(false, &testling);
+ void testHandleIQ_WithFrom() {
+ IQRouter testling(channel_);
+ testling.setFrom(JID("foo@bar.com/baz"));
+ DummyIQHandler handler(false, &testling);
- channel_->onIQReceived(boost::make_shared<IQ>());
+ channel_->onIQReceived(std::make_shared<IQ>());
- CPPUNIT_ASSERT_EQUAL(JID("foo@bar.com/baz"), channel_->iqs_[0]->getFrom());
- }
+ CPPUNIT_ASSERT_EQUAL(JID("foo@bar.com/baz"), channel_->iqs_[0]->getFrom());
+ }
- private:
- struct DummyIQHandler : public IQHandler {
- DummyIQHandler(bool handle, IQRouter* router) : handle(handle), router(router), called(0) {
- router->addHandler(this);
- }
+ private:
+ struct DummyIQHandler : public IQHandler {
+ DummyIQHandler(bool handle, IQRouter* router) : handle(handle), router(router), called(0) {
+ router->addHandler(this);
+ }
- ~DummyIQHandler() {
- router->removeHandler(this);
- }
+ ~DummyIQHandler() {
+ router->removeHandler(this);
+ }
- virtual bool handleIQ(boost::shared_ptr<IQ>) {
- called++;
- return handle;
- }
- bool handle;
- IQRouter* router;
- int called;
- };
+ virtual bool handleIQ(std::shared_ptr<IQ>) {
+ called++;
+ return handle;
+ }
+ bool handle;
+ IQRouter* router;
+ int called;
+ };
- struct RemovingIQHandler : public IQHandler {
- RemovingIQHandler(IQRouter* router) : router(router), called(0) {
- router->addHandler(this);
- }
+ struct RemovingIQHandler : public IQHandler {
+ RemovingIQHandler(IQRouter* router) : router(router), called(0) {
+ router->addHandler(this);
+ }
- virtual bool handleIQ(boost::shared_ptr<IQ>) {
- called++;
- router->removeHandler(this);
- return false;
- }
- IQRouter* router;
- int called;
- };
+ virtual bool handleIQ(std::shared_ptr<IQ>) {
+ called++;
+ router->removeHandler(this);
+ return false;
+ }
+ IQRouter* router;
+ int called;
+ };
- DummyIQChannel* channel_;
+ DummyIQChannel* channel_;
};
CPPUNIT_TEST_SUITE_REGISTRATION(IQRouterTest);
diff --git a/Swiften/Queries/UnitTest/RequestTest.cpp b/Swiften/Queries/UnitTest/RequestTest.cpp
index 46532f5..b46f1d4 100644
--- a/Swiften/Queries/UnitTest/RequestTest.cpp
+++ b/Swiften/Queries/UnitTest/RequestTest.cpp
@@ -1,366 +1,367 @@
/*
- * Copyright (c) 2010 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
+#include <memory>
+
+#include <boost/bind.hpp>
+
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
-#include <boost/shared_ptr.hpp>
-#include <boost/bind.hpp>
-#include <boost/smart_ptr/make_shared.hpp>
-#include <Swiften/Queries/GenericRequest.h>
-#include <Swiften/Queries/IQRouter.h>
-#include <Swiften/Queries/DummyIQChannel.h>
#include <Swiften/Elements/Payload.h>
#include <Swiften/Elements/RawXMLPayload.h>
+#include <Swiften/Queries/DummyIQChannel.h>
+#include <Swiften/Queries/GenericRequest.h>
+#include <Swiften/Queries/IQRouter.h>
using namespace Swift;
class RequestTest : public CppUnit::TestFixture {
- CPPUNIT_TEST_SUITE(RequestTest);
- CPPUNIT_TEST(testSendGet);
- CPPUNIT_TEST(testSendSet);
- CPPUNIT_TEST(testHandleIQ);
- CPPUNIT_TEST(testHandleIQ_InvalidID);
- CPPUNIT_TEST(testHandleIQ_Error);
- CPPUNIT_TEST(testHandleIQ_ErrorWithoutPayload);
- CPPUNIT_TEST(testHandleIQ_BeforeSend);
- CPPUNIT_TEST(testHandleIQ_DifferentPayload);
- CPPUNIT_TEST(testHandleIQ_RawXMLPayload);
- CPPUNIT_TEST(testHandleIQ_GetWithSameID);
- CPPUNIT_TEST(testHandleIQ_SetWithSameID);
- CPPUNIT_TEST(testHandleIQ_IncorrectSender);
- CPPUNIT_TEST(testHandleIQ_IncorrectSenderForServerQuery);
- CPPUNIT_TEST(testHandleIQ_IncorrectOtherResourceSenderForServerQuery);
- CPPUNIT_TEST(testHandleIQ_ServerRespondsWithDomain);
- CPPUNIT_TEST(testHandleIQ_ServerRespondsWithBareJID);
- CPPUNIT_TEST(testHandleIQ_ServerRespondsWithoutFrom);
- CPPUNIT_TEST(testHandleIQ_ServerRespondsWithFullJID);
- CPPUNIT_TEST_SUITE_END();
-
- public:
- class MyPayload : public Payload {
- public:
- MyPayload(const std::string& s = "") : text_(s) {}
- std::string text_;
- };
-
- struct MyOtherPayload : public Payload {
- };
-
- class MyRequest : public Request {
- public:
- MyRequest(
- IQ::Type type,
- const JID& receiver,
- boost::shared_ptr<Payload> payload,
- IQRouter* router) :
- Request(type, receiver, payload, router) {
- }
-
- virtual void handleResponse(boost::shared_ptr<Payload> payload, ErrorPayload::ref error) {
- onResponse(payload, error);
- }
-
- public:
- boost::signal<void (boost::shared_ptr<Payload>, ErrorPayload::ref)> onResponse;
- };
-
- public:
- void setUp() {
- channel_ = new DummyIQChannel();
- router_ = new IQRouter(channel_);
- payload_ = boost::shared_ptr<Payload>(new MyPayload("foo"));
- responsePayload_ = boost::shared_ptr<Payload>(new MyPayload("bar"));
- responsesReceived_ = 0;
- }
-
- void tearDown() {
- delete router_;
- delete channel_;
- }
-
- void testSendSet() {
- MyRequest testling(IQ::Set, JID("foo@bar.com/baz"), payload_, router_);
- testling.send();
-
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(channel_->iqs_.size()));
- CPPUNIT_ASSERT_EQUAL(JID("foo@bar.com/baz"), channel_->iqs_[0]->getTo());
- CPPUNIT_ASSERT_EQUAL(IQ::Set, channel_->iqs_[0]->getType());
- CPPUNIT_ASSERT_EQUAL(std::string("test-id"), channel_->iqs_[0]->getID());
- }
-
- void testSendGet() {
- MyRequest testling(IQ::Get, JID("foo@bar.com/baz"), payload_, router_);
- testling.send();
-
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(channel_->iqs_.size()));
- CPPUNIT_ASSERT_EQUAL(IQ::Get, channel_->iqs_[0]->getType());
- }
-
- void testHandleIQ() {
- MyRequest testling(IQ::Get, JID("foo@bar.com/baz"), payload_, router_);
- testling.onResponse.connect(boost::bind(&RequestTest::handleResponse, this, _1, _2));
- testling.send();
-
- channel_->onIQReceived(createResponse(JID("foo@bar.com/baz"),"test-id"));
-
- CPPUNIT_ASSERT_EQUAL(1, responsesReceived_);
- CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(receivedErrors.size()));
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(channel_->iqs_.size()));
- }
-
- // FIXME: Doesn't test that it didn't handle the payload
- void testHandleIQ_InvalidID() {
- MyRequest testling(IQ::Get, JID("foo@bar.com/baz"), payload_, router_);
- testling.onResponse.connect(boost::bind(&RequestTest::handleResponse, this, _1, _2));
- testling.send();
-
- channel_->onIQReceived(createResponse(JID("foo@bar.com/baz"),"different-id"));
-
- CPPUNIT_ASSERT_EQUAL(0, responsesReceived_);
- CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(receivedErrors.size()));
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(channel_->iqs_.size()));
- }
-
- void testHandleIQ_Error() {
- MyRequest testling(IQ::Get, JID("foo@bar.com/baz"), payload_, router_);
- testling.onResponse.connect(boost::bind(&RequestTest::handleResponse, this, _1, _2));
- testling.send();
-
- boost::shared_ptr<IQ> error = createError(JID("foo@bar.com/baz"),"test-id");
- boost::shared_ptr<Payload> errorPayload = boost::make_shared<ErrorPayload>(ErrorPayload::InternalServerError);
- error->addPayload(errorPayload);
- channel_->onIQReceived(error);
-
- CPPUNIT_ASSERT_EQUAL(0, responsesReceived_);
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(receivedErrors.size()));
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(channel_->iqs_.size()));
- CPPUNIT_ASSERT_EQUAL(ErrorPayload::InternalServerError, receivedErrors[0].getCondition());
- }
-
- void testHandleIQ_ErrorWithoutPayload() {
- MyRequest testling(IQ::Get, JID("foo@bar.com/baz"), payload_, router_);
- testling.onResponse.connect(boost::bind(&RequestTest::handleResponse, this, _1, _2));
- testling.send();
-
- channel_->onIQReceived(createError(JID("foo@bar.com/baz"),"test-id"));
-
- CPPUNIT_ASSERT_EQUAL(0, responsesReceived_);
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(receivedErrors.size()));
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(channel_->iqs_.size()));
- CPPUNIT_ASSERT_EQUAL(ErrorPayload::UndefinedCondition, receivedErrors[0].getCondition());
- }
-
- 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(JID("foo@bar.com/baz"),"test-id"));
-
- CPPUNIT_ASSERT_EQUAL(0, responsesReceived_);
- CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(receivedErrors.size()));
- CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(channel_->iqs_.size()));
- }
-
- void testHandleIQ_DifferentPayload() {
- MyRequest testling(IQ::Get, JID("foo@bar.com/baz"), payload_, router_);
- testling.onResponse.connect(boost::bind(&RequestTest::handleDifferentResponse, this, _1, _2));
- testling.send();
-
- responsePayload_ = boost::make_shared<MyOtherPayload>();
- channel_->onIQReceived(createResponse(JID("foo@bar.com/baz"),"test-id"));
-
- CPPUNIT_ASSERT_EQUAL(1, responsesReceived_);
- CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(receivedErrors.size()));
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(channel_->iqs_.size()));
- }
-
- void testHandleIQ_RawXMLPayload() {
- payload_ = boost::make_shared<RawXMLPayload>("<bla/>");
- MyRequest testling(IQ::Get, JID("foo@bar.com/baz"), payload_, router_);
- testling.onResponse.connect(boost::bind(&RequestTest::handleRawXMLResponse, this, _1, _2));
- testling.send();
-
- responsePayload_ = boost::make_shared<MyOtherPayload>();
- channel_->onIQReceived(createResponse(JID("foo@bar.com/baz"),"test-id"));
-
- CPPUNIT_ASSERT_EQUAL(1, responsesReceived_);
- CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(receivedErrors.size()));
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(channel_->iqs_.size()));
- }
-
- void testHandleIQ_GetWithSameID() {
- MyRequest testling(IQ::Get, JID("foo@bar.com/baz"), payload_, router_);
- testling.onResponse.connect(boost::bind(&RequestTest::handleResponse, this, _1, _2));
- testling.send();
-
- boost::shared_ptr<IQ> response = createResponse(JID("foo@bar.com/baz"),"test-id");
- response->setType(IQ::Get);
- channel_->onIQReceived(response);
-
- CPPUNIT_ASSERT_EQUAL(0, responsesReceived_);
- CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(receivedErrors.size()));
- CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(channel_->iqs_.size()));
- }
-
- void testHandleIQ_SetWithSameID() {
- MyRequest testling(IQ::Get, JID("foo@bar.com/baz"), payload_, router_);
- testling.onResponse.connect(boost::bind(&RequestTest::handleResponse, this, _1, _2));
- testling.send();
-
- boost::shared_ptr<IQ> response = createResponse(JID("foo@bar.com/baz"), "test-id");
- response->setType(IQ::Set);
- channel_->onIQReceived(response);
-
- CPPUNIT_ASSERT_EQUAL(0, responsesReceived_);
- CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(receivedErrors.size()));
- CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(channel_->iqs_.size()));
- }
-
- void testHandleIQ_IncorrectSender() {
- MyRequest testling(IQ::Get, JID("foo@bar.com/baz"), payload_, router_);
- router_->setJID("alice@wonderland.lit/TeaParty");
- testling.onResponse.connect(boost::bind(&RequestTest::handleResponse, this, _1, _2));
- testling.send();
-
- channel_->onIQReceived(createResponse(JID("anotherfoo@bar.com/baz"), "test-id"));
-
- CPPUNIT_ASSERT_EQUAL(0, responsesReceived_);
- CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(receivedErrors.size()));
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(channel_->iqs_.size()));
- }
-
- void testHandleIQ_IncorrectSenderForServerQuery() {
- MyRequest testling(IQ::Get, JID(), payload_, router_);
- router_->setJID("alice@wonderland.lit/TeaParty");
- testling.onResponse.connect(boost::bind(&RequestTest::handleResponse, this, _1, _2));
- testling.send();
-
- channel_->onIQReceived(createResponse(JID("foo@bar.com/baz"), "test-id"));
-
- CPPUNIT_ASSERT_EQUAL(0, responsesReceived_);
- CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(receivedErrors.size()));
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(channel_->iqs_.size()));
- }
-
- void testHandleIQ_IncorrectOtherResourceSenderForServerQuery() {
- MyRequest testling(IQ::Get, JID(), payload_, router_);
- router_->setJID("alice@wonderland.lit/TeaParty");
- testling.onResponse.connect(boost::bind(&RequestTest::handleResponse, this, _1, _2));
- testling.send();
-
- channel_->onIQReceived(createResponse(JID("alice@wonderland.lit/RabbitHole"), "test-id"));
-
- CPPUNIT_ASSERT_EQUAL(0, responsesReceived_);
- CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(receivedErrors.size()));
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(channel_->iqs_.size()));
- }
-
- void testHandleIQ_ServerRespondsWithDomain() {
- MyRequest testling(IQ::Get, JID(), payload_, router_);
- router_->setJID("alice@wonderland.lit/TeaParty");
- testling.onResponse.connect(boost::bind(&RequestTest::handleResponse, this, _1, _2));
- testling.send();
-
- channel_->onIQReceived(createResponse(JID("wonderland.lit"),"test-id"));
-
- CPPUNIT_ASSERT_EQUAL(0, responsesReceived_);
- CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(receivedErrors.size()));
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(channel_->iqs_.size()));
- }
-
- void testHandleIQ_ServerRespondsWithBareJID() {
- MyRequest testling(IQ::Get, JID(), payload_, router_);
- router_->setJID("alice@wonderland.lit/TeaParty");
- testling.onResponse.connect(boost::bind(&RequestTest::handleResponse, this, _1, _2));
- testling.send();
-
- channel_->onIQReceived(createResponse(JID("alice@wonderland.lit"),"test-id"));
-
- CPPUNIT_ASSERT_EQUAL(1, responsesReceived_);
- CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(receivedErrors.size()));
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(channel_->iqs_.size()));
- }
-
- // This tests a bug in ejabberd servers (2.0.5)
- void testHandleIQ_ServerRespondsWithFullJID() {
- MyRequest testling(IQ::Get, JID(), payload_, router_);
- router_->setJID("alice@wonderland.lit/TeaParty");
- testling.onResponse.connect(boost::bind(&RequestTest::handleResponse, this, _1, _2));
- testling.send();
-
- channel_->onIQReceived(createResponse(JID("alice@wonderland.lit/TeaParty"),"test-id"));
-
- CPPUNIT_ASSERT_EQUAL(1, responsesReceived_);
- CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(receivedErrors.size()));
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(channel_->iqs_.size()));
- }
-
- void testHandleIQ_ServerRespondsWithoutFrom() {
- MyRequest testling(IQ::Get, JID(), payload_, router_);
- router_->setJID("alice@wonderland.lit/TeaParty");
- testling.onResponse.connect(boost::bind(&RequestTest::handleResponse, this, _1, _2));
- testling.send();
-
- channel_->onIQReceived(createResponse(JID(),"test-id"));
-
- CPPUNIT_ASSERT_EQUAL(1, responsesReceived_);
- CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(receivedErrors.size()));
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(channel_->iqs_.size()));
- }
-
-
-
- private:
- void handleResponse(boost::shared_ptr<Payload> p, ErrorPayload::ref e) {
- if (e) {
- receivedErrors.push_back(*e);
- }
- else {
- boost::shared_ptr<MyPayload> payload(boost::dynamic_pointer_cast<MyPayload>(p));
- CPPUNIT_ASSERT(payload);
- CPPUNIT_ASSERT_EQUAL(std::string("bar"), payload->text_);
- ++responsesReceived_;
- }
- }
-
- void handleDifferentResponse(boost::shared_ptr<Payload> p, ErrorPayload::ref e) {
- CPPUNIT_ASSERT(!e);
- CPPUNIT_ASSERT(!p);
- ++responsesReceived_;
- }
-
- void handleRawXMLResponse(boost::shared_ptr<Payload> p, ErrorPayload::ref e) {
- CPPUNIT_ASSERT(!e);
- CPPUNIT_ASSERT(p);
- CPPUNIT_ASSERT(boost::dynamic_pointer_cast<MyOtherPayload>(p));
- ++responsesReceived_;
- }
-
- boost::shared_ptr<IQ> createResponse(const JID& from, const std::string& id) {
- boost::shared_ptr<IQ> iq(new IQ(IQ::Result));
- iq->setFrom(from);
- iq->addPayload(responsePayload_);
- iq->setID(id);
- return iq;
- }
-
- boost::shared_ptr<IQ> createError(const JID& from, const std::string& id) {
- boost::shared_ptr<IQ> iq(new IQ(IQ::Error));
- iq->setFrom(from);
- iq->setID(id);
- return iq;
- }
-
- private:
- IQRouter* router_;
- DummyIQChannel* channel_;
- boost::shared_ptr<Payload> payload_;
- boost::shared_ptr<Payload> responsePayload_;
- int responsesReceived_;
- std::vector<ErrorPayload> receivedErrors;
+ CPPUNIT_TEST_SUITE(RequestTest);
+ CPPUNIT_TEST(testSendGet);
+ CPPUNIT_TEST(testSendSet);
+ CPPUNIT_TEST(testHandleIQ);
+ CPPUNIT_TEST(testHandleIQ_InvalidID);
+ CPPUNIT_TEST(testHandleIQ_Error);
+ CPPUNIT_TEST(testHandleIQ_ErrorWithoutPayload);
+ CPPUNIT_TEST(testHandleIQ_BeforeSend);
+ CPPUNIT_TEST(testHandleIQ_DifferentPayload);
+ CPPUNIT_TEST(testHandleIQ_RawXMLPayload);
+ CPPUNIT_TEST(testHandleIQ_GetWithSameID);
+ CPPUNIT_TEST(testHandleIQ_SetWithSameID);
+ CPPUNIT_TEST(testHandleIQ_IncorrectSender);
+ CPPUNIT_TEST(testHandleIQ_IncorrectSenderForServerQuery);
+ CPPUNIT_TEST(testHandleIQ_IncorrectOtherResourceSenderForServerQuery);
+ CPPUNIT_TEST(testHandleIQ_ServerRespondsWithDomain);
+ CPPUNIT_TEST(testHandleIQ_ServerRespondsWithBareJID);
+ CPPUNIT_TEST(testHandleIQ_ServerRespondsWithoutFrom);
+ CPPUNIT_TEST(testHandleIQ_ServerRespondsWithFullJID);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ class MyPayload : public Payload {
+ public:
+ MyPayload(const std::string& s = "") : text_(s) {}
+ std::string text_;
+ };
+
+ struct MyOtherPayload : public Payload {
+ };
+
+ class MyRequest : public Request {
+ public:
+ MyRequest(
+ IQ::Type type,
+ const JID& receiver,
+ std::shared_ptr<Payload> payload,
+ IQRouter* router) :
+ Request(type, receiver, payload, router) {
+ }
+
+ virtual void handleResponse(std::shared_ptr<Payload> payload, ErrorPayload::ref error) {
+ onResponse(payload, error);
+ }
+
+ public:
+ boost::signals2::signal<void (std::shared_ptr<Payload>, ErrorPayload::ref)> onResponse;
+ };
+
+ public:
+ void setUp() {
+ channel_ = new DummyIQChannel();
+ router_ = new IQRouter(channel_);
+ payload_ = std::make_shared<MyPayload>("foo");
+ responsePayload_ = std::make_shared<MyPayload>("bar");
+ responsesReceived_ = 0;
+ }
+
+ void tearDown() {
+ delete router_;
+ delete channel_;
+ }
+
+ void testSendSet() {
+ MyRequest testling(IQ::Set, JID("foo@bar.com/baz"), payload_, router_);
+ testling.send();
+
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(channel_->iqs_.size()));
+ CPPUNIT_ASSERT_EQUAL(JID("foo@bar.com/baz"), channel_->iqs_[0]->getTo());
+ CPPUNIT_ASSERT_EQUAL(IQ::Set, channel_->iqs_[0]->getType());
+ CPPUNIT_ASSERT_EQUAL(std::string("test-id"), channel_->iqs_[0]->getID());
+ }
+
+ void testSendGet() {
+ MyRequest testling(IQ::Get, JID("foo@bar.com/baz"), payload_, router_);
+ testling.send();
+
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(channel_->iqs_.size()));
+ CPPUNIT_ASSERT_EQUAL(IQ::Get, channel_->iqs_[0]->getType());
+ }
+
+ void testHandleIQ() {
+ MyRequest testling(IQ::Get, JID("foo@bar.com/baz"), payload_, router_);
+ testling.onResponse.connect(boost::bind(&RequestTest::handleResponse, this, _1, _2));
+ testling.send();
+
+ channel_->onIQReceived(createResponse(JID("foo@bar.com/baz"),"test-id"));
+
+ CPPUNIT_ASSERT_EQUAL(1, responsesReceived_);
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(receivedErrors.size()));
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(channel_->iqs_.size()));
+ }
+
+ // FIXME: Doesn't test that it didn't handle the payload
+ void testHandleIQ_InvalidID() {
+ MyRequest testling(IQ::Get, JID("foo@bar.com/baz"), payload_, router_);
+ testling.onResponse.connect(boost::bind(&RequestTest::handleResponse, this, _1, _2));
+ testling.send();
+
+ channel_->onIQReceived(createResponse(JID("foo@bar.com/baz"),"different-id"));
+
+ CPPUNIT_ASSERT_EQUAL(0, responsesReceived_);
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(receivedErrors.size()));
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(channel_->iqs_.size()));
+ }
+
+ void testHandleIQ_Error() {
+ MyRequest testling(IQ::Get, JID("foo@bar.com/baz"), payload_, router_);
+ testling.onResponse.connect(boost::bind(&RequestTest::handleResponse, this, _1, _2));
+ testling.send();
+
+ std::shared_ptr<IQ> error = createError(JID("foo@bar.com/baz"),"test-id");
+ std::shared_ptr<Payload> errorPayload = std::make_shared<ErrorPayload>(ErrorPayload::InternalServerError);
+ error->addPayload(errorPayload);
+ channel_->onIQReceived(error);
+
+ CPPUNIT_ASSERT_EQUAL(0, responsesReceived_);
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(receivedErrors.size()));
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(channel_->iqs_.size()));
+ CPPUNIT_ASSERT_EQUAL(ErrorPayload::InternalServerError, receivedErrors[0].getCondition());
+ }
+
+ void testHandleIQ_ErrorWithoutPayload() {
+ MyRequest testling(IQ::Get, JID("foo@bar.com/baz"), payload_, router_);
+ testling.onResponse.connect(boost::bind(&RequestTest::handleResponse, this, _1, _2));
+ testling.send();
+
+ channel_->onIQReceived(createError(JID("foo@bar.com/baz"),"test-id"));
+
+ CPPUNIT_ASSERT_EQUAL(0, responsesReceived_);
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(receivedErrors.size()));
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(channel_->iqs_.size()));
+ CPPUNIT_ASSERT_EQUAL(ErrorPayload::UndefinedCondition, receivedErrors[0].getCondition());
+ }
+
+ 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(JID("foo@bar.com/baz"),"test-id"));
+
+ CPPUNIT_ASSERT_EQUAL(0, responsesReceived_);
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(receivedErrors.size()));
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(channel_->iqs_.size()));
+ }
+
+ void testHandleIQ_DifferentPayload() {
+ MyRequest testling(IQ::Get, JID("foo@bar.com/baz"), payload_, router_);
+ testling.onResponse.connect(boost::bind(&RequestTest::handleDifferentResponse, this, _1, _2));
+ testling.send();
+
+ responsePayload_ = std::make_shared<MyOtherPayload>();
+ channel_->onIQReceived(createResponse(JID("foo@bar.com/baz"),"test-id"));
+
+ CPPUNIT_ASSERT_EQUAL(1, responsesReceived_);
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(receivedErrors.size()));
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(channel_->iqs_.size()));
+ }
+
+ void testHandleIQ_RawXMLPayload() {
+ payload_ = std::make_shared<RawXMLPayload>("<bla/>");
+ MyRequest testling(IQ::Get, JID("foo@bar.com/baz"), payload_, router_);
+ testling.onResponse.connect(boost::bind(&RequestTest::handleRawXMLResponse, this, _1, _2));
+ testling.send();
+
+ responsePayload_ = std::make_shared<MyOtherPayload>();
+ channel_->onIQReceived(createResponse(JID("foo@bar.com/baz"),"test-id"));
+
+ CPPUNIT_ASSERT_EQUAL(1, responsesReceived_);
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(receivedErrors.size()));
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(channel_->iqs_.size()));
+ }
+
+ void testHandleIQ_GetWithSameID() {
+ MyRequest testling(IQ::Get, JID("foo@bar.com/baz"), payload_, router_);
+ testling.onResponse.connect(boost::bind(&RequestTest::handleResponse, this, _1, _2));
+ testling.send();
+
+ std::shared_ptr<IQ> response = createResponse(JID("foo@bar.com/baz"),"test-id");
+ response->setType(IQ::Get);
+ channel_->onIQReceived(response);
+
+ CPPUNIT_ASSERT_EQUAL(0, responsesReceived_);
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(receivedErrors.size()));
+ CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(channel_->iqs_.size()));
+ }
+
+ void testHandleIQ_SetWithSameID() {
+ MyRequest testling(IQ::Get, JID("foo@bar.com/baz"), payload_, router_);
+ testling.onResponse.connect(boost::bind(&RequestTest::handleResponse, this, _1, _2));
+ testling.send();
+
+ std::shared_ptr<IQ> response = createResponse(JID("foo@bar.com/baz"), "test-id");
+ response->setType(IQ::Set);
+ channel_->onIQReceived(response);
+
+ CPPUNIT_ASSERT_EQUAL(0, responsesReceived_);
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(receivedErrors.size()));
+ CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(channel_->iqs_.size()));
+ }
+
+ void testHandleIQ_IncorrectSender() {
+ MyRequest testling(IQ::Get, JID("foo@bar.com/baz"), payload_, router_);
+ router_->setJID("alice@wonderland.lit/TeaParty");
+ testling.onResponse.connect(boost::bind(&RequestTest::handleResponse, this, _1, _2));
+ testling.send();
+
+ channel_->onIQReceived(createResponse(JID("anotherfoo@bar.com/baz"), "test-id"));
+
+ CPPUNIT_ASSERT_EQUAL(0, responsesReceived_);
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(receivedErrors.size()));
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(channel_->iqs_.size()));
+ }
+
+ void testHandleIQ_IncorrectSenderForServerQuery() {
+ MyRequest testling(IQ::Get, JID(), payload_, router_);
+ router_->setJID("alice@wonderland.lit/TeaParty");
+ testling.onResponse.connect(boost::bind(&RequestTest::handleResponse, this, _1, _2));
+ testling.send();
+
+ channel_->onIQReceived(createResponse(JID("foo@bar.com/baz"), "test-id"));
+
+ CPPUNIT_ASSERT_EQUAL(0, responsesReceived_);
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(receivedErrors.size()));
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(channel_->iqs_.size()));
+ }
+
+ void testHandleIQ_IncorrectOtherResourceSenderForServerQuery() {
+ MyRequest testling(IQ::Get, JID(), payload_, router_);
+ router_->setJID("alice@wonderland.lit/TeaParty");
+ testling.onResponse.connect(boost::bind(&RequestTest::handleResponse, this, _1, _2));
+ testling.send();
+
+ channel_->onIQReceived(createResponse(JID("alice@wonderland.lit/RabbitHole"), "test-id"));
+
+ CPPUNIT_ASSERT_EQUAL(0, responsesReceived_);
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(receivedErrors.size()));
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(channel_->iqs_.size()));
+ }
+
+ void testHandleIQ_ServerRespondsWithDomain() {
+ MyRequest testling(IQ::Get, JID(), payload_, router_);
+ router_->setJID("alice@wonderland.lit/TeaParty");
+ testling.onResponse.connect(boost::bind(&RequestTest::handleResponse, this, _1, _2));
+ testling.send();
+
+ channel_->onIQReceived(createResponse(JID("wonderland.lit"),"test-id"));
+
+ CPPUNIT_ASSERT_EQUAL(0, responsesReceived_);
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(receivedErrors.size()));
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(channel_->iqs_.size()));
+ }
+
+ void testHandleIQ_ServerRespondsWithBareJID() {
+ MyRequest testling(IQ::Get, JID(), payload_, router_);
+ router_->setJID("alice@wonderland.lit/TeaParty");
+ testling.onResponse.connect(boost::bind(&RequestTest::handleResponse, this, _1, _2));
+ testling.send();
+
+ channel_->onIQReceived(createResponse(JID("alice@wonderland.lit"),"test-id"));
+
+ CPPUNIT_ASSERT_EQUAL(1, responsesReceived_);
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(receivedErrors.size()));
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(channel_->iqs_.size()));
+ }
+
+ // This tests a bug in ejabberd servers (2.0.5)
+ void testHandleIQ_ServerRespondsWithFullJID() {
+ MyRequest testling(IQ::Get, JID(), payload_, router_);
+ router_->setJID("alice@wonderland.lit/TeaParty");
+ testling.onResponse.connect(boost::bind(&RequestTest::handleResponse, this, _1, _2));
+ testling.send();
+
+ channel_->onIQReceived(createResponse(JID("alice@wonderland.lit/TeaParty"),"test-id"));
+
+ CPPUNIT_ASSERT_EQUAL(1, responsesReceived_);
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(receivedErrors.size()));
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(channel_->iqs_.size()));
+ }
+
+ void testHandleIQ_ServerRespondsWithoutFrom() {
+ MyRequest testling(IQ::Get, JID(), payload_, router_);
+ router_->setJID("alice@wonderland.lit/TeaParty");
+ testling.onResponse.connect(boost::bind(&RequestTest::handleResponse, this, _1, _2));
+ testling.send();
+
+ channel_->onIQReceived(createResponse(JID(),"test-id"));
+
+ CPPUNIT_ASSERT_EQUAL(1, responsesReceived_);
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(receivedErrors.size()));
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(channel_->iqs_.size()));
+ }
+
+
+
+ private:
+ void handleResponse(std::shared_ptr<Payload> p, ErrorPayload::ref e) {
+ if (e) {
+ receivedErrors.push_back(*e);
+ }
+ else {
+ std::shared_ptr<MyPayload> payload(std::dynamic_pointer_cast<MyPayload>(p));
+ CPPUNIT_ASSERT(payload);
+ CPPUNIT_ASSERT_EQUAL(std::string("bar"), payload->text_);
+ ++responsesReceived_;
+ }
+ }
+
+ void handleDifferentResponse(std::shared_ptr<Payload> p, ErrorPayload::ref e) {
+ CPPUNIT_ASSERT(!e);
+ CPPUNIT_ASSERT(!p);
+ ++responsesReceived_;
+ }
+
+ void handleRawXMLResponse(std::shared_ptr<Payload> p, ErrorPayload::ref e) {
+ CPPUNIT_ASSERT(!e);
+ CPPUNIT_ASSERT(p);
+ CPPUNIT_ASSERT(std::dynamic_pointer_cast<MyOtherPayload>(p));
+ ++responsesReceived_;
+ }
+
+ std::shared_ptr<IQ> createResponse(const JID& from, const std::string& id) {
+ std::shared_ptr<IQ> iq(new IQ(IQ::Result));
+ iq->setFrom(from);
+ iq->addPayload(responsePayload_);
+ iq->setID(id);
+ return iq;
+ }
+
+ std::shared_ptr<IQ> createError(const JID& from, const std::string& id) {
+ std::shared_ptr<IQ> iq(new IQ(IQ::Error));
+ iq->setFrom(from);
+ iq->setID(id);
+ return iq;
+ }
+
+ private:
+ IQRouter* router_;
+ DummyIQChannel* channel_;
+ std::shared_ptr<Payload> payload_;
+ std::shared_ptr<Payload> responsePayload_;
+ int responsesReceived_;
+ std::vector<ErrorPayload> receivedErrors;
};
CPPUNIT_TEST_SUITE_REGISTRATION(RequestTest);
diff --git a/Swiften/Queries/UnitTest/ResponderTest.cpp b/Swiften/Queries/UnitTest/ResponderTest.cpp
index 4664eb9..94bfed1 100644
--- a/Swiften/Queries/UnitTest/ResponderTest.cpp
+++ b/Swiften/Queries/UnitTest/ResponderTest.cpp
@@ -1,157 +1,157 @@
/*
- * Copyright (c) 2010 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
+#include <memory>
+
+#include <boost/bind.hpp>
+
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
-#include <boost/shared_ptr.hpp>
-#include <boost/smart_ptr/make_shared.hpp>
-#include <boost/bind.hpp>
-#include <Swiften/Queries/Responder.h>
-#include <Swiften/Queries/IQRouter.h>
-#include <Swiften/Queries/DummyIQChannel.h>
#include <Swiften/Elements/SoftwareVersion.h>
+#include <Swiften/Queries/DummyIQChannel.h>
+#include <Swiften/Queries/IQRouter.h>
+#include <Swiften/Queries/Responder.h>
using namespace Swift;
class ResponderTest : public CppUnit::TestFixture {
- CPPUNIT_TEST_SUITE(ResponderTest);
- CPPUNIT_TEST(testConstructor);
- CPPUNIT_TEST(testStart);
- CPPUNIT_TEST(testStop);
- CPPUNIT_TEST(testHandleIQ_Set);
- CPPUNIT_TEST(testHandleIQ_Get);
- CPPUNIT_TEST(testHandleIQ_Error);
- CPPUNIT_TEST(testHandleIQ_Result);
- CPPUNIT_TEST(testHandleIQ_NoPayload);
- CPPUNIT_TEST_SUITE_END();
+ CPPUNIT_TEST_SUITE(ResponderTest);
+ CPPUNIT_TEST(testConstructor);
+ CPPUNIT_TEST(testStart);
+ CPPUNIT_TEST(testStop);
+ CPPUNIT_TEST(testHandleIQ_Set);
+ CPPUNIT_TEST(testHandleIQ_Get);
+ CPPUNIT_TEST(testHandleIQ_Error);
+ CPPUNIT_TEST(testHandleIQ_Result);
+ CPPUNIT_TEST(testHandleIQ_NoPayload);
+ CPPUNIT_TEST_SUITE_END();
- public:
- void setUp() {
- channel_ = new DummyIQChannel();
- router_ = new IQRouter(channel_);
- payload_ = boost::make_shared<SoftwareVersion>("foo");
- }
+ public:
+ void setUp() {
+ channel_ = std::unique_ptr<DummyIQChannel>(new DummyIQChannel());
+ router_ = std::unique_ptr<IQRouter>(new IQRouter(channel_.get()));
+ payload_ = std::make_shared<SoftwareVersion>("foo");
+ }
- void tearDown() {
- delete router_;
- delete channel_;
- }
-
- void testConstructor() {
- MyResponder testling(router_);
-
- channel_->onIQReceived(createRequest(IQ::Set));
-
- CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(testling.setPayloads_.size()));
- }
-
- void testStart() {
- MyResponder testling(router_);
-
- testling.start();
- channel_->onIQReceived(createRequest(IQ::Set));
-
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(testling.setPayloads_.size()));
- }
-
- void testStop() {
- MyResponder testling(router_);
-
- testling.start();
- testling.stop();
- channel_->onIQReceived(createRequest(IQ::Set));
-
- CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(testling.setPayloads_.size()));
- }
-
- void testHandleIQ_Set() {
- MyResponder testling(router_);
-
- CPPUNIT_ASSERT(dynamic_cast<IQHandler*>(&testling)->handleIQ(createRequest(IQ::Set)));
-
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(testling.setPayloads_.size()));
- CPPUNIT_ASSERT(payload_ == testling.setPayloads_[0]);
- CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(testling.getPayloads_.size()));
- }
-
- void testHandleIQ_Get() {
- MyResponder testling(router_);
-
- CPPUNIT_ASSERT(dynamic_cast<IQHandler*>(&testling)->handleIQ(createRequest(IQ::Get)));
-
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(testling.getPayloads_.size()));
- CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(testling.setPayloads_.size()));
- CPPUNIT_ASSERT(payload_ == testling.getPayloads_[0]);
- }
-
- void testHandleIQ_Error() {
- MyResponder testling(router_);
-
- CPPUNIT_ASSERT(!dynamic_cast<IQHandler*>(&testling)->handleIQ(createRequest(IQ::Error)));
-
- CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(testling.getPayloads_.size()));
- CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(testling.setPayloads_.size()));
- }
-
- void testHandleIQ_Result() {
- MyResponder testling(router_);
-
- CPPUNIT_ASSERT(!dynamic_cast<IQHandler*>(&testling)->handleIQ(createRequest(IQ::Result)));
-
- CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(testling.getPayloads_.size()));
- CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(testling.setPayloads_.size()));
- }
-
- void testHandleIQ_NoPayload() {
- MyResponder testling(router_);
-
- CPPUNIT_ASSERT(!dynamic_cast<IQHandler*>(&testling)->handleIQ(boost::make_shared<IQ>(IQ::Get)));
-
- CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(testling.getPayloads_.size()));
- CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(testling.setPayloads_.size()));
- }
-
- private:
- boost::shared_ptr<IQ> createRequest(IQ::Type type) {
- boost::shared_ptr<IQ> iq(new IQ(type));
- iq->addPayload(payload_);
- iq->setID("myid");
- iq->setFrom(JID("foo@bar.com/baz"));
- return iq;
- }
-
- private:
- class MyResponder : public Responder<SoftwareVersion> {
- public:
- MyResponder(IQRouter* router) : Responder<SoftwareVersion>(router), getRequestResponse_(true), setRequestResponse_(true) {}
+ void tearDown() {
+ router_.reset();
+ }
+
+ void testConstructor() {
+ MyResponder testling(router_.get());
+
+ channel_->onIQReceived(createRequest(IQ::Set));
+
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(testling.setPayloads_.size()));
+ }
+
+ void testStart() {
+ MyResponder testling(router_.get());
+
+ testling.start();
+ channel_->onIQReceived(createRequest(IQ::Set));
+
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(testling.setPayloads_.size()));
+ }
+
+ void testStop() {
+ MyResponder testling(router_.get());
+
+ testling.start();
+ testling.stop();
+ channel_->onIQReceived(createRequest(IQ::Set));
+
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(testling.setPayloads_.size()));
+ }
+
+ void testHandleIQ_Set() {
+ MyResponder testling(router_.get());
+
+ CPPUNIT_ASSERT(dynamic_cast<IQHandler*>(&testling)->handleIQ(createRequest(IQ::Set)));
+
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(testling.setPayloads_.size()));
+ CPPUNIT_ASSERT(payload_ == testling.setPayloads_[0]);
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(testling.getPayloads_.size()));
+ }
+
+ void testHandleIQ_Get() {
+ MyResponder testling(router_.get());
+
+ CPPUNIT_ASSERT(dynamic_cast<IQHandler*>(&testling)->handleIQ(createRequest(IQ::Get)));
+
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(testling.getPayloads_.size()));
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(testling.setPayloads_.size()));
+ CPPUNIT_ASSERT(payload_ == testling.getPayloads_[0]);
+ }
+
+ void testHandleIQ_Error() {
+ MyResponder testling(router_.get());
+
+ CPPUNIT_ASSERT(!dynamic_cast<IQHandler*>(&testling)->handleIQ(createRequest(IQ::Error)));
+
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(testling.getPayloads_.size()));
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(testling.setPayloads_.size()));
+ }
+
+ void testHandleIQ_Result() {
+ MyResponder testling(router_.get());
+
+ CPPUNIT_ASSERT(!dynamic_cast<IQHandler*>(&testling)->handleIQ(createRequest(IQ::Result)));
+
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(testling.getPayloads_.size()));
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(testling.setPayloads_.size()));
+ }
+
+ void testHandleIQ_NoPayload() {
+ MyResponder testling(router_.get());
+
+ CPPUNIT_ASSERT(!dynamic_cast<IQHandler*>(&testling)->handleIQ(std::make_shared<IQ>(IQ::Get)));
+
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(testling.getPayloads_.size()));
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(testling.setPayloads_.size()));
+ }
+
+ private:
+ std::shared_ptr<IQ> createRequest(IQ::Type type) {
+ std::shared_ptr<IQ> iq(new IQ(type));
+ iq->addPayload(payload_);
+ iq->setID("myid");
+ iq->setFrom(JID("foo@bar.com/baz"));
+ return iq;
+ }
+
+ private:
+ class MyResponder : public Responder<SoftwareVersion> {
+ public:
+ MyResponder(IQRouter* router) : Responder<SoftwareVersion>(router), getRequestResponse_(true), setRequestResponse_(true) {}
- virtual bool handleGetRequest(const JID& from, const JID&, const std::string& id, boost::shared_ptr<SoftwareVersion> payload) {
- CPPUNIT_ASSERT_EQUAL(JID("foo@bar.com/baz"), from);
- CPPUNIT_ASSERT_EQUAL(std::string("myid"), id);
- getPayloads_.push_back(payload);
- return getRequestResponse_;
- }
- virtual bool handleSetRequest(const JID& from, const JID&, const std::string& id, boost::shared_ptr<SoftwareVersion> payload) {
- CPPUNIT_ASSERT_EQUAL(JID("foo@bar.com/baz"), from);
- CPPUNIT_ASSERT_EQUAL(std::string("myid"), id);
- setPayloads_.push_back(payload);
- return setRequestResponse_;
- }
+ virtual bool handleGetRequest(const JID& from, const JID&, const std::string& id, std::shared_ptr<SoftwareVersion> payload) {
+ CPPUNIT_ASSERT_EQUAL(JID("foo@bar.com/baz"), from);
+ CPPUNIT_ASSERT_EQUAL(std::string("myid"), id);
+ getPayloads_.push_back(payload);
+ return getRequestResponse_;
+ }
+ virtual bool handleSetRequest(const JID& from, const JID&, const std::string& id, std::shared_ptr<SoftwareVersion> payload) {
+ CPPUNIT_ASSERT_EQUAL(JID("foo@bar.com/baz"), from);
+ CPPUNIT_ASSERT_EQUAL(std::string("myid"), id);
+ setPayloads_.push_back(payload);
+ return setRequestResponse_;
+ }
- bool getRequestResponse_;
- bool setRequestResponse_;
- std::vector<boost::shared_ptr<SoftwareVersion> > getPayloads_;
- std::vector<boost::shared_ptr<SoftwareVersion> > setPayloads_;
- };
+ bool getRequestResponse_;
+ bool setRequestResponse_;
+ std::vector<std::shared_ptr<SoftwareVersion> > getPayloads_;
+ std::vector<std::shared_ptr<SoftwareVersion> > setPayloads_;
+ };
- private:
- IQRouter* router_;
- DummyIQChannel* channel_;
- boost::shared_ptr<SoftwareVersion> payload_;
+ private:
+ std::unique_ptr<IQRouter> router_;
+ std::unique_ptr<DummyIQChannel> channel_;
+ std::shared_ptr<SoftwareVersion> payload_;
};
CPPUNIT_TEST_SUITE_REGISTRATION(ResponderTest);