From f1d74218cb432513c376b46aa115acb3e107ed3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Remko=20Tron=C3=A7on?= Date: Sun, 8 Nov 2009 17:12:48 +0100 Subject: Added Error class. diff --git a/Limber/main.cpp b/Limber/main.cpp index 965abc2..25cccec 100644 --- a/Limber/main.cpp +++ b/Limber/main.cpp @@ -63,11 +63,11 @@ class Server { session->sendElement(IQ::createResult(iq->getFrom(), iq->getID(), vcard)); } else { - session->sendElement(IQ::createError(iq->getFrom(), iq->getID(), Error::Forbidden, Error::Cancel)); + session->sendElement(IQ::createError(iq->getFrom(), iq->getID(), ErrorPayload::Forbidden, ErrorPayload::Cancel)); } } else { - session->sendElement(IQ::createError(iq->getFrom(), iq->getID(), Error::FeatureNotImplemented, Error::Cancel)); + session->sendElement(IQ::createError(iq->getFrom(), iq->getID(), ErrorPayload::FeatureNotImplemented, ErrorPayload::Cancel)); } } } diff --git a/Slimber/Server.cpp b/Slimber/Server.cpp index e07fb41..278a572 100644 --- a/Slimber/Server.cpp +++ b/Slimber/Server.cpp @@ -211,7 +211,7 @@ void Server::handleElementReceived(boost::shared_ptr element, boost::sh } } else { - session->sendElement(IQ::createError(iq->getFrom(), iq->getID(), Error::Forbidden, Error::Cancel)); + session->sendElement(IQ::createError(iq->getFrom(), iq->getID(), ErrorPayload::Forbidden, ErrorPayload::Cancel)); } } if (boost::shared_ptr vcard = iq->getPayload()) { @@ -227,7 +227,7 @@ void Server::handleElementReceived(boost::shared_ptr element, boost::sh } } else { - session->sendElement(IQ::createError(iq->getFrom(), iq->getID(), Error::FeatureNotImplemented, Error::Cancel)); + session->sendElement(IQ::createError(iq->getFrom(), iq->getID(), ErrorPayload::FeatureNotImplemented, ErrorPayload::Cancel)); } } } @@ -260,7 +260,7 @@ void Server::handleElementReceived(boost::shared_ptr element, boost::sh else { session->sendElement(IQ::createError( stanza->getFrom(), stanza->getID(), - Error::RecipientUnavailable, Error::Wait)); + ErrorPayload::RecipientUnavailable, ErrorPayload::Wait)); } } } diff --git a/Swift/Controllers/ChatControllerBase.cpp b/Swift/Controllers/ChatControllerBase.cpp index baa715b..2b873f1 100644 --- a/Swift/Controllers/ChatControllerBase.cpp +++ b/Swift/Controllers/ChatControllerBase.cpp @@ -67,7 +67,7 @@ void ChatControllerBase::handleSendMessageRequest(const String &body) { postSendMessage(message->getBody()); } -void ChatControllerBase::handleSecurityLabelsCatalogResponse(boost::shared_ptr catalog, const boost::optional& error) { +void ChatControllerBase::handleSecurityLabelsCatalogResponse(boost::shared_ptr catalog, const boost::optional& error) { if (!error) { if (catalog->getLabels().size() == 0) { chatWindow_->setSecurityLabelsEnabled(false); @@ -97,7 +97,7 @@ void ChatControllerBase::handleIncomingMessage(boost::shared_ptr m preHandleIncomingMessage(message); String body = message->getBody(); if (message->isError()) { - String errorMessage = getErrorMessage(message->getPayload()); + String errorMessage = getErrorMessage(message->getPayload()); chatWindow_->addErrorMessage(errorMessage); } else { @@ -109,35 +109,35 @@ void ChatControllerBase::handleIncomingMessage(boost::shared_ptr m } } -String ChatControllerBase::getErrorMessage(boost::shared_ptr error) { +String ChatControllerBase::getErrorMessage(boost::shared_ptr error) { String defaultMessage = "Error sending message"; if (!error->getText().isEmpty()) { return error->getText(); } else { switch (error->getCondition()) { - case Error::BadRequest: return defaultMessage; break; - case Error::Conflict: return defaultMessage; break; - case Error::FeatureNotImplemented: return defaultMessage; break; - case Error::Forbidden: return defaultMessage; break; - case Error::Gone: return "Recipient can no longer be contacted"; break; - case Error::InternalServerError: return "Internal server error"; break; - case Error::ItemNotFound: return defaultMessage; break; - case Error::JIDMalformed: return defaultMessage; break; - case Error::NotAcceptable: return "Message was rejected"; break; - case Error::NotAllowed: return defaultMessage; break; - case Error::NotAuthorized: return defaultMessage; break; - case Error::PaymentRequired: return defaultMessage; break; - case Error::RecipientUnavailable: return "Recipient is unavailable."; break; - case Error::Redirect: return defaultMessage; break; - case Error::RegistrationRequired: return defaultMessage; break; - case Error::RemoteServerNotFound: return "Recipient's server not found."; break; - case Error::RemoteServerTimeout: return defaultMessage; break; - case Error::ResourceConstraint: return defaultMessage; break; - case Error::ServiceUnavailable: return defaultMessage; break; - case Error::SubscriptionRequired: return defaultMessage; break; - case Error::UndefinedCondition: return defaultMessage; break; - case Error::UnexpectedRequest: return defaultMessage; break; + case ErrorPayload::BadRequest: return defaultMessage; break; + case ErrorPayload::Conflict: return defaultMessage; break; + case ErrorPayload::FeatureNotImplemented: return defaultMessage; break; + case ErrorPayload::Forbidden: return defaultMessage; break; + case ErrorPayload::Gone: return "Recipient can no longer be contacted"; break; + case ErrorPayload::InternalServerError: return "Internal server error"; break; + case ErrorPayload::ItemNotFound: return defaultMessage; break; + case ErrorPayload::JIDMalformed: return defaultMessage; break; + case ErrorPayload::NotAcceptable: return "Message was rejected"; break; + case ErrorPayload::NotAllowed: return defaultMessage; break; + case ErrorPayload::NotAuthorized: return defaultMessage; break; + case ErrorPayload::PaymentRequired: return defaultMessage; break; + case ErrorPayload::RecipientUnavailable: return "Recipient is unavailable."; break; + case ErrorPayload::Redirect: return defaultMessage; break; + case ErrorPayload::RegistrationRequired: return defaultMessage; break; + case ErrorPayload::RemoteServerNotFound: return "Recipient's server not found."; break; + case ErrorPayload::RemoteServerTimeout: return defaultMessage; break; + case ErrorPayload::ResourceConstraint: return defaultMessage; break; + case ErrorPayload::ServiceUnavailable: return defaultMessage; break; + case ErrorPayload::SubscriptionRequired: return defaultMessage; break; + case ErrorPayload::UndefinedCondition: return defaultMessage; break; + case ErrorPayload::UnexpectedRequest: return defaultMessage; break; } } return defaultMessage; diff --git a/Swift/Controllers/ChatControllerBase.h b/Swift/Controllers/ChatControllerBase.h index 601e56b..91b72a8 100644 --- a/Swift/Controllers/ChatControllerBase.h +++ b/Swift/Controllers/ChatControllerBase.h @@ -12,7 +12,7 @@ #include "Swiften/Events/MessageEvent.h" #include "Swiften/JID/JID.h" #include "Swiften/Elements/SecurityLabelsCatalog.h" -#include "Swiften/Elements/Error.h" +#include "Swiften/Elements/ErrorPayload.h" #include "Swiften/Presence/PresenceOracle.h" #include "Swiften/Queries/IQRouter.h" @@ -44,8 +44,8 @@ namespace Swift { private: void handleSendMessageRequest(const String &body); void handleAllMessagesRead(); - void handleSecurityLabelsCatalogResponse(boost::shared_ptr, const boost::optional& error); - String getErrorMessage(boost::shared_ptr); + void handleSecurityLabelsCatalogResponse(boost::shared_ptr, const boost::optional& error); + String getErrorMessage(boost::shared_ptr); protected: JID selfJID_; diff --git a/Swift/Controllers/MainController.cpp b/Swift/Controllers/MainController.cpp index 15947b6..6b3b002 100644 --- a/Swift/Controllers/MainController.cpp +++ b/Swift/Controllers/MainController.cpp @@ -387,7 +387,7 @@ void MainController::handleIncomingMessage(boost::shared_ptr message) { } } -void MainController::handleServerDiscoInfoResponse(boost::shared_ptr info, const boost::optional& error) { +void MainController::handleServerDiscoInfoResponse(boost::shared_ptr info, const boost::optional& error) { if (!error) { serverDiscoInfo_ = info; foreach (JIDChatControllerPair pair, chatControllers_) { @@ -403,7 +403,7 @@ bool MainController::isMUC(const JID& jid) const { return mucControllers_.find(jid.toBare()) != mucControllers_.end(); } -void MainController::handleOwnVCardReceived(boost::shared_ptr vCard, const boost::optional& error) { +void MainController::handleOwnVCardReceived(boost::shared_ptr vCard, const boost::optional& error) { if (!error && !vCard->getPhoto().isEmpty()) { vCardPhotoHash_ = SHA1::getHexHash(vCard->getPhoto()); if (lastSentPresence_) { diff --git a/Swift/Controllers/MainController.h b/Swift/Controllers/MainController.h index 3179df9..db6a110 100644 --- a/Swift/Controllers/MainController.h +++ b/Swift/Controllers/MainController.h @@ -10,7 +10,7 @@ #include "Swiften/JID/JID.h" #include "Swiften/Elements/VCard.h" #include "Swiften/Elements/DiscoInfo.h" -#include "Swiften/Elements/Error.h" +#include "Swiften/Elements/ErrorPayload.h" #include "Swiften/Elements/Presence.h" #include "Swiften/Elements/Message.h" #include "Swiften/Settings/SettingsProvider.h" @@ -64,9 +64,9 @@ namespace Swift { void handleIncomingMessage(boost::shared_ptr message); void handleChangeStatusRequest(StatusShow::Type show, const String &statusText); void handleError(const ClientError& error); - void handleServerDiscoInfoResponse(boost::shared_ptr, const boost::optional&); + void handleServerDiscoInfoResponse(boost::shared_ptr, const boost::optional&); void handleEventQueueLengthChange(int count); - void handleOwnVCardReceived(boost::shared_ptr vCard, const boost::optional& error); + void handleOwnVCardReceived(boost::shared_ptr vCard, const boost::optional& error); ChatController* getChatController(const JID &contact); void sendPresence(boost::shared_ptr presence); void handleInputIdle(); diff --git a/Swiften/Avatars/AvatarManager.cpp b/Swiften/Avatars/AvatarManager.cpp index 6a1efc6..574e199 100644 --- a/Swiften/Avatars/AvatarManager.cpp +++ b/Swiften/Avatars/AvatarManager.cpp @@ -35,7 +35,7 @@ void AvatarManager::handlePresenceReceived(boost::shared_ptr presence) } } -void AvatarManager::handleVCardReceived(const JID& from, const String& promisedHash, boost::shared_ptr vCard, const boost::optional& error) { +void AvatarManager::handleVCardReceived(const JID& from, const String& promisedHash, boost::shared_ptr vCard, const boost::optional& error) { if (error) { // FIXME: What to do here? std::cerr << "Warning: " << from << ": Could not get vCard" << std::endl; diff --git a/Swiften/Avatars/AvatarManager.h b/Swiften/Avatars/AvatarManager.h index 3ac4433..65ec372 100644 --- a/Swiften/Avatars/AvatarManager.h +++ b/Swiften/Avatars/AvatarManager.h @@ -9,7 +9,7 @@ #include "Swiften/JID/JID.h" #include "Swiften/Elements/Presence.h" #include "Swiften/Elements/VCard.h" -#include "Swiften/Elements/Error.h" +#include "Swiften/Elements/ErrorPayload.h" namespace Swift { class MUCRegistry; @@ -30,7 +30,7 @@ namespace Swift { private: void handlePresenceReceived(boost::shared_ptr); - void handleVCardReceived(const JID& from, const String& hash, boost::shared_ptr, const boost::optional&); + void handleVCardReceived(const JID& from, const String& hash, boost::shared_ptr, const boost::optional&); void setAvatarHash(const JID& from, const String& hash); JID getAvatarJID(const JID& o) const; diff --git a/Swiften/Base/Error.cpp b/Swiften/Base/Error.cpp new file mode 100644 index 0000000..597c155 --- /dev/null +++ b/Swiften/Base/Error.cpp @@ -0,0 +1,8 @@ +#include "Swiften/Base/Error.h" + +namespace Swift { + +Error::~Error() { +} + +} diff --git a/Swiften/Base/Error.h b/Swiften/Base/Error.h new file mode 100644 index 0000000..4c729ff --- /dev/null +++ b/Swiften/Base/Error.h @@ -0,0 +1,8 @@ +#pragma once + +namespace Swift { + class Error { + public: + virtual ~Error(); + }; +}; diff --git a/Swiften/Base/SConscript b/Swiften/Base/SConscript index d308e11..a0984e5 100644 --- a/Swiften/Base/SConscript +++ b/Swiften/Base/SConscript @@ -2,6 +2,7 @@ Import("swiften_env") objects = swiften_env.StaticObject([ "ByteArray.cpp", + "Error.cpp", "IDGenerator.cpp", "String.cpp", "sleep.cpp", diff --git a/Swiften/Client/Client.cpp b/Swiften/Client/Client.cpp index 60dfade..b3bea0d 100644 --- a/Swiften/Client/Client.cpp +++ b/Swiften/Client/Client.cpp @@ -10,6 +10,7 @@ #include "Swiften/Network/BoostConnectionFactory.h" #include "Swiften/Network/DomainNameResolveException.h" #include "Swiften/TLS/PKCS12Certificate.h" +#include "Swiften/Session/BasicSessionStream.h" namespace Swift { @@ -46,6 +47,10 @@ void Client::handleConnectionConnectFinished(bool error) { onError(ClientError::ConnectionError); } else { + assert(!sessionStream_); + sessionStream_ = boost::shared_ptr(new BasicSessionStream(connection_, &payloadParserFactories_, &payloadSerializers_, tlsLayerFactory_)); + sessionStream_->initialize(); + session_ = boost::shared_ptr(new ClientSession(jid_, connection_, tlsLayerFactory_, &payloadParserFactories_, &payloadSerializers_)); if (!certificate_.isEmpty()) { session_->setCertificate(PKCS12Certificate(certificate_, password_)); diff --git a/Swiften/Client/Client.h b/Swiften/Client/Client.h index 59e1c05..0e68f55 100644 --- a/Swiften/Client/Client.h +++ b/Swiften/Client/Client.h @@ -20,6 +20,7 @@ namespace Swift { class TLSLayerFactory; class ConnectionFactory; class ClientSession; + class BasicSessionStream; class Client : public StanzaChannel, public IQRouter, public boost::bsignals::trackable { public: @@ -53,6 +54,8 @@ namespace Swift { void handleDataRead(const ByteArray&); void handleDataWritten(const ByteArray&); + void reset(); + private: JID jid_; String password_; @@ -61,8 +64,9 @@ namespace Swift { TLSLayerFactory* tlsLayerFactory_; FullPayloadParserFactoryCollection payloadParserFactories_; FullPayloadSerializerCollection payloadSerializers_; - boost::shared_ptr session_; boost::shared_ptr connection_; + boost::shared_ptr sessionStream_; + boost::shared_ptr session_; String certificate_; }; } diff --git a/Swiften/Client/UnitTest/ClientSessionTest.cpp b/Swiften/Client/UnitTest/ClientSessionTest.cpp index cbf20d2..70d4ba9 100644 --- a/Swiften/Client/UnitTest/ClientSessionTest.cpp +++ b/Swiften/Client/UnitTest/ClientSessionTest.cpp @@ -14,7 +14,7 @@ #include "Swiften/Elements/ProtocolHeader.h" #include "Swiften/Elements/StreamFeatures.h" #include "Swiften/Elements/Element.h" -#include "Swiften/Elements/Error.h" +#include "Swiften/Elements/ErrorPayload.h" #include "Swiften/Elements/IQ.h" #include "Swiften/Elements/AuthRequest.h" #include "Swiften/Elements/AuthSuccess.h" diff --git a/Swiften/Elements/Error.h b/Swiften/Elements/Error.h deleted file mode 100644 index 8793f35..0000000 --- a/Swiften/Elements/Error.h +++ /dev/null @@ -1,70 +0,0 @@ -#ifndef SWIFTEN_Error_H -#define SWIFTEN_Error_H - -#include "Swiften/Elements/Payload.h" -#include "Swiften/Base/String.h" - -namespace Swift { - class Error : public Payload { - public: - enum Type { Cancel, Continue, Modify, Auth, Wait }; - - enum Condition { - BadRequest, - Conflict, - FeatureNotImplemented, - Forbidden, - Gone, - InternalServerError, - ItemNotFound, - JIDMalformed, - NotAcceptable, - NotAllowed, - NotAuthorized, - PaymentRequired, - RecipientUnavailable, - Redirect, - RegistrationRequired, - RemoteServerNotFound, - RemoteServerTimeout, - ResourceConstraint, - ServiceUnavailable, - SubscriptionRequired, - UndefinedCondition, - UnexpectedRequest - }; - - Error(Condition condition = UndefinedCondition, Type type = Cancel, const String& text = String()) : type_(type), condition_(condition), text_(text) { } - - Type getType() const { - return type_; - } - - void setType(Type type) { - type_ = type; - } - - Condition getCondition() const { - return condition_; - } - - void setCondition(Condition condition) { - condition_ = condition; - } - - void setText(const String& text) { - text_ = text; - } - - const String& getText() const { - return text_; - } - - private: - Type type_; - Condition condition_; - String text_; - }; -} - -#endif diff --git a/Swiften/Elements/ErrorPayload.h b/Swiften/Elements/ErrorPayload.h new file mode 100644 index 0000000..32fd067 --- /dev/null +++ b/Swiften/Elements/ErrorPayload.h @@ -0,0 +1,67 @@ +#pragma once + +#include "Swiften/Elements/Payload.h" +#include "Swiften/Base/String.h" + +namespace Swift { + class ErrorPayload : public Payload { + public: + enum Type { Cancel, Continue, Modify, Auth, Wait }; + + enum Condition { + BadRequest, + Conflict, + FeatureNotImplemented, + Forbidden, + Gone, + InternalServerError, + ItemNotFound, + JIDMalformed, + NotAcceptable, + NotAllowed, + NotAuthorized, + PaymentRequired, + RecipientUnavailable, + Redirect, + RegistrationRequired, + RemoteServerNotFound, + RemoteServerTimeout, + ResourceConstraint, + ServiceUnavailable, + SubscriptionRequired, + UndefinedCondition, + UnexpectedRequest + }; + + ErrorPayload(Condition condition = UndefinedCondition, Type type = Cancel, const String& text = String()) : type_(type), condition_(condition), text_(text) { } + + Type getType() const { + return type_; + } + + void setType(Type type) { + type_ = type; + } + + Condition getCondition() const { + return condition_; + } + + void setCondition(Condition condition) { + condition_ = condition; + } + + void setText(const String& text) { + text_ = text; + } + + const String& getText() const { + return text_; + } + + private: + Type type_; + Condition condition_; + String text_; + }; +} diff --git a/Swiften/Elements/IQ.cpp b/Swiften/Elements/IQ.cpp index 3f47182..53dec53 100644 --- a/Swiften/Elements/IQ.cpp +++ b/Swiften/Elements/IQ.cpp @@ -26,11 +26,11 @@ boost::shared_ptr IQ::createResult( return iq; } -boost::shared_ptr IQ::createError(const JID& to, const String& id, Error::Condition condition, Error::Type type) { +boost::shared_ptr IQ::createError(const JID& to, const String& id, ErrorPayload::Condition condition, ErrorPayload::Type type) { boost::shared_ptr iq(new IQ(IQ::Error)); iq->setTo(to); iq->setID(id); - iq->addPayload(boost::shared_ptr(new Swift::Error(condition, type))); + iq->addPayload(boost::shared_ptr(new Swift::ErrorPayload(condition, type))); return iq; } diff --git a/Swiften/Elements/IQ.h b/Swiften/Elements/IQ.h index 231439f..80c2913 100644 --- a/Swiften/Elements/IQ.h +++ b/Swiften/Elements/IQ.h @@ -1,8 +1,7 @@ -#ifndef SWIFTEN_IQ_H -#define SWIFTEN_IQ_H +#pragma once #include "Swiften/Elements/Stanza.h" -#include "Swiften/Elements/Error.h" +#include "Swiften/Elements/ErrorPayload.h" namespace Swift { @@ -28,12 +27,10 @@ namespace Swift static boost::shared_ptr createError( const JID& to, const String& id, - Error::Condition condition, - Error::Type type); + ErrorPayload::Condition condition, + ErrorPayload::Type type); private: Type type_; }; } - -#endif diff --git a/Swiften/Elements/Message.h b/Swiften/Elements/Message.h index a49f496..6d9171f 100644 --- a/Swiften/Elements/Message.h +++ b/Swiften/Elements/Message.h @@ -1,11 +1,10 @@ -#ifndef SWIFTEN_STANZAS_MESSAGE_H -#define SWIFTEN_STANZAS_MESSAGE_H +#pragma once #include #include "Swiften/Base/String.h" #include "Swiften/Elements/Body.h" -#include "Swiften/Elements/Error.h" +#include "Swiften/Elements/ErrorPayload.h" #include "Swiften/Elements/Stanza.h" namespace Swift @@ -30,8 +29,8 @@ namespace Swift } bool isError() { - boost::shared_ptr error(getPayload()); - return getType() == Message::Error || error.get() != NULL; + boost::shared_ptr error(getPayload()); + return getType() == Message::Error || error; } Type getType() const { return type_; } @@ -42,5 +41,3 @@ namespace Swift Type type_; }; } - -#endif diff --git a/Swiften/Elements/UnitTest/IQTest.cpp b/Swiften/Elements/UnitTest/IQTest.cpp index bc22c81..a5e6dc8 100644 --- a/Swiften/Elements/UnitTest/IQTest.cpp +++ b/Swiften/Elements/UnitTest/IQTest.cpp @@ -37,14 +37,14 @@ class IQTest : public CppUnit::TestFixture } void testCreateError() { - boost::shared_ptr iq(IQ::createError(JID("foo@bar/fum"), "myid", Error::BadRequest, Error::Modify)); + boost::shared_ptr iq(IQ::createError(JID("foo@bar/fum"), "myid", ErrorPayload::BadRequest, ErrorPayload::Modify)); CPPUNIT_ASSERT_EQUAL(JID("foo@bar/fum"), iq->getTo()); CPPUNIT_ASSERT_EQUAL(String("myid"), iq->getID()); - boost::shared_ptr error(iq->getPayload()); + boost::shared_ptr error(iq->getPayload()); CPPUNIT_ASSERT(error); - CPPUNIT_ASSERT_EQUAL(Error::BadRequest, error->getCondition()); - CPPUNIT_ASSERT_EQUAL(Error::Modify, error->getType()); + CPPUNIT_ASSERT_EQUAL(ErrorPayload::BadRequest, error->getCondition()); + CPPUNIT_ASSERT_EQUAL(ErrorPayload::Modify, error->getType()); } }; diff --git a/Swiften/Parser/PayloadParsers/ErrorParser.cpp b/Swiften/Parser/PayloadParsers/ErrorParser.cpp index 13380c8..ae85265 100644 --- a/Swiften/Parser/PayloadParsers/ErrorParser.cpp +++ b/Swiften/Parser/PayloadParsers/ErrorParser.cpp @@ -9,19 +9,19 @@ void ErrorParser::handleStartElement(const String&, const String&, const Attribu if (level_ == TopLevel) { String type = attributes.getAttribute("type"); if (type == "continue") { - getPayloadInternal()->setType(Error::Continue); + getPayloadInternal()->setType(ErrorPayload::Continue); } else if (type == "modify") { - getPayloadInternal()->setType(Error::Modify); + getPayloadInternal()->setType(ErrorPayload::Modify); } else if (type == "auth") { - getPayloadInternal()->setType(Error::Auth); + getPayloadInternal()->setType(ErrorPayload::Auth); } else if (type == "wait") { - getPayloadInternal()->setType(Error::Wait); + getPayloadInternal()->setType(ErrorPayload::Wait); } else { - getPayloadInternal()->setType(Error::Cancel); + getPayloadInternal()->setType(ErrorPayload::Cancel); } } ++level_; @@ -34,70 +34,70 @@ void ErrorParser::handleEndElement(const String& element, const String&) { getPayloadInternal()->setText(currentText_); } else if (element == "bad-request") { - getPayloadInternal()->setCondition(Error::BadRequest); + getPayloadInternal()->setCondition(ErrorPayload::BadRequest); } else if (element == "conflict") { - getPayloadInternal()->setCondition(Error::Conflict); + getPayloadInternal()->setCondition(ErrorPayload::Conflict); } else if (element == "feature-not-implemented") { - getPayloadInternal()->setCondition(Error::FeatureNotImplemented); + getPayloadInternal()->setCondition(ErrorPayload::FeatureNotImplemented); } else if (element == "forbidden") { - getPayloadInternal()->setCondition(Error::Forbidden); + getPayloadInternal()->setCondition(ErrorPayload::Forbidden); } else if (element == "gone") { - getPayloadInternal()->setCondition(Error::Gone); + getPayloadInternal()->setCondition(ErrorPayload::Gone); } else if (element == "internal-server-error") { - getPayloadInternal()->setCondition(Error::InternalServerError); + getPayloadInternal()->setCondition(ErrorPayload::InternalServerError); } else if (element == "item-not-found") { - getPayloadInternal()->setCondition(Error::ItemNotFound); + getPayloadInternal()->setCondition(ErrorPayload::ItemNotFound); } else if (element == "jid-malformed") { - getPayloadInternal()->setCondition(Error::JIDMalformed); + getPayloadInternal()->setCondition(ErrorPayload::JIDMalformed); } else if (element == "not-acceptable") { - getPayloadInternal()->setCondition(Error::NotAcceptable); + getPayloadInternal()->setCondition(ErrorPayload::NotAcceptable); } else if (element == "not-allowed") { - getPayloadInternal()->setCondition(Error::NotAllowed); + getPayloadInternal()->setCondition(ErrorPayload::NotAllowed); } else if (element == "not-authorized") { - getPayloadInternal()->setCondition(Error::NotAuthorized); + getPayloadInternal()->setCondition(ErrorPayload::NotAuthorized); } else if (element == "payment-required") { - getPayloadInternal()->setCondition(Error::PaymentRequired); + getPayloadInternal()->setCondition(ErrorPayload::PaymentRequired); } else if (element == "recipient-unavailable") { - getPayloadInternal()->setCondition(Error::RecipientUnavailable); + getPayloadInternal()->setCondition(ErrorPayload::RecipientUnavailable); } else if (element == "redirect") { - getPayloadInternal()->setCondition(Error::Redirect); + getPayloadInternal()->setCondition(ErrorPayload::Redirect); } else if (element == "registration-required") { - getPayloadInternal()->setCondition(Error::RegistrationRequired); + getPayloadInternal()->setCondition(ErrorPayload::RegistrationRequired); } else if (element == "remote-server-not-found") { - getPayloadInternal()->setCondition(Error::RemoteServerNotFound); + getPayloadInternal()->setCondition(ErrorPayload::RemoteServerNotFound); } else if (element == "remote-server-timeout") { - getPayloadInternal()->setCondition(Error::RemoteServerTimeout); + getPayloadInternal()->setCondition(ErrorPayload::RemoteServerTimeout); } else if (element == "resource-constraint") { - getPayloadInternal()->setCondition(Error::ResourceConstraint); + getPayloadInternal()->setCondition(ErrorPayload::ResourceConstraint); } else if (element == "service-unavailable") { - getPayloadInternal()->setCondition(Error::ServiceUnavailable); + getPayloadInternal()->setCondition(ErrorPayload::ServiceUnavailable); } else if (element == "subscription-required") { - getPayloadInternal()->setCondition(Error::SubscriptionRequired); + getPayloadInternal()->setCondition(ErrorPayload::SubscriptionRequired); } else if (element == "unexpected-request") { - getPayloadInternal()->setCondition(Error::UnexpectedRequest); + getPayloadInternal()->setCondition(ErrorPayload::UnexpectedRequest); } else { - getPayloadInternal()->setCondition(Error::UndefinedCondition); + getPayloadInternal()->setCondition(ErrorPayload::UndefinedCondition); } } } diff --git a/Swiften/Parser/PayloadParsers/ErrorParser.h b/Swiften/Parser/PayloadParsers/ErrorParser.h index 76db205..17b78b9 100644 --- a/Swiften/Parser/PayloadParsers/ErrorParser.h +++ b/Swiften/Parser/PayloadParsers/ErrorParser.h @@ -1,11 +1,11 @@ #ifndef SWIFTEN_ErrorParser_H #define SWIFTEN_ErrorParser_H -#include "Swiften/Elements/Error.h" +#include "Swiften/Elements/ErrorPayload.h" #include "Swiften/Parser/GenericPayloadParser.h" namespace Swift { - class ErrorParser : public GenericPayloadParser { + class ErrorParser : public GenericPayloadParser { public: ErrorParser(); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/ErrorParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/ErrorParserTest.cpp index 338fb3f..dcd3172 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/ErrorParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/ErrorParserTest.cpp @@ -24,9 +24,9 @@ class ErrorParserTest : public CppUnit::TestFixture "boo" "")); - Error* payload = dynamic_cast(parser.getPayload().get()); - CPPUNIT_ASSERT_EQUAL(Error::BadRequest, payload->getCondition()); - CPPUNIT_ASSERT_EQUAL(Error::Modify, payload->getType()); + ErrorPayload* payload = dynamic_cast(parser.getPayload().get()); + CPPUNIT_ASSERT_EQUAL(ErrorPayload::BadRequest, payload->getCondition()); + CPPUNIT_ASSERT_EQUAL(ErrorPayload::Modify, payload->getType()); CPPUNIT_ASSERT_EQUAL(String("boo"), payload->getText()); } }; diff --git a/Swiften/Queries/GenericRequest.h b/Swiften/Queries/GenericRequest.h index b4a1918..77dae52 100644 --- a/Swiften/Queries/GenericRequest.h +++ b/Swiften/Queries/GenericRequest.h @@ -1,5 +1,4 @@ -#ifndef SWIFTEN_GenericRequest_H -#define SWIFTEN_GenericRequest_H +#pragma once #include @@ -17,13 +16,11 @@ namespace Swift { Request(type, receiver, payload, router) { } - virtual void handleResponse(boost::shared_ptr payload, boost::optional error) { + virtual void handleResponse(boost::shared_ptr payload, boost::optional error) { onResponse(boost::dynamic_pointer_cast(payload), error); } public: - boost::signal, const boost::optional&)> onResponse; + boost::signal, const boost::optional&)> onResponse; }; } - -#endif diff --git a/Swiften/Queries/IQRouter.cpp b/Swiften/Queries/IQRouter.cpp index ffed5f7..fdfa00b 100644 --- a/Swiften/Queries/IQRouter.cpp +++ b/Swiften/Queries/IQRouter.cpp @@ -6,7 +6,7 @@ #include "Swiften/Base/foreach.h" #include "Swiften/Queries/IQHandler.h" #include "Swiften/Queries/IQChannel.h" -#include "Swiften/Elements/Error.h" +#include "Swiften/Elements/ErrorPayload.h" namespace Swift { @@ -34,7 +34,7 @@ void IQRouter::handleIQ(boost::shared_ptr iq) { } } if (!handled && (iq->getType() == IQ::Get || iq->getType() == IQ::Set) ) { - channel_->sendIQ(IQ::createError(iq->getFrom(), iq->getID(), Error::FeatureNotImplemented, Error::Cancel)); + channel_->sendIQ(IQ::createError(iq->getFrom(), iq->getID(), ErrorPayload::FeatureNotImplemented, ErrorPayload::Cancel)); } processPendingRemoves(); diff --git a/Swiften/Queries/Request.cpp b/Swiften/Queries/Request.cpp index 90aa295..18446ae 100644 --- a/Swiften/Queries/Request.cpp +++ b/Swiften/Queries/Request.cpp @@ -35,11 +35,11 @@ bool Request::handleIQ(boost::shared_ptr iq) { bool handled = false; if (sent_ && iq->getID() == id_) { if (iq->getType() == IQ::Result) { - handleResponse(iq->getPayloadOfSameType(payload_), boost::optional()); + handleResponse(iq->getPayloadOfSameType(payload_), boost::optional()); } else { // FIXME: Get proper error - handleResponse(boost::shared_ptr(), boost::optional(Error::UndefinedCondition)); + handleResponse(boost::shared_ptr(), boost::optional(ErrorPayload::UndefinedCondition)); } router_->removeHandler(this); handled = true; diff --git a/Swiften/Queries/Request.h b/Swiften/Queries/Request.h index 8f7a1d1..cc4a58e 100644 --- a/Swiften/Queries/Request.h +++ b/Swiften/Queries/Request.h @@ -9,7 +9,7 @@ #include "Swiften/Queries/IQHandler.h" #include "Swiften/Elements/IQ.h" #include "Swiften/Elements/Payload.h" -#include "Swiften/Elements/Error.h" +#include "Swiften/Elements/ErrorPayload.h" #include "Swiften/JID/JID.h" namespace Swift { @@ -32,7 +32,7 @@ namespace Swift { payload_ = p; } - virtual void handleResponse(boost::shared_ptr, boost::optional) = 0; + virtual void handleResponse(boost::shared_ptr, boost::optional) = 0; private: bool handleIQ(boost::shared_ptr); diff --git a/Swiften/Queries/Requests/GetPrivateStorageRequest.h b/Swiften/Queries/Requests/GetPrivateStorageRequest.h index c5f8aef..5d6440e 100644 --- a/Swiften/Queries/Requests/GetPrivateStorageRequest.h +++ b/Swiften/Queries/Requests/GetPrivateStorageRequest.h @@ -5,7 +5,7 @@ #include "Swiften/Queries/Request.h" #include "Swiften/Elements/PrivateStorage.h" -#include "Swiften/Elements/Error.h" +#include "Swiften/Elements/ErrorPayload.h" namespace Swift { template @@ -14,7 +14,7 @@ namespace Swift { GetPrivateStorageRequest(IQRouter* router) : Request(IQ::Get, JID(), boost::shared_ptr(new PrivateStorage(boost::shared_ptr(new PAYLOAD_TYPE()))), router) { } - virtual void handleResponse(boost::shared_ptr payload, boost::optional error) { + virtual void handleResponse(boost::shared_ptr payload, boost::optional error) { boost::shared_ptr storage = boost::dynamic_pointer_cast(payload); if (storage) { onResponse(boost::dynamic_pointer_cast(storage->getPayload()), error); @@ -25,6 +25,6 @@ namespace Swift { } public: - boost::signal, const boost::optional&)> onResponse; + boost::signal, const boost::optional&)> onResponse; }; } diff --git a/Swiften/Queries/Requests/SetPrivateStorageRequest.h b/Swiften/Queries/Requests/SetPrivateStorageRequest.h index 63ac8dc..834ddd8 100644 --- a/Swiften/Queries/Requests/SetPrivateStorageRequest.h +++ b/Swiften/Queries/Requests/SetPrivateStorageRequest.h @@ -5,7 +5,7 @@ #include "Swiften/Queries/Request.h" #include "Swiften/Elements/PrivateStorage.h" -#include "Swiften/Elements/Error.h" +#include "Swiften/Elements/ErrorPayload.h" namespace Swift { template @@ -14,11 +14,11 @@ namespace Swift { SetPrivateStorageRequest(boost::shared_ptr payload, IQRouter* router) : Request(IQ::Set, JID(), boost::shared_ptr(new PrivateStorage(payload)), router) { } - virtual void handleResponse(boost::shared_ptr payload, boost::optional error) { + virtual void handleResponse(boost::shared_ptr payload, boost::optional error) { onResponse(error); } public: - boost::signal&)> onResponse; + boost::signal&)> onResponse; }; } diff --git a/Swiften/Queries/Requests/UnitTest/GetPrivateStorageRequestTest.cpp b/Swiften/Queries/Requests/UnitTest/GetPrivateStorageRequestTest.cpp index 14e04cf..a86a111 100644 --- a/Swiften/Queries/Requests/UnitTest/GetPrivateStorageRequestTest.cpp +++ b/Swiften/Queries/Requests/UnitTest/GetPrivateStorageRequestTest.cpp @@ -72,7 +72,7 @@ class GetPrivateStorageRequestTest : public CppUnit::TestFixture } private: - void handleResponse(boost::shared_ptr p, const boost::optional& e) { + void handleResponse(boost::shared_ptr p, const boost::optional& e) { if (e) { errors.push_back(*e); } @@ -99,7 +99,7 @@ class GetPrivateStorageRequestTest : public CppUnit::TestFixture private: IQRouter* router; DummyIQChannel* channel; - std::vector< Error > errors; + std::vector< ErrorPayload > errors; std::vector< boost::shared_ptr > responses; }; diff --git a/Swiften/Queries/Responder.h b/Swiften/Queries/Responder.h index e6e8ca6..9c025eb 100644 --- a/Swiften/Queries/Responder.h +++ b/Swiften/Queries/Responder.h @@ -3,7 +3,7 @@ #include "Swiften/Queries/IQHandler.h" #include "Swiften/Queries/IQRouter.h" -#include "Swiften/Elements/Error.h" +#include "Swiften/Elements/ErrorPayload.h" namespace Swift { template @@ -25,7 +25,7 @@ namespace Swift { router_->sendIQ(IQ::createResult(to, id, payload)); } - void sendError(const JID& to, const String& id, Error::Condition condition, Error::Type type) { + void sendError(const JID& to, const String& id, ErrorPayload::Condition condition, ErrorPayload::Type type) { router_->sendIQ(IQ::createError(to, id, condition, type)); } @@ -42,7 +42,7 @@ namespace Swift { result = handleGetRequest(iq->getFrom(), iq->getID(), payload); } if (!result) { - router_->sendIQ(IQ::createError(iq->getFrom(), iq->getID(), Error::NotAllowed, Error::Cancel)); + router_->sendIQ(IQ::createError(iq->getFrom(), iq->getID(), ErrorPayload::NotAllowed, ErrorPayload::Cancel)); } return true; } diff --git a/Swiften/Queries/Responders/DiscoInfoResponder.cpp b/Swiften/Queries/Responders/DiscoInfoResponder.cpp index a114fbc..572f83f 100644 --- a/Swiften/Queries/Responders/DiscoInfoResponder.cpp +++ b/Swiften/Queries/Responders/DiscoInfoResponder.cpp @@ -27,7 +27,7 @@ bool DiscoInfoResponder::handleGetRequest(const JID& from, const String& id, boo sendResponse(from, id, boost::shared_ptr(new DiscoInfo((*i).second))); } else { - sendError(from, id, Error::ItemNotFound, Error::Cancel); + sendError(from, id, ErrorPayload::ItemNotFound, ErrorPayload::Cancel); } } return true; diff --git a/Swiften/Queries/Responders/UnitTest/DiscoInfoResponderTest.cpp b/Swiften/Queries/Responders/UnitTest/DiscoInfoResponderTest.cpp index 6ed7b9e..5993d0c 100644 --- a/Swiften/Queries/Responders/UnitTest/DiscoInfoResponderTest.cpp +++ b/Swiften/Queries/Responders/UnitTest/DiscoInfoResponderTest.cpp @@ -72,7 +72,7 @@ class DiscoInfoResponderTest : public CppUnit::TestFixture { channel_->onIQReceived(IQ::createRequest(IQ::Get, JID("foo@bar.com"), "id-1", query)); CPPUNIT_ASSERT_EQUAL(1, static_cast(channel_->iqs_.size())); - boost::shared_ptr payload(channel_->iqs_[0]->getPayload()); + boost::shared_ptr payload(channel_->iqs_[0]->getPayload()); CPPUNIT_ASSERT(payload); } diff --git a/Swiften/Queries/UnitTest/IQRouterTest.cpp b/Swiften/Queries/UnitTest/IQRouterTest.cpp index 94b7de8..5760b09 100644 --- a/Swiften/Queries/UnitTest/IQRouterTest.cpp +++ b/Swiften/Queries/UnitTest/IQRouterTest.cpp @@ -87,7 +87,7 @@ class IQRouterTest : public CppUnit::TestFixture channel_->onIQReceived(boost::shared_ptr(new IQ())); CPPUNIT_ASSERT_EQUAL(1, static_cast(channel_->iqs_.size())); - CPPUNIT_ASSERT(channel_->iqs_[0]->getPayload()); + CPPUNIT_ASSERT(channel_->iqs_[0]->getPayload()); } diff --git a/Swiften/Queries/UnitTest/RequestTest.cpp b/Swiften/Queries/UnitTest/RequestTest.cpp index ea6dee6..51d5a51 100644 --- a/Swiften/Queries/UnitTest/RequestTest.cpp +++ b/Swiften/Queries/UnitTest/RequestTest.cpp @@ -113,7 +113,7 @@ class RequestTest : public CppUnit::TestFixture } private: - void handleResponse(boost::shared_ptr p, const boost::optional& e) { + void handleResponse(boost::shared_ptr p, const boost::optional& e) { if (e) { ++errorsReceived_; } diff --git a/Swiften/SConscript b/Swiften/SConscript index 148f1f8..35728be 100644 --- a/Swiften/SConscript +++ b/Swiften/SConscript @@ -75,6 +75,8 @@ sources = [ "Server/SimpleUserRegistry.cpp", "Server/UserRegistry.cpp", "Session/Session.cpp", + "Session/SessionStream.cpp", + "Session/BasicSessionStream.cpp", "StringCodecs/Base64.cpp", "StringCodecs/SHA1.cpp", ] diff --git a/Swiften/Serializer/PayloadSerializers/ErrorSerializer.cpp b/Swiften/Serializer/PayloadSerializers/ErrorSerializer.cpp index 347e1a5..f5ce478 100644 --- a/Swiften/Serializer/PayloadSerializers/ErrorSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/ErrorSerializer.cpp @@ -3,43 +3,43 @@ namespace Swift { -ErrorSerializer::ErrorSerializer() : GenericPayloadSerializer() { +ErrorSerializer::ErrorSerializer() : GenericPayloadSerializer() { } -String ErrorSerializer::serializePayload(boost::shared_ptr error) const { +String ErrorSerializer::serializePayload(boost::shared_ptr error) const { String result("getType()) { - case Error::Continue: result += "continue"; break; - case Error::Modify: result += "modify"; break; - case Error::Auth: result += "auth"; break; - case Error::Wait: result += "wait"; break; + case ErrorPayload::Continue: result += "continue"; break; + case ErrorPayload::Modify: result += "modify"; break; + case ErrorPayload::Auth: result += "auth"; break; + case ErrorPayload::Wait: result += "wait"; break; default: result += "cancel"; break; } result += "\">"; String conditionElement; switch (error->getCondition()) { - case Error::BadRequest: conditionElement = "bad-request"; break; - case Error::Conflict: conditionElement = "conflict"; break; - case Error::FeatureNotImplemented: conditionElement = "feature-not-implemented"; break; - case Error::Forbidden: conditionElement = "forbidden"; break; - case Error::Gone: conditionElement = "gone"; break; - case Error::InternalServerError: conditionElement = "internal-server-error"; break; - case Error::ItemNotFound: conditionElement = "item-not-found"; break; - case Error::JIDMalformed: conditionElement = "jid-malformed"; break; - case Error::NotAcceptable: conditionElement = "not-acceptable"; break; - case Error::NotAllowed: conditionElement = "not-allowed"; break; - case Error::NotAuthorized: conditionElement = "not-authorized"; break; - case Error::PaymentRequired: conditionElement = "payment-required"; break; - case Error::RecipientUnavailable: conditionElement = "recipient-unavailable"; break; - case Error::Redirect: conditionElement = "redirect"; break; - case Error::RegistrationRequired: conditionElement = "registration-required"; break; - case Error::RemoteServerNotFound: conditionElement = "remote-server-not-found"; break; - case Error::RemoteServerTimeout: conditionElement = "remote-server-timeout"; break; - case Error::ResourceConstraint: conditionElement = "resource-constraint"; break; - case Error::ServiceUnavailable: conditionElement = "service-unavailable"; break; - case Error::SubscriptionRequired: conditionElement = "subscription-required"; break; - case Error::UnexpectedRequest: conditionElement = "unexpected-request"; break; + case ErrorPayload::BadRequest: conditionElement = "bad-request"; break; + case ErrorPayload::Conflict: conditionElement = "conflict"; break; + case ErrorPayload::FeatureNotImplemented: conditionElement = "feature-not-implemented"; break; + case ErrorPayload::Forbidden: conditionElement = "forbidden"; break; + case ErrorPayload::Gone: conditionElement = "gone"; break; + case ErrorPayload::InternalServerError: conditionElement = "internal-server-error"; break; + case ErrorPayload::ItemNotFound: conditionElement = "item-not-found"; break; + case ErrorPayload::JIDMalformed: conditionElement = "jid-malformed"; break; + case ErrorPayload::NotAcceptable: conditionElement = "not-acceptable"; break; + case ErrorPayload::NotAllowed: conditionElement = "not-allowed"; break; + case ErrorPayload::NotAuthorized: conditionElement = "not-authorized"; break; + case ErrorPayload::PaymentRequired: conditionElement = "payment-required"; break; + case ErrorPayload::RecipientUnavailable: conditionElement = "recipient-unavailable"; break; + case ErrorPayload::Redirect: conditionElement = "redirect"; break; + case ErrorPayload::RegistrationRequired: conditionElement = "registration-required"; break; + case ErrorPayload::RemoteServerNotFound: conditionElement = "remote-server-not-found"; break; + case ErrorPayload::RemoteServerTimeout: conditionElement = "remote-server-timeout"; break; + case ErrorPayload::ResourceConstraint: conditionElement = "resource-constraint"; break; + case ErrorPayload::ServiceUnavailable: conditionElement = "service-unavailable"; break; + case ErrorPayload::SubscriptionRequired: conditionElement = "subscription-required"; break; + case ErrorPayload::UnexpectedRequest: conditionElement = "unexpected-request"; break; default: conditionElement = "undefined-condition"; break; } result += "<" + conditionElement + " xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\"/>"; diff --git a/Swiften/Serializer/PayloadSerializers/ErrorSerializer.h b/Swiften/Serializer/PayloadSerializers/ErrorSerializer.h index ecf73dc..931596f 100644 --- a/Swiften/Serializer/PayloadSerializers/ErrorSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/ErrorSerializer.h @@ -2,14 +2,14 @@ #define SWIFTEN_ErrorSerializer_H #include "Swiften/Serializer/GenericPayloadSerializer.h" -#include "Swiften/Elements/Error.h" +#include "Swiften/Elements/ErrorPayload.h" namespace Swift { - class ErrorSerializer : public GenericPayloadSerializer { + class ErrorSerializer : public GenericPayloadSerializer { public: ErrorSerializer(); - virtual String serializePayload(boost::shared_ptr error) const; + virtual String serializePayload(boost::shared_ptr error) const; }; } diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/ErrorSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/ErrorSerializerTest.cpp index 2d68a3d..ecd904a 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/ErrorSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/ErrorSerializerTest.cpp @@ -16,7 +16,7 @@ class ErrorSerializerTest : public CppUnit::TestFixture void testSerialize() { ErrorSerializer testling; - boost::shared_ptr error(new Error(Error::BadRequest, Error::Cancel, "My Error")); + boost::shared_ptr error(new ErrorPayload(ErrorPayload::BadRequest, ErrorPayload::Cancel, "My Error")); CPPUNIT_ASSERT_EQUAL(String("My Error"), testling.serialize(error)); } diff --git a/Swiften/Session/BasicSessionStream.cpp b/Swiften/Session/BasicSessionStream.cpp index 46d4e16..73eaf5b 100644 --- a/Swiften/Session/BasicSessionStream.cpp +++ b/Swiften/Session/BasicSessionStream.cpp @@ -13,13 +13,16 @@ namespace Swift { -BasicSessionStream::BasicSessionStream(boost::shared_ptr connection, PayloadParserFactoryCollection* payloadParserFactories, PayloadSerializerCollection* payloadSerializers, TLSLayerFactory* tlsLayerFactory) : tlsLayerFactory(tlsLayerFactory) { +BasicSessionStream::BasicSessionStream(boost::shared_ptr connection, PayloadParserFactoryCollection* payloadParserFactories, PayloadSerializerCollection* payloadSerializers, TLSLayerFactory* tlsLayerFactory) : connection(connection), payloadParserFactories(payloadParserFactories), payloadSerializers(payloadSerializers), tlsLayerFactory(tlsLayerFactory) { +} + +void BasicSessionStream::initialize() { xmppLayer = boost::shared_ptr( new XMPPLayer(payloadParserFactories, payloadSerializers)); - xmppLayer->onStreamStart.connect(boost::ref(onStreamStartReceived)); - xmppLayer->onElement.connect(boost::ref(onElementReceived)); + xmppLayer->onStreamStart.connect(boost::bind(&BasicSessionStream::handleStreamStartReceived, shared_from_this(), _1)); + xmppLayer->onElement.connect(boost::bind(&BasicSessionStream::handleElementReceived, shared_from_this(), _1)); xmppLayer->onError.connect(boost::bind( - &BasicSessionStream::handleXMPPError, this)); + &BasicSessionStream::handleXMPPError, shared_from_this())); connectionLayer = boost::shared_ptr( new ConnectionLayer(connection)); @@ -47,7 +50,7 @@ void BasicSessionStream::addTLSEncryption() { tlsLayer = tlsLayerFactory->createTLSLayer(); streamStack->addLayer(tlsLayer); // TODO: Add tls layer certificate if needed - tlsLayer->onError.connect(boost::bind(&BasicSessionStream::handleTLSError, this)); + tlsLayer->onError.connect(boost::bind(&BasicSessionStream::handleTLSError, shared_from_this())); tlsLayer->connect(); } @@ -61,12 +64,20 @@ void BasicSessionStream::resetXMPPParser() { xmppLayer->resetParser(); } +void BasicSessionStream::handleStreamStartReceived(const ProtocolHeader& header) { + onStreamStartReceived(header); +} + +void BasicSessionStream::handleElementReceived(boost::shared_ptr element) { + onElementReceived(element); +} + void BasicSessionStream::handleXMPPError() { - // TODO + onError(boost::shared_ptr(new Error())); } void BasicSessionStream::handleTLSError() { - // TODO + onError(boost::shared_ptr(new Error())); } }; diff --git a/Swiften/Session/BasicSessionStream.h b/Swiften/Session/BasicSessionStream.h index bf92bbb..d248ebc 100644 --- a/Swiften/Session/BasicSessionStream.h +++ b/Swiften/Session/BasicSessionStream.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include "Swiften/Network/Connection.h" #include "Swiften/Session/SessionStream.h" @@ -17,7 +18,7 @@ namespace Swift { class BasicSessionStream : public SessionStream, - public boost::BOOST_SIGNALS_NAMESPACE::trackable { + public boost::enable_shared_from_this { public: BasicSessionStream( boost::shared_ptr connection, @@ -27,6 +28,8 @@ namespace Swift { ); ~BasicSessionStream(); + void initialize(); + virtual void writeHeader(const ProtocolHeader& header); virtual void writeElement(boost::shared_ptr); @@ -40,12 +43,17 @@ namespace Swift { private: void handleXMPPError(); void handleTLSError(); + void handleStreamStartReceived(const ProtocolHeader&); + void handleElementReceived(boost::shared_ptr); private: + boost::shared_ptr connection; + PayloadParserFactoryCollection* payloadParserFactories; + PayloadSerializerCollection* payloadSerializers; + TLSLayerFactory* tlsLayerFactory; boost::shared_ptr xmppLayer; boost::shared_ptr connectionLayer; StreamStack* streamStack; - TLSLayerFactory* tlsLayerFactory; boost::shared_ptr tlsLayer; boost::shared_ptr whitespacePingLayer; }; diff --git a/Swiften/Session/SessionStream.h b/Swiften/Session/SessionStream.h index 17d9a24..44a1980 100644 --- a/Swiften/Session/SessionStream.h +++ b/Swiften/Session/SessionStream.h @@ -5,10 +5,16 @@ #include "Swiften/Elements/ProtocolHeader.h" #include "Swiften/Elements/Element.h" +#include "Swiften/Base/Error.h" namespace Swift { class SessionStream { public: + class Error : public Swift::Error { + public: + Error() {} + }; + virtual ~SessionStream(); virtual void writeHeader(const ProtocolHeader& header) = 0; @@ -23,5 +29,6 @@ namespace Swift { boost::signal onStreamStartReceived; boost::signal)> onElementReceived; + boost::signal)> onError; }; } -- cgit v0.10.2-6-g49f6