diff options
101 files changed, 272 insertions, 271 deletions
diff --git a/Limber/Server/ServerFromClientSession.cpp b/Limber/Server/ServerFromClientSession.cpp index 71a8fef..9b1d2cf 100644 --- a/Limber/Server/ServerFromClientSession.cpp +++ b/Limber/Server/ServerFromClientSession.cpp @@ -1,78 +1,78 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #include "Limber/Server/ServerFromClientSession.h" #include <boost/smart_ptr/make_shared.hpp> #include <boost/bind.hpp> #include "Swiften/Elements/ProtocolHeader.h" #include "Limber/Server/UserRegistry.h" #include "Swiften/Network/Connection.h" #include "Swiften/StreamStack/XMPPLayer.h" #include "Swiften/Elements/StreamFeatures.h" #include "Swiften/Elements/ResourceBind.h" #include "Swiften/Elements/StartSession.h" #include "Swiften/Elements/IQ.h" #include "Swiften/Elements/AuthSuccess.h" #include "Swiften/Elements/AuthFailure.h" #include "Swiften/Elements/AuthRequest.h" #include "Swiften/SASL/PLAINMessage.h" namespace Swift { ServerFromClientSession::ServerFromClientSession( const std::string& id, boost::shared_ptr<Connection> connection, PayloadParserFactoryCollection* payloadParserFactories, PayloadSerializerCollection* payloadSerializers, XMLParserFactory* xmlParserFactory, UserRegistry* userRegistry) : Session(connection, payloadParserFactories, payloadSerializers, xmlParserFactory), id_(id), userRegistry_(userRegistry), authenticated_(false), initialized(false), allowSASLEXTERNAL(false) { } -void ServerFromClientSession::handleElement(boost::shared_ptr<Element> element) { +void ServerFromClientSession::handleElement(boost::shared_ptr<ToplevelElement> element) { if (isInitialized()) { onElementReceived(element); } else { if (AuthRequest* authRequest = dynamic_cast<AuthRequest*>(element.get())) { if (authRequest->getMechanism() == "PLAIN" || (allowSASLEXTERNAL && authRequest->getMechanism() == "EXTERNAL")) { if (authRequest->getMechanism() == "EXTERNAL") { getXMPPLayer()->writeElement(boost::make_shared<AuthSuccess>()); authenticated_ = true; getXMPPLayer()->resetParser(); } else { PLAINMessage plainMessage(authRequest->getMessage() ? *authRequest->getMessage() : createSafeByteArray("")); if (userRegistry_->isValidUserPassword(JID(plainMessage.getAuthenticationID(), getLocalJID().getDomain()), plainMessage.getPassword())) { getXMPPLayer()->writeElement(boost::make_shared<AuthSuccess>()); user_ = plainMessage.getAuthenticationID(); authenticated_ = true; getXMPPLayer()->resetParser(); } else { getXMPPLayer()->writeElement(boost::shared_ptr<AuthFailure>(new AuthFailure)); finishSession(AuthenticationFailedError); } } } else { getXMPPLayer()->writeElement(boost::shared_ptr<AuthFailure>(new AuthFailure)); finishSession(NoSupportedAuthMechanismsError); } } else if (IQ* iq = dynamic_cast<IQ*>(element.get())) { if (boost::shared_ptr<ResourceBind> resourceBind = iq->getPayload<ResourceBind>()) { setRemoteJID(JID(user_, getLocalJID().getDomain(), resourceBind->getResource())); boost::shared_ptr<ResourceBind> resultResourceBind(new ResourceBind()); resultResourceBind->setJID(getRemoteJID()); diff --git a/Limber/Server/ServerFromClientSession.h b/Limber/Server/ServerFromClientSession.h index e2754b9..00dfd79 100644 --- a/Limber/Server/ServerFromClientSession.h +++ b/Limber/Server/ServerFromClientSession.h @@ -1,62 +1,62 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <boost/shared_ptr.hpp> #include <boost/enable_shared_from_this.hpp> #include <string> #include <Swiften/Base/boost_bsignals.h> #include <Swiften/Session/Session.h> #include <Swiften/JID/JID.h> #include <Swiften/Network/Connection.h> #include <Swiften/Base/ByteArray.h> namespace Swift { class ProtocolHeader; - class Element; + class ToplevelElement; class Stanza; class PayloadParserFactoryCollection; class PayloadSerializerCollection; class StreamStack; class UserRegistry; class XMPPLayer; class ConnectionLayer; class Connection; class XMLParserFactory; class ServerFromClientSession : public Session { public: ServerFromClientSession( const std::string& id, boost::shared_ptr<Connection> connection, PayloadParserFactoryCollection* payloadParserFactories, PayloadSerializerCollection* payloadSerializers, XMLParserFactory* xmlParserFactory, UserRegistry* userRegistry); boost::signal<void ()> onSessionStarted; void setAllowSASLEXTERNAL(); private: - void handleElement(boost::shared_ptr<Element>); + void handleElement(boost::shared_ptr<ToplevelElement>); void handleStreamStart(const ProtocolHeader& header); void setInitialized(); bool isInitialized() const { return initialized; } private: std::string id_; UserRegistry* userRegistry_; bool authenticated_; bool initialized; bool allowSASLEXTERNAL; std::string user_; }; } diff --git a/Limber/main.cpp b/Limber/main.cpp index 3809729..3e095d5 100644 --- a/Limber/main.cpp +++ b/Limber/main.cpp @@ -1,87 +1,87 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #include <string> #include <boost/bind.hpp> #include <boost/shared_ptr.hpp> #include "Swiften/Elements/IQ.h" #include "Swiften/Elements/RosterPayload.h" #include "Swiften/Elements/VCard.h" #include "Swiften/Base/IDGenerator.h" #include "Swiften/EventLoop/EventLoop.h" #include "Swiften/EventLoop/SimpleEventLoop.h" #include "Swiften/EventLoop/EventOwner.h" #include "Swiften/Elements/Stanza.h" #include "Swiften/Network/ConnectionServer.h" #include "Swiften/Network/BoostConnection.h" #include "Swiften/Network/BoostIOServiceThread.h" #include "Swiften/Network/BoostConnectionServer.h" #include "Limber/Server/SimpleUserRegistry.h" #include "Limber/Server/ServerFromClientSession.h" #include "Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h" #include "Swiften/Parser/PlatformXMLParserFactory.h" #include "Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h" using namespace Swift; class Server { public: Server(UserRegistry* userRegistry, EventLoop* eventLoop) : userRegistry_(userRegistry) { serverFromClientConnectionServer_ = BoostConnectionServer::create(5222, boostIOServiceThread_.getIOService(), eventLoop); serverFromClientConnectionServer_->onNewConnection.connect(boost::bind(&Server::handleNewConnection, this, _1)); serverFromClientConnectionServer_->start(); } private: void handleNewConnection(boost::shared_ptr<Connection> c) { boost::shared_ptr<ServerFromClientSession> session(new ServerFromClientSession(idGenerator_.generateID(), c, &payloadParserFactories_, &payloadSerializers_, &xmlParserFactory, userRegistry_)); serverFromClientSessions_.push_back(session); session->onElementReceived.connect(boost::bind(&Server::handleElementReceived, this, _1, session)); session->onSessionFinished.connect(boost::bind(&Server::handleSessionFinished, this, session)); session->startSession(); } void handleSessionFinished(boost::shared_ptr<ServerFromClientSession> session) { serverFromClientSessions_.erase(std::remove(serverFromClientSessions_.begin(), serverFromClientSessions_.end(), session), serverFromClientSessions_.end()); } - void handleElementReceived(boost::shared_ptr<Element> element, boost::shared_ptr<ServerFromClientSession> session) { + void handleElementReceived(boost::shared_ptr<ToplevelElement> element, boost::shared_ptr<ServerFromClientSession> session) { boost::shared_ptr<Stanza> stanza(boost::dynamic_pointer_cast<Stanza>(element)); if (!stanza) { return; } stanza->setFrom(session->getRemoteJID()); if (!stanza->getTo().isValid()) { stanza->setTo(JID(session->getLocalJID())); } if (!stanza->getTo().isValid() || stanza->getTo() == session->getLocalJID() || stanza->getTo() == session->getRemoteJID().toBare()) { if (boost::shared_ptr<IQ> iq = boost::dynamic_pointer_cast<IQ>(stanza)) { if (iq->getPayload<RosterPayload>()) { session->sendElement(IQ::createResult(iq->getFrom(), iq->getID(), boost::make_shared<RosterPayload>())); } if (iq->getPayload<VCard>()) { if (iq->getType() == IQ::Get) { boost::shared_ptr<VCard> vcard(new VCard()); vcard->setNickname(iq->getFrom().getNode()); session->sendElement(IQ::createResult(iq->getFrom(), iq->getID(), vcard)); } else { session->sendElement(IQ::createError(iq->getFrom(), iq->getID(), ErrorPayload::Forbidden, ErrorPayload::Cancel)); } } else { session->sendElement(IQ::createError(iq->getFrom(), iq->getID(), ErrorPayload::FeatureNotImplemented, ErrorPayload::Cancel)); } } } } private: IDGenerator idGenerator_; PlatformXMLParserFactory xmlParserFactory; UserRegistry* userRegistry_; BoostIOServiceThread boostIOServiceThread_; diff --git a/Slimber/Server.cpp b/Slimber/Server.cpp index b63ca67..41b90c4 100644 --- a/Slimber/Server.cpp +++ b/Slimber/Server.cpp @@ -1,52 +1,52 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #include "Slimber/Server.h" #include <string> #include <boost/bind.hpp> #include <iostream> #include "Swiften/Base/String.h" #include "Swiften/LinkLocal/LinkLocalConnector.h" #include "Swiften/Network/Connection.h" #include "Swiften/Session/SessionTracer.h" -#include "Swiften/Elements/Element.h" +#include "Swiften/Elements/ToplevelElement.h" #include "Swiften/Elements/Presence.h" #include "Swiften/Elements/RosterPayload.h" #include "Swiften/Network/BoostConnection.h" #include "Swiften/Network/BoostConnectionServer.h" #include "Swiften/Session/SessionTracer.h" #include "Swiften/Elements/IQ.h" #include "Swiften/Elements/VCard.h" #include "Limber/Server/UserRegistry.h" #include "Swiften/Session/Session.h" #include <Swiften/Base/foreach.h> #include <string> #include <Swiften/LinkLocal/LinkLocalServiceInfo.h> #include <Swiften/LinkLocal/OutgoingLinkLocalSession.h> #include <Swiften/LinkLocal/IncomingLinkLocalSession.h> #include <Swiften/LinkLocal/LinkLocalServiceBrowser.h> #include <Swiften/Network/ConnectionServer.h> #include "Slimber/VCardCollection.h" #include "Slimber/LinkLocalPresenceManager.h" #include "Limber/Server/ServerFromClientSession.h" namespace Swift { Server::Server( int clientConnectionPort, int linkLocalConnectionPort, LinkLocalServiceBrowser* linkLocalServiceBrowser, VCardCollection* vCardCollection, EventLoop* eventLoop) : linkLocalServiceRegistered(false), rosterRequested(false), clientConnectionPort(clientConnectionPort), linkLocalConnectionPort(linkLocalConnectionPort), linkLocalServiceBrowser(linkLocalServiceBrowser), vCardCollection(vCardCollection), eventLoop(eventLoop), @@ -150,71 +150,71 @@ void Server::handleNewClientConnection(boost::shared_ptr<Connection> connection) &payloadParserFactories, &payloadSerializers, &xmlParserFactory, &userRegistry)); serverFromClientSession->setAllowSASLEXTERNAL(); serverFromClientSession->onSessionStarted.connect( boost::bind(&Server::handleSessionStarted, this)); serverFromClientSession->onElementReceived.connect( boost::bind(&Server::handleElementReceived, this, _1, serverFromClientSession)); serverFromClientSession->onSessionFinished.connect( boost::bind(&Server::handleSessionFinished, this, serverFromClientSession)); //tracers.push_back(boost::shared_ptr<SessionTracer>( // new SessionTracer(serverFromClientSession))); serverFromClientSession->startSession(); } void Server::handleSessionStarted() { onSelfConnected(true); } void Server::handleSessionFinished(boost::shared_ptr<ServerFromClientSession>) { serverFromClientSession.reset(); unregisterService(); selfJID = JID(); rosterRequested = false; onSelfConnected(false); lastPresence.reset(); } void Server::unregisterService() { if (linkLocalServiceRegistered) { linkLocalServiceRegistered = false; linkLocalServiceBrowser->unregisterService(); } } -void Server::handleElementReceived(boost::shared_ptr<Element> element, boost::shared_ptr<ServerFromClientSession> session) { +void Server::handleElementReceived(boost::shared_ptr<ToplevelElement> element, boost::shared_ptr<ServerFromClientSession> session) { boost::shared_ptr<Stanza> stanza = boost::dynamic_pointer_cast<Stanza>(element); if (!stanza) { return; } stanza->setFrom(session->getRemoteJID()); if (!stanza->getTo().isValid()) { stanza->setTo(session->getLocalJID()); } if (boost::shared_ptr<Presence> presence = boost::dynamic_pointer_cast<Presence>(stanza)) { if (presence->getType() == Presence::Available) { if (!linkLocalServiceRegistered) { linkLocalServiceRegistered = true; linkLocalServiceBrowser->registerService( session->getRemoteJID().toBare().toString(), linkLocalConnectionPort, getLinkLocalServiceInfo(presence)); } else { linkLocalServiceBrowser->updateService( getLinkLocalServiceInfo(presence)); } lastPresence = presence; } else { unregisterService(); } } else if (!stanza->getTo().isValid() || stanza->getTo() == session->getLocalJID() || stanza->getTo() == session->getRemoteJID().toBare()) { if (boost::shared_ptr<IQ> iq = boost::dynamic_pointer_cast<IQ>(stanza)) { if (iq->getPayload<RosterPayload>()) { if (iq->getType() == IQ::Get) { session->sendElement(IQ::createResult(iq->getFrom(), iq->getID(), presenceManager->getRoster())); rosterRequested = true; foreach(const boost::shared_ptr<Presence> presence, presenceManager->getAllPresence()) { @@ -260,92 +260,92 @@ void Server::handleElementReceived(boost::shared_ptr<Element> element, boost::sh new LinkLocalConnector( *service, linkLocalServiceBrowser->getQuerier(), BoostConnection::create(boostIOServiceThread.getIOService(), eventLoop))); connector->onConnectFinished.connect( boost::bind(&Server::handleConnectFinished, this, connector, _1)); connectors.push_back(connector); connector->connect(); } connector->queueElement(element); } else { session->sendElement(IQ::createError( stanza->getFrom(), stanza->getID(), ErrorPayload::RecipientUnavailable, ErrorPayload::Wait)); } } } } void Server::handleNewLinkLocalConnection(boost::shared_ptr<Connection> connection) { boost::shared_ptr<IncomingLinkLocalSession> session( new IncomingLinkLocalSession( selfJID, connection, &payloadParserFactories, &payloadSerializers, &xmlParserFactory)); registerLinkLocalSession(session); } void Server::handleLinkLocalSessionFinished(boost::shared_ptr<Session> session) { //std::cout << "Link local session from " << session->getRemoteJID() << " ended" << std::endl; linkLocalSessions.erase( std::remove(linkLocalSessions.begin(), linkLocalSessions.end(), session), linkLocalSessions.end()); } -void Server::handleLinkLocalElementReceived(boost::shared_ptr<Element> element, boost::shared_ptr<Session> session) { +void Server::handleLinkLocalElementReceived(boost::shared_ptr<ToplevelElement> element, boost::shared_ptr<Session> session) { if (boost::shared_ptr<Stanza> stanza = boost::dynamic_pointer_cast<Stanza>(element)) { JID fromJID = session->getRemoteJID(); if (!presenceManager->getServiceForJID(fromJID.toBare())) { return; // TODO: Send error back } stanza->setFrom(fromJID); serverFromClientSession->sendElement(stanza); } } void Server::handleConnectFinished(boost::shared_ptr<LinkLocalConnector> connector, bool error) { if (error) { std::cerr << "Error connecting" << std::endl; // TODO: Send back queued stanzas } else { boost::shared_ptr<OutgoingLinkLocalSession> outgoingSession( new OutgoingLinkLocalSession( selfJID, connector->getService().getJID(), connector->getConnection(), &payloadParserFactories, &payloadSerializers, &xmlParserFactory)); - foreach(const boost::shared_ptr<Element> element, connector->getQueuedElements()) { + foreach(const boost::shared_ptr<ToplevelElement> element, connector->getQueuedElements()) { outgoingSession->queueElement(element); } registerLinkLocalSession(outgoingSession); } connectors.erase(std::remove(connectors.begin(), connectors.end(), connector), connectors.end()); } void Server::registerLinkLocalSession(boost::shared_ptr<Session> session) { session->onSessionFinished.connect( boost::bind(&Server::handleLinkLocalSessionFinished, this, session)); session->onElementReceived.connect( boost::bind(&Server::handleLinkLocalElementReceived, this, _1, session)); linkLocalSessions.push_back(session); //tracers.push_back(boost::make_shared<SessionTracer>(session)); session->startSession(); } boost::shared_ptr<Session> Server::getLinkLocalSessionForJID(const JID& jid) { foreach(const boost::shared_ptr<Session> session, linkLocalSessions) { if (session->getRemoteJID() == jid) { return session; } } return boost::shared_ptr<Session>(); } boost::shared_ptr<LinkLocalConnector> Server::getLinkLocalConnectorForJID(const JID& jid) { foreach(const boost::shared_ptr<LinkLocalConnector> connector, connectors) { if (connector->getService().getJID() == jid) { return connector; } } return boost::shared_ptr<LinkLocalConnector>(); } diff --git a/Slimber/Server.h b/Slimber/Server.h index 96401d9..2d520d6 100644 --- a/Slimber/Server.h +++ b/Slimber/Server.h @@ -1,109 +1,109 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <boost/shared_ptr.hpp> #include <boost/optional.hpp> #include <vector> #include "Swiften/Network/BoostIOServiceThread.h" #include "Swiften/Network/BoostConnectionServer.h" #include "Limber/Server/UserRegistry.h" #include "Swiften/Base/IDGenerator.h" #include "Swiften/Parser/PlatformXMLParserFactory.h" #include "Limber/Server/ServerFromClientSession.h" #include "Swiften/JID/JID.h" #include "Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h" #include "Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h" #include "Swiften/LinkLocal/LinkLocalServiceInfo.h" #include "Slimber/ServerError.h" namespace Swift { class DNSSDServiceID; class VCardCollection; class LinkLocalConnector; class LinkLocalServiceBrowser; class LinkLocalPresenceManager; class BoostConnectionServer; class SessionTracer; class RosterPayload; class Presence; class EventLoop; class Server { public: Server( int clientConnectionPort, int linkLocalConnectionPort, LinkLocalServiceBrowser* browser, VCardCollection* vCardCollection, EventLoop* eventLoop); ~Server(); void start(); void stop(); int getLinkLocalPort() const { return linkLocalConnectionPort; } int getClientToServerPort() const { return clientConnectionPort; } boost::signal<void (bool)> onSelfConnected; boost::signal<void (boost::optional<ServerError>)> onStopped; private: void stop(boost::optional<ServerError>); void handleNewClientConnection(boost::shared_ptr<Connection> c); void handleSessionStarted(); void handleSessionFinished(boost::shared_ptr<ServerFromClientSession>); - void handleElementReceived(boost::shared_ptr<Element> element, boost::shared_ptr<ServerFromClientSession> session); + void handleElementReceived(boost::shared_ptr<ToplevelElement> element, boost::shared_ptr<ServerFromClientSession> session); void handleRosterChanged(boost::shared_ptr<RosterPayload> roster); void handlePresenceChanged(boost::shared_ptr<Presence> presence); void handleServiceRegistered(const DNSSDServiceID& service); void handleNewLinkLocalConnection(boost::shared_ptr<Connection> connection); void handleLinkLocalSessionFinished(boost::shared_ptr<Session> session); - void handleLinkLocalElementReceived(boost::shared_ptr<Element> element, boost::shared_ptr<Session> session); + void handleLinkLocalElementReceived(boost::shared_ptr<ToplevelElement> element, boost::shared_ptr<Session> session); void handleConnectFinished(boost::shared_ptr<LinkLocalConnector> connector, bool error); void handleClientConnectionServerStopped( boost::optional<BoostConnectionServer::Error>); void handleLinkLocalConnectionServerStopped( boost::optional<BoostConnectionServer::Error>); boost::shared_ptr<Session> getLinkLocalSessionForJID(const JID& jid); boost::shared_ptr<LinkLocalConnector> getLinkLocalConnectorForJID(const JID& jid); void registerLinkLocalSession(boost::shared_ptr<Session> session); void unregisterService(); LinkLocalServiceInfo getLinkLocalServiceInfo(boost::shared_ptr<Presence> presence); private: class DummyUserRegistry : public UserRegistry { public: DummyUserRegistry() {} virtual bool isValidUserPassword(const JID&, const SafeByteArray&) const { return true; } }; private: IDGenerator idGenerator; FullPayloadParserFactoryCollection payloadParserFactories; FullPayloadSerializerCollection payloadSerializers; BoostIOServiceThread boostIOServiceThread; DummyUserRegistry userRegistry; PlatformXMLParserFactory xmlParserFactory; bool linkLocalServiceRegistered; bool rosterRequested; int clientConnectionPort; int linkLocalConnectionPort; LinkLocalServiceBrowser* linkLocalServiceBrowser; VCardCollection* vCardCollection; EventLoop* eventLoop; diff --git a/Swiften/Client/ClientSession.cpp b/Swiften/Client/ClientSession.cpp index b29f63d..441189e 100644 --- a/Swiften/Client/ClientSession.cpp +++ b/Swiften/Client/ClientSession.cpp @@ -1,37 +1,37 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #include <Swiften/Client/ClientSession.h> #include <boost/bind.hpp> #include <boost/uuid/uuid.hpp> #include <boost/uuid/uuid_io.hpp> #include <boost/uuid/uuid_generators.hpp> #include <boost/smart_ptr/make_shared.hpp> #include <Swiften/Base/Platform.h> #include <Swiften/Base/Log.h> #include <Swiften/Elements/ProtocolHeader.h> #include <Swiften/Elements/StreamFeatures.h> #include <Swiften/Elements/StreamError.h> #include <Swiften/Elements/StartTLSRequest.h> #include <Swiften/Elements/StartTLSFailure.h> #include <Swiften/Elements/TLSProceed.h> #include <Swiften/Elements/AuthRequest.h> #include <Swiften/Elements/AuthSuccess.h> #include <Swiften/Elements/AuthFailure.h> #include <Swiften/Elements/AuthChallenge.h> #include <Swiften/Elements/AuthResponse.h> #include <Swiften/Elements/Compressed.h> #include <Swiften/Elements/CompressFailure.h> #include <Swiften/Elements/CompressRequest.h> #include <Swiften/Elements/EnableStreamManagement.h> #include <Swiften/Elements/StreamManagementEnabled.h> #include <Swiften/Elements/StreamManagementFailed.h> #include <Swiften/Elements/StartSession.h> #include <Swiften/Elements/StanzaAck.h> #include <Swiften/Elements/StanzaAckRequest.h> #include <Swiften/Elements/IQ.h> @@ -82,71 +82,71 @@ if (WindowsRegistry::isFIPSEnabled()) { #endif } ClientSession::~ClientSession() { } void ClientSession::start() { stream->onStreamStartReceived.connect(boost::bind(&ClientSession::handleStreamStart, shared_from_this(), _1)); stream->onElementReceived.connect(boost::bind(&ClientSession::handleElement, shared_from_this(), _1)); stream->onClosed.connect(boost::bind(&ClientSession::handleStreamClosed, shared_from_this(), _1)); stream->onTLSEncrypted.connect(boost::bind(&ClientSession::handleTLSEncrypted, shared_from_this())); assert(state == Initial); state = WaitingForStreamStart; sendStreamHeader(); } void ClientSession::sendStreamHeader() { ProtocolHeader header; header.setTo(getRemoteJID()); stream->writeHeader(header); } void ClientSession::sendStanza(boost::shared_ptr<Stanza> stanza) { stream->writeElement(stanza); if (stanzaAckRequester_) { stanzaAckRequester_->handleStanzaSent(stanza); } } void ClientSession::handleStreamStart(const ProtocolHeader&) { CHECK_STATE_OR_RETURN(WaitingForStreamStart); state = Negotiating; } -void ClientSession::handleElement(boost::shared_ptr<Element> element) { +void ClientSession::handleElement(boost::shared_ptr<ToplevelElement> element) { if (boost::shared_ptr<Stanza> stanza = boost::dynamic_pointer_cast<Stanza>(element)) { if (stanzaAckResponder_) { stanzaAckResponder_->handleStanzaReceived(); } if (getState() == Initialized) { onStanzaReceived(stanza); } else if (boost::shared_ptr<IQ> iq = boost::dynamic_pointer_cast<IQ>(element)) { if (state == BindingResource) { boost::shared_ptr<ResourceBind> resourceBind(iq->getPayload<ResourceBind>()); if (iq->getType() == IQ::Error && iq->getID() == "session-bind") { finishSession(Error::ResourceBindError); } else if (!resourceBind) { finishSession(Error::UnexpectedElementError); } else if (iq->getType() == IQ::Result) { localJID = resourceBind->getJID(); if (!localJID.isValid()) { finishSession(Error::ResourceBindError); } needResourceBind = false; continueSessionInitialization(); } else { finishSession(Error::UnexpectedElementError); } } else if (state == StartingSession) { if (iq->getType() == IQ::Result) { needSessionStart = false; continueSessionInitialization(); } else if (iq->getType() == IQ::Error) { finishSession(Error::SessionStartError); diff --git a/Swiften/Client/ClientSession.h b/Swiften/Client/ClientSession.h index 4b944fc..8a3deb4 100644 --- a/Swiften/Client/ClientSession.h +++ b/Swiften/Client/ClientSession.h @@ -1,53 +1,53 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <Swiften/Base/boost_bsignals.h> #include <boost/shared_ptr.hpp> #include <boost/enable_shared_from_this.hpp> #include <Swiften/Base/API.h> #include <Swiften/Base/Error.h> #include <Swiften/Session/SessionStream.h> #include <string> #include <Swiften/JID/JID.h> -#include <Swiften/Elements/Element.h> +#include <Swiften/Elements/ToplevelElement.h> #include <Swiften/StreamManagement/StanzaAckRequester.h> #include <Swiften/StreamManagement/StanzaAckResponder.h> namespace Swift { class ClientAuthenticator; class CertificateTrustChecker; class IDNConverter; class CryptoProvider; class SWIFTEN_API ClientSession : public boost::enable_shared_from_this<ClientSession> { public: enum State { Initial, WaitingForStreamStart, Negotiating, Compressing, WaitingForEncrypt, Encrypting, WaitingForCredentials, Authenticating, EnablingSessionManagement, BindingResource, StartingSession, Initialized, Finishing, Finished }; struct Error : public Swift::Error { enum Type { AuthenticationFailedError, CompressionFailedError, ServerVerificationFailedError, NoSupportedAuthMechanismsError, UnexpectedElementError, @@ -116,71 +116,71 @@ namespace Swift { bool isFinished() const { return getState() == Finished; } void sendCredentials(const SafeByteArray& password); void sendStanza(boost::shared_ptr<Stanza>); void setCertificateTrustChecker(CertificateTrustChecker* checker) { certificateTrustChecker = checker; } public: boost::signal<void ()> onNeedCredentials; boost::signal<void ()> onInitialized; boost::signal<void (boost::shared_ptr<Swift::Error>)> onFinished; boost::signal<void (boost::shared_ptr<Stanza>)> onStanzaReceived; boost::signal<void (boost::shared_ptr<Stanza>)> onStanzaAcked; private: ClientSession( const JID& jid, boost::shared_ptr<SessionStream>, IDNConverter* idnConverter, CryptoProvider* crypto); void finishSession(Error::Type error); void finishSession(boost::shared_ptr<Swift::Error> error); JID getRemoteJID() const { return JID("", localJID.getDomain()); } void sendStreamHeader(); - void handleElement(boost::shared_ptr<Element>); + void handleElement(boost::shared_ptr<ToplevelElement>); void handleStreamStart(const ProtocolHeader&); void handleStreamClosed(boost::shared_ptr<Swift::Error>); void handleTLSEncrypted(); bool checkState(State); void continueSessionInitialization(); void requestAck(); void handleStanzaAcked(boost::shared_ptr<Stanza> stanza); void ack(unsigned int handledStanzasCount); void continueAfterTLSEncrypted(); void checkTrustOrFinish(const std::vector<Certificate::ref>& certificateChain, boost::shared_ptr<CertificateVerificationError> error); private: JID localJID; State state; boost::shared_ptr<SessionStream> stream; IDNConverter* idnConverter; CryptoProvider* crypto; bool allowPLAINOverNonTLS; bool useStreamCompression; UseTLS useTLS; bool useAcks; bool needSessionStart; bool needResourceBind; bool needAcking; bool rosterVersioningSupported; ClientAuthenticator* authenticator; boost::shared_ptr<StanzaAckRequester> stanzaAckRequester_; boost::shared_ptr<StanzaAckResponder> stanzaAckResponder_; boost::shared_ptr<Swift::Error> error_; CertificateTrustChecker* certificateTrustChecker; }; } diff --git a/Swiften/Client/UnitTest/ClientSessionTest.cpp b/Swiften/Client/UnitTest/ClientSessionTest.cpp index 4ef6727..4e1fc31 100644 --- a/Swiften/Client/UnitTest/ClientSessionTest.cpp +++ b/Swiften/Client/UnitTest/ClientSessionTest.cpp @@ -1,37 +1,37 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> #include <deque> #include <boost/bind.hpp> #include <boost/optional.hpp> #include <boost/smart_ptr/make_shared.hpp> #include <Swiften/IDN/IDNConverter.h> #include <Swiften/IDN/PlatformIDNConverter.h> #include <Swiften/Session/SessionStream.h> #include <Swiften/Client/ClientSession.h> #include <Swiften/Elements/Message.h> #include <Swiften/Elements/AuthChallenge.h> #include <Swiften/Elements/StartTLSRequest.h> #include <Swiften/Elements/StreamFeatures.h> #include <Swiften/Elements/StreamError.h> #include <Swiften/Elements/TLSProceed.h> #include <Swiften/Elements/StartTLSFailure.h> #include <Swiften/Elements/AuthRequest.h> #include <Swiften/Elements/AuthSuccess.h> #include <Swiften/Elements/AuthFailure.h> #include <Swiften/Elements/StreamManagementEnabled.h> #include <Swiften/Elements/StreamManagementFailed.h> #include <Swiften/Elements/StanzaAck.h> #include <Swiften/Elements/EnableStreamManagement.h> #include <Swiften/Elements/IQ.h> #include <Swiften/Elements/ResourceBind.h> #include <Swiften/TLS/SimpleCertificate.h> #include <Swiften/TLS/BlindCertificateTrustChecker.h> #include <Swiften/Crypto/CryptoProvider.h> #include <Swiften/Crypto/PlatformCryptoProvider.h> @@ -349,99 +349,99 @@ class ClientSessionTest : public CppUnit::TestFixture { session->onFinished.connect(boost::bind(&ClientSessionTest::handleSessionFinished, this, _1)); session->onNeedCredentials.connect(boost::bind(&ClientSessionTest::handleSessionNeedCredentials, this)); session->setAllowPLAINOverNonTLS(true); return session; } void initializeSession(boost::shared_ptr<ClientSession> session) { session->start(); server->receiveStreamStart(); server->sendStreamStart(); server->sendStreamFeaturesWithPLAINAuthentication(); session->sendCredentials(createSafeByteArray("mypass")); server->receiveAuthRequest("PLAIN"); server->sendAuthSuccess(); server->receiveStreamStart(); server->sendStreamStart(); server->sendStreamFeaturesWithBindAndStreamManagement(); server->receiveBind(); server->sendBindResult(); server->receiveStreamManagementEnable(); server->sendStreamManagementEnabled(); } void handleSessionFinished(boost::shared_ptr<Error> error) { sessionFinishedReceived = true; sessionFinishedError = error; } void handleSessionNeedCredentials() { needCredentials = true; } class MockSessionStream : public SessionStream { public: struct Event { - Event(boost::shared_ptr<Element> element) : element(element), footer(false) {} + Event(boost::shared_ptr<ToplevelElement> element) : element(element), footer(false) {} Event(const ProtocolHeader& header) : header(header), footer(false) {} Event() : footer(true) {} - boost::shared_ptr<Element> element; + boost::shared_ptr<ToplevelElement> element; boost::optional<ProtocolHeader> header; bool footer; }; MockSessionStream() : available(true), canTLSEncrypt(true), tlsEncrypted(false), compressed(false), whitespacePingEnabled(false), resetCount(0) { } virtual void close() { onClosed(boost::shared_ptr<Error>()); } virtual bool isOpen() { return available; } virtual void writeHeader(const ProtocolHeader& header) { receivedEvents.push_back(Event(header)); } virtual void writeFooter() { receivedEvents.push_back(Event()); } - virtual void writeElement(boost::shared_ptr<Element> element) { + virtual void writeElement(boost::shared_ptr<ToplevelElement> element) { receivedEvents.push_back(Event(element)); } virtual void writeData(const std::string&) { } virtual bool supportsTLSEncryption() { return canTLSEncrypt; } virtual void addTLSEncryption() { tlsEncrypted = true; } virtual bool isTLSEncrypted() { return tlsEncrypted; } virtual ByteArray getTLSFinishMessage() const { return ByteArray(); } virtual Certificate::ref getPeerCertificate() const { return Certificate::ref(new SimpleCertificate()); } virtual std::vector<Certificate::ref> getPeerCertificateChain() const { return std::vector<Certificate::ref>(); } virtual boost::shared_ptr<CertificateVerificationError> getPeerCertificateVerificationError() const { return boost::shared_ptr<CertificateVerificationError>(); } virtual bool supportsZLibCompression() { diff --git a/Swiften/Component/ComponentSession.cpp b/Swiften/Component/ComponentSession.cpp index 7925b23..826451d 100644 --- a/Swiften/Component/ComponentSession.cpp +++ b/Swiften/Component/ComponentSession.cpp @@ -1,87 +1,87 @@ /* - * Copyright (c) 2010-2013 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #include <Swiften/Component/ComponentSession.h> #include <boost/bind.hpp> #include <boost/smart_ptr/make_shared.hpp> #include <Swiften/Elements/ProtocolHeader.h> #include <Swiften/Elements/StreamFeatures.h> #include <Swiften/Elements/ComponentHandshake.h> #include <Swiften/Session/SessionStream.h> #include <Swiften/Component/ComponentHandshakeGenerator.h> namespace Swift { ComponentSession::ComponentSession(const JID& jid, const std::string& secret, boost::shared_ptr<SessionStream> stream, CryptoProvider* crypto) : jid(jid), secret(secret), stream(stream), crypto(crypto), state(Initial) { } ComponentSession::~ComponentSession() { } void ComponentSession::start() { stream->onStreamStartReceived.connect(boost::bind(&ComponentSession::handleStreamStart, shared_from_this(), _1)); stream->onElementReceived.connect(boost::bind(&ComponentSession::handleElement, shared_from_this(), _1)); stream->onClosed.connect(boost::bind(&ComponentSession::handleStreamClosed, shared_from_this(), _1)); assert(state == Initial); state = WaitingForStreamStart; sendStreamHeader(); } void ComponentSession::sendStreamHeader() { ProtocolHeader header; header.setTo(jid); stream->writeHeader(header); } void ComponentSession::sendStanza(boost::shared_ptr<Stanza> stanza) { stream->writeElement(stanza); } void ComponentSession::handleStreamStart(const ProtocolHeader& header) { checkState(WaitingForStreamStart); state = Authenticating; stream->writeElement(ComponentHandshake::ref(new ComponentHandshake(ComponentHandshakeGenerator::getHandshake(header.getID(), secret, crypto)))); } -void ComponentSession::handleElement(boost::shared_ptr<Element> element) { +void ComponentSession::handleElement(boost::shared_ptr<ToplevelElement> element) { if (boost::shared_ptr<Stanza> stanza = boost::dynamic_pointer_cast<Stanza>(element)) { if (getState() == Initialized) { onStanzaReceived(stanza); } else { finishSession(Error::UnexpectedElementError); } } else if (boost::dynamic_pointer_cast<ComponentHandshake>(element)) { if (!checkState(Authenticating)) { return; } stream->setWhitespacePingEnabled(true); state = Initialized; onInitialized(); } else if (getState() == Authenticating) { if (boost::dynamic_pointer_cast<StreamFeatures>(element)) { // M-Link sends stream features, so swallow that. } else { // FIXME: We should actually check the element received finishSession(Error::AuthenticationFailedError); } } else { finishSession(Error::UnexpectedElementError); } } bool ComponentSession::checkState(State state) { if (this->state != state) { finishSession(Error::UnexpectedElementError); return false; } diff --git a/Swiften/Component/ComponentSession.h b/Swiften/Component/ComponentSession.h index 3103335..1fa7b5c 100644 --- a/Swiften/Component/ComponentSession.h +++ b/Swiften/Component/ComponentSession.h @@ -1,86 +1,86 @@ /* - * Copyright (c) 2010-2013 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <boost/shared_ptr.hpp> #include <boost/enable_shared_from_this.hpp> #include <Swiften/Base/API.h> #include <Swiften/JID/JID.h> #include <Swiften/Base/boost_bsignals.h> #include <Swiften/Base/Error.h> #include <string> -#include <Swiften/Elements/Element.h> +#include <Swiften/Elements/ToplevelElement.h> #include <Swiften/Elements/Stanza.h> #include <Swiften/Session/SessionStream.h> namespace Swift { class ComponentAuthenticator; class CryptoProvider; class SWIFTEN_API ComponentSession : public boost::enable_shared_from_this<ComponentSession> { public: enum State { Initial, WaitingForStreamStart, Authenticating, Initialized, Finishing, Finished }; struct Error : public Swift::Error { enum Type { AuthenticationFailedError, UnexpectedElementError } type; Error(Type type) : type(type) {} }; ~ComponentSession(); static boost::shared_ptr<ComponentSession> create(const JID& jid, const std::string& secret, boost::shared_ptr<SessionStream> stream, CryptoProvider* crypto) { return boost::shared_ptr<ComponentSession>(new ComponentSession(jid, secret, stream, crypto)); } State getState() const { return state; } void start(); void finish(); void sendStanza(boost::shared_ptr<Stanza>); public: boost::signal<void ()> onInitialized; boost::signal<void (boost::shared_ptr<Swift::Error>)> onFinished; boost::signal<void (boost::shared_ptr<Stanza>)> onStanzaReceived; private: ComponentSession(const JID& jid, const std::string& secret, boost::shared_ptr<SessionStream>, CryptoProvider*); void finishSession(Error::Type error); void finishSession(boost::shared_ptr<Swift::Error> error); void sendStreamHeader(); - void handleElement(boost::shared_ptr<Element>); + void handleElement(boost::shared_ptr<ToplevelElement>); void handleStreamStart(const ProtocolHeader&); void handleStreamClosed(boost::shared_ptr<Swift::Error>); bool checkState(State); private: JID jid; std::string secret; boost::shared_ptr<SessionStream> stream; CryptoProvider* crypto; boost::shared_ptr<Swift::Error> error; State state; }; } diff --git a/Swiften/Component/UnitTest/ComponentSessionTest.cpp b/Swiften/Component/UnitTest/ComponentSessionTest.cpp index 0533645..79d9ab3 100644 --- a/Swiften/Component/UnitTest/ComponentSessionTest.cpp +++ b/Swiften/Component/UnitTest/ComponentSessionTest.cpp @@ -1,37 +1,37 @@ /* - * Copyright (c) 2010-2013 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> #include <deque> #include <boost/bind.hpp> #include <boost/optional.hpp> #include <Swiften/Session/SessionStream.h> #include <Swiften/Component/ComponentSession.h> #include <Swiften/Elements/ComponentHandshake.h> #include <Swiften/Elements/AuthFailure.h> #include <Swiften/Crypto/CryptoProvider.h> #include <Swiften/Crypto/PlatformCryptoProvider.h> using namespace Swift; class ComponentSessionTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(ComponentSessionTest); CPPUNIT_TEST(testStart); CPPUNIT_TEST(testStart_Error); CPPUNIT_TEST(testStart_Unauthorized); CPPUNIT_TEST_SUITE_END(); public: void setUp() { server = boost::make_shared<MockSessionStream>(); sessionFinishedReceived = false; crypto = boost::shared_ptr<CryptoProvider>(PlatformCryptoProvider::create()); } void testStart() { boost::shared_ptr<ComponentSession> session(createSession()); @@ -54,99 +54,99 @@ class ComponentSessionTest : public CppUnit::TestFixture { server->breakConnection(); CPPUNIT_ASSERT_EQUAL(ComponentSession::Finished, session->getState()); CPPUNIT_ASSERT(sessionFinishedReceived); CPPUNIT_ASSERT(sessionFinishedError); } void testStart_Unauthorized() { boost::shared_ptr<ComponentSession> session(createSession()); session->start(); server->receiveStreamStart(); server->sendStreamStart(); server->receiveHandshake(); server->sendHandshakeError(); CPPUNIT_ASSERT_EQUAL(ComponentSession::Finished, session->getState()); CPPUNIT_ASSERT(sessionFinishedReceived); CPPUNIT_ASSERT(sessionFinishedError); } private: boost::shared_ptr<ComponentSession> createSession() { boost::shared_ptr<ComponentSession> session = ComponentSession::create(JID("service.foo.com"), "servicesecret", server, crypto.get()); session->onFinished.connect(boost::bind(&ComponentSessionTest::handleSessionFinished, this, _1)); return session; } void handleSessionFinished(boost::shared_ptr<Error> error) { sessionFinishedReceived = true; sessionFinishedError = error; } class MockSessionStream : public SessionStream { public: struct Event { - Event(boost::shared_ptr<Element> element) : element(element), footer(false) {} + Event(boost::shared_ptr<ToplevelElement> element) : element(element), footer(false) {} Event(const ProtocolHeader& header) : header(header), footer(false) {} Event() : footer(true) {} - boost::shared_ptr<Element> element; + boost::shared_ptr<ToplevelElement> element; boost::optional<ProtocolHeader> header; bool footer; }; MockSessionStream() : available(true), whitespacePingEnabled(false), resetCount(0) { } virtual void close() { onClosed(boost::shared_ptr<Error>()); } virtual bool isOpen() { return available; } virtual void writeHeader(const ProtocolHeader& header) { receivedEvents.push_back(Event(header)); } virtual void writeFooter() { receivedEvents.push_back(Event()); } - virtual void writeElement(boost::shared_ptr<Element> element) { + virtual void writeElement(boost::shared_ptr<ToplevelElement> element) { receivedEvents.push_back(Event(element)); } virtual void writeData(const std::string&) { } virtual bool supportsTLSEncryption() { return false; } virtual void addTLSEncryption() { assert(false); } virtual bool isTLSEncrypted() { return false; } virtual ByteArray getTLSFinishMessage() const { return ByteArray(); } virtual Certificate::ref getPeerCertificate() const { return Certificate::ref(); } virtual std::vector<Certificate::ref> getPeerCertificateChain() const { return std::vector<Certificate::ref>(); } virtual boost::shared_ptr<CertificateVerificationError> getPeerCertificateVerificationError() const { return boost::shared_ptr<CertificateVerificationError>(); } virtual bool supportsZLibCompression() { diff --git a/Swiften/Elements/AuthChallenge.h b/Swiften/Elements/AuthChallenge.h index f7f2796..6332d69 100644 --- a/Swiften/Elements/AuthChallenge.h +++ b/Swiften/Elements/AuthChallenge.h @@ -1,34 +1,34 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <boost/optional.hpp> #include <vector> -#include <Swiften/Elements/Element.h> +#include <Swiften/Elements/ToplevelElement.h> namespace Swift { - class AuthChallenge : public Element { + class AuthChallenge : public ToplevelElement { public: AuthChallenge() { } AuthChallenge(const std::vector<unsigned char>& value) : value(value) { } const boost::optional< std::vector<unsigned char> >& getValue() const { return value; } void setValue(const std::vector<unsigned char>& value) { this->value = boost::optional<std::vector<unsigned char> >(value); } private: boost::optional< std::vector<unsigned char> > value; }; } diff --git a/Swiften/Elements/AuthFailure.h b/Swiften/Elements/AuthFailure.h index ac40956..5088dcf 100644 --- a/Swiften/Elements/AuthFailure.h +++ b/Swiften/Elements/AuthFailure.h @@ -1,20 +1,20 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <boost/shared_ptr.hpp> -#include <Swiften/Elements/Element.h> +#include <Swiften/Elements/ToplevelElement.h> namespace Swift { - class AuthFailure : public Element { + class AuthFailure : public ToplevelElement { public: typedef boost::shared_ptr<AuthFailure> ref; AuthFailure() {} }; } diff --git a/Swiften/Elements/AuthRequest.h b/Swiften/Elements/AuthRequest.h index bfc86c2..bc88b9b 100644 --- a/Swiften/Elements/AuthRequest.h +++ b/Swiften/Elements/AuthRequest.h @@ -1,50 +1,50 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <vector> #include <string> #include <boost/optional.hpp> -#include <Swiften/Elements/Element.h> +#include <Swiften/Elements/ToplevelElement.h> #include <Swiften/Base/SafeByteArray.h> namespace Swift { - class AuthRequest : public Element { + class AuthRequest : public ToplevelElement { public: AuthRequest(const std::string& mechanism = "") : mechanism_(mechanism) { } AuthRequest(const std::string& mechanism, const SafeByteArray& message) : mechanism_(mechanism), message_(message) { } AuthRequest(const std::string& mechanism, const boost::optional<SafeByteArray>& message) : mechanism_(mechanism), message_(message) { } const boost::optional<SafeByteArray>& getMessage() const { return message_; } void setMessage(const SafeByteArray& message) { message_ = boost::optional<SafeByteArray>(message); } const std::string& getMechanism() const { return mechanism_; } void setMechanism(const std::string& mechanism) { mechanism_ = mechanism; } private: std::string mechanism_; boost::optional<SafeByteArray> message_; }; } diff --git a/Swiften/Elements/AuthResponse.h b/Swiften/Elements/AuthResponse.h index db2dcea..f8a075c 100644 --- a/Swiften/Elements/AuthResponse.h +++ b/Swiften/Elements/AuthResponse.h @@ -1,38 +1,38 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <vector> #include <boost/optional.hpp> -#include <Swiften/Elements/Element.h> +#include <Swiften/Elements/ToplevelElement.h> #include <Swiften/Base/SafeByteArray.h> namespace Swift { - class AuthResponse : public Element { + class AuthResponse : public ToplevelElement { public: AuthResponse() { } AuthResponse(const SafeByteArray& value) : value(value) { } AuthResponse(const boost::optional<SafeByteArray>& value) : value(value) { } const boost::optional<SafeByteArray>& getValue() const { return value; } void setValue(const SafeByteArray& value) { this->value = boost::optional<SafeByteArray>(value); } private: boost::optional<SafeByteArray> value; }; } diff --git a/Swiften/Elements/AuthSuccess.h b/Swiften/Elements/AuthSuccess.h index 3c0f329..8e4591c 100644 --- a/Swiften/Elements/AuthSuccess.h +++ b/Swiften/Elements/AuthSuccess.h @@ -1,30 +1,30 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <vector> #include <boost/optional.hpp> -#include <Swiften/Elements/Element.h> +#include <Swiften/Elements/ToplevelElement.h> namespace Swift { - class AuthSuccess : public Element { + class AuthSuccess : public ToplevelElement { public: AuthSuccess() {} const boost::optional<std::vector<unsigned char> >& getValue() const { return value; } void setValue(const std::vector<unsigned char>& value) { this->value = boost::optional<std::vector<unsigned char> >(value); } private: boost::optional<std::vector<unsigned char> > value; }; } diff --git a/Swiften/Elements/ComponentHandshake.h b/Swiften/Elements/ComponentHandshake.h index 5992b8c..b2f9b21 100644 --- a/Swiften/Elements/ComponentHandshake.h +++ b/Swiften/Elements/ComponentHandshake.h @@ -1,33 +1,33 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <boost/shared_ptr.hpp> #include <string> -#include <Swiften/Elements/Element.h> +#include <Swiften/Elements/ToplevelElement.h> namespace Swift { - class ComponentHandshake : public Element { + class ComponentHandshake : public ToplevelElement { public: typedef boost::shared_ptr<ComponentHandshake> ref; ComponentHandshake(const std::string& data = "") : data(data) { } void setData(const std::string& d) { data = d; } const std::string& getData() const { return data; } private: std::string data; }; } diff --git a/Swiften/Elements/CompressFailure.h b/Swiften/Elements/CompressFailure.h index 7dd8867..75e1d1d 100644 --- a/Swiften/Elements/CompressFailure.h +++ b/Swiften/Elements/CompressFailure.h @@ -1,17 +1,17 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once -#include <Swiften/Elements/Element.h> +#include <Swiften/Elements/ToplevelElement.h> namespace Swift { - class CompressFailure : public Element { + class CompressFailure : public ToplevelElement { public: CompressFailure() {} }; } diff --git a/Swiften/Elements/CompressRequest.h b/Swiften/Elements/CompressRequest.h index b6fcc64..9e2e267 100644 --- a/Swiften/Elements/CompressRequest.h +++ b/Swiften/Elements/CompressRequest.h @@ -1,28 +1,28 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once -#include <Swiften/Elements/Element.h> +#include <Swiften/Elements/ToplevelElement.h> namespace Swift { - class CompressRequest : public Element + class CompressRequest : public ToplevelElement { public: CompressRequest(const std::string& method = "") : method_(method) {} const std::string& getMethod() const { return method_; } void setMethod(const std::string& method) { method_ = method; } private: std::string method_; }; } diff --git a/Swiften/Elements/Compressed.h b/Swiften/Elements/Compressed.h index 2affec5..f593412 100644 --- a/Swiften/Elements/Compressed.h +++ b/Swiften/Elements/Compressed.h @@ -1,16 +1,16 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once -#include <Swiften/Elements/Element.h> +#include <Swiften/Elements/ToplevelElement.h> namespace Swift { - class Compressed : public Element { + class Compressed : public ToplevelElement { public: Compressed() {} }; } diff --git a/Swiften/Elements/EnableStreamManagement.h b/Swiften/Elements/EnableStreamManagement.h index 15a091e..732b225 100644 --- a/Swiften/Elements/EnableStreamManagement.h +++ b/Swiften/Elements/EnableStreamManagement.h @@ -1,17 +1,17 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once -#include <Swiften/Elements/Element.h> +#include <Swiften/Elements/ToplevelElement.h> namespace Swift { - class EnableStreamManagement : public Element { + class EnableStreamManagement : public ToplevelElement { public: EnableStreamManagement() {} }; } diff --git a/Swiften/Elements/Payload.h b/Swiften/Elements/Payload.h index 1459837..7d6789c 100644 --- a/Swiften/Elements/Payload.h +++ b/Swiften/Elements/Payload.h @@ -1,24 +1,25 @@ /* * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <boost/shared_ptr.hpp> #include <Swiften/Base/API.h> +#include <Swiften/Elements/ToplevelElement.h> namespace Swift { - class SWIFTEN_API Payload { + class SWIFTEN_API Payload : public ToplevelElement { public: typedef boost::shared_ptr<Payload> ref; public: Payload() {} SWIFTEN_DEFAULT_COPY_CONSTRUCTOR(Payload) virtual ~Payload(); SWIFTEN_DEFAULT_COPY_ASSIGMNENT_OPERATOR(Payload) }; } diff --git a/Swiften/Elements/Stanza.h b/Swiften/Elements/Stanza.h index e83f522..648c4df 100644 --- a/Swiften/Elements/Stanza.h +++ b/Swiften/Elements/Stanza.h @@ -1,57 +1,57 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <vector> #include <string> #include <boost/shared_ptr.hpp> #include <boost/optional/optional_fwd.hpp> #include <boost/date_time/posix_time/ptime.hpp> #include <Swiften/Base/API.h> -#include <Swiften/Elements/Element.h> +#include <Swiften/Elements/ToplevelElement.h> #include <Swiften/JID/JID.h> namespace Swift { class Payload; - class SWIFTEN_API Stanza : public Element { + class SWIFTEN_API Stanza : public ToplevelElement { public: typedef boost::shared_ptr<Stanza> ref; protected: Stanza(); public: virtual ~Stanza(); SWIFTEN_DEFAULT_COPY_CONSTRUCTOR(Stanza) template<typename T> boost::shared_ptr<T> getPayload() const { for (size_t i = 0; i < payloads_.size(); ++i) { boost::shared_ptr<T> result(boost::dynamic_pointer_cast<T>(payloads_[i])); if (result) { return result; } } return boost::shared_ptr<T>(); } template<typename T> std::vector< boost::shared_ptr<T> > getPayloads() const { std::vector< boost::shared_ptr<T> > results; for (size_t i = 0; i < payloads_.size(); ++i) { boost::shared_ptr<T> result(boost::dynamic_pointer_cast<T>(payloads_[i])); if (result) { results.push_back(result); } } return results; } const std::vector< boost::shared_ptr<Payload> >& getPayloads() const { diff --git a/Swiften/Elements/StanzaAck.h b/Swiften/Elements/StanzaAck.h index 8fe64e0..0d99c5b 100644 --- a/Swiften/Elements/StanzaAck.h +++ b/Swiften/Elements/StanzaAck.h @@ -1,36 +1,36 @@ /* - * Copyright (c) 2010-2013 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <boost/shared_ptr.hpp> -#include <Swiften/Elements/Element.h> +#include <Swiften/Elements/ToplevelElement.h> namespace Swift { - class StanzaAck : public Element { + class StanzaAck : public ToplevelElement { public: typedef boost::shared_ptr<StanzaAck> ref; StanzaAck() : valid(false), handledStanzasCount(0) {} StanzaAck(unsigned int handledStanzasCount) : valid(true), handledStanzasCount(handledStanzasCount) {} virtual ~StanzaAck(); unsigned int getHandledStanzasCount() const { return handledStanzasCount; } void setHandledStanzasCount(int i); bool isValid() const { return valid; } private: bool valid; unsigned int handledStanzasCount; }; } diff --git a/Swiften/Elements/StanzaAckRequest.h b/Swiften/Elements/StanzaAckRequest.h index 81b3871..0ae11ad 100644 --- a/Swiften/Elements/StanzaAckRequest.h +++ b/Swiften/Elements/StanzaAckRequest.h @@ -1,15 +1,15 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once -#include <Swiften/Elements/Element.h> +#include <Swiften/Elements/ToplevelElement.h> namespace Swift { - class StanzaAckRequest : public Element { + class StanzaAckRequest : public ToplevelElement { }; } diff --git a/Swiften/Elements/StartTLSFailure.h b/Swiften/Elements/StartTLSFailure.h index 5e233fb..ce13fd6 100644 --- a/Swiften/Elements/StartTLSFailure.h +++ b/Swiften/Elements/StartTLSFailure.h @@ -1,16 +1,16 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once -#include <Swiften/Elements/Element.h> +#include <Swiften/Elements/ToplevelElement.h> namespace Swift { - class StartTLSFailure : public Element { + class StartTLSFailure : public ToplevelElement { public: StartTLSFailure() {} }; } diff --git a/Swiften/Elements/StartTLSRequest.h b/Swiften/Elements/StartTLSRequest.h index e284f75..4b4f1f1 100644 --- a/Swiften/Elements/StartTLSRequest.h +++ b/Swiften/Elements/StartTLSRequest.h @@ -1,16 +1,16 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once -#include <Swiften/Elements/Element.h> +#include <Swiften/Elements/ToplevelElement.h> namespace Swift { - class StartTLSRequest : public Element { + class StartTLSRequest : public ToplevelElement { public: StartTLSRequest() {} }; } diff --git a/Swiften/Elements/StreamError.h b/Swiften/Elements/StreamError.h index a58d3ae..300f1c7 100644 --- a/Swiften/Elements/StreamError.h +++ b/Swiften/Elements/StreamError.h @@ -1,50 +1,50 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <boost/shared_ptr.hpp> -#include <Swiften/Elements/Element.h> +#include <Swiften/Elements/ToplevelElement.h> #include <string> namespace Swift { - class StreamError : public Element { + class StreamError : public ToplevelElement { public: typedef boost::shared_ptr<StreamError> ref; enum Type { BadFormat, BadNamespacePrefix, Conflict, ConnectionTimeout, HostGone, HostUnknown, ImproperAddressing, InternalServerError, InvalidFrom, InvalidID, InvalidNamespace, InvalidXML, NotAuthorized, NotWellFormed, PolicyViolation, RemoteConnectionFailed, Reset, ResourceConstraint, RestrictedXML, SeeOtherHost, SystemShutdown, UndefinedCondition, UnsupportedEncoding, UnsupportedStanzaType, UnsupportedVersion }; StreamError(Type type = UndefinedCondition, const std::string& text = std::string()) : type_(type), text_(text) { } Type getType() const { return type_; diff --git a/Swiften/Elements/StreamFeatures.h b/Swiften/Elements/StreamFeatures.h index 5e7b6c9..ed40544 100644 --- a/Swiften/Elements/StreamFeatures.h +++ b/Swiften/Elements/StreamFeatures.h @@ -1,52 +1,52 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <vector> #include <string> #include <boost/shared_ptr.hpp> #include <Swiften/Base/API.h> -#include <Swiften/Elements/Element.h> +#include <Swiften/Elements/ToplevelElement.h> namespace Swift { - class SWIFTEN_API StreamFeatures : public Element { + class SWIFTEN_API StreamFeatures : public ToplevelElement { public: typedef boost::shared_ptr<StreamFeatures> ref; StreamFeatures() : hasStartTLS_(false), hasResourceBind_(false), hasSession_(false), hasStreamManagement_(false), hasRosterVersioning_(false) {} void setHasStartTLS() { hasStartTLS_ = true; } bool hasStartTLS() const { return hasStartTLS_; } void setHasSession() { hasSession_ = true; } bool hasSession() const { return hasSession_; } void setHasResourceBind() { hasResourceBind_ = true; } bool hasResourceBind() const { return hasResourceBind_; } const std::vector<std::string>& getCompressionMethods() const { return compressionMethods_; } void addCompressionMethod(const std::string& mechanism) { compressionMethods_.push_back(mechanism); diff --git a/Swiften/Elements/StreamManagementEnabled.h b/Swiften/Elements/StreamManagementEnabled.h index 0985574..bb1f858 100644 --- a/Swiften/Elements/StreamManagementEnabled.h +++ b/Swiften/Elements/StreamManagementEnabled.h @@ -1,40 +1,40 @@ /* - * Copyright (c) 2010-2011 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <string> #include <Swiften/Base/API.h> -#include <Swiften/Elements/Element.h> +#include <Swiften/Elements/ToplevelElement.h> namespace Swift { - class SWIFTEN_API StreamManagementEnabled : public Element { + class SWIFTEN_API StreamManagementEnabled : public ToplevelElement { public: StreamManagementEnabled(); ~StreamManagementEnabled(); void setResumeSupported() { resumeSupported = true; } bool getResumeSupported() const { return resumeSupported; } void setResumeID(const std::string& id) { resumeID = id; } const std::string& getResumeID() const { return resumeID; } private: bool resumeSupported; std::string resumeID; }; } diff --git a/Swiften/Elements/StreamManagementFailed.h b/Swiften/Elements/StreamManagementFailed.h index 7c6d1b7..a90bddd 100644 --- a/Swiften/Elements/StreamManagementFailed.h +++ b/Swiften/Elements/StreamManagementFailed.h @@ -1,17 +1,17 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once -#include <Swiften/Elements/Element.h> +#include <Swiften/Elements/ToplevelElement.h> namespace Swift { - class StreamManagementFailed : public Element { + class StreamManagementFailed : public ToplevelElement { public: StreamManagementFailed() {} }; } diff --git a/Swiften/Elements/StreamResume.h b/Swiften/Elements/StreamResume.h index aec0909..e87dabb 100644 --- a/Swiften/Elements/StreamResume.h +++ b/Swiften/Elements/StreamResume.h @@ -1,40 +1,40 @@ /* - * Copyright (c) 2011 Remko Tronçon + * Copyright (c) 2011-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <string> #include <boost/optional.hpp> -#include <Swiften/Elements/Element.h> +#include <Swiften/Elements/ToplevelElement.h> namespace Swift { - class StreamResume : public Element { + class StreamResume : public ToplevelElement { public: StreamResume(); ~StreamResume(); void setResumeID(const std::string& id) { resumeID = id; } const std::string& getResumeID() const { return resumeID; } const boost::optional<unsigned int> getHandledStanzasCount() const { return handledStanzasCount; } void setHandledStanzasCount(unsigned int i) { handledStanzasCount = i; } private: std::string resumeID; boost::optional<unsigned int> handledStanzasCount; }; } diff --git a/Swiften/Elements/StreamResumed.h b/Swiften/Elements/StreamResumed.h index cf9a755..7890901 100644 --- a/Swiften/Elements/StreamResumed.h +++ b/Swiften/Elements/StreamResumed.h @@ -1,40 +1,40 @@ /* - * Copyright (c) 2011 Remko Tronçon + * Copyright (c) 2011-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <string> #include <boost/optional.hpp> -#include <Swiften/Elements/Element.h> +#include <Swiften/Elements/ToplevelElement.h> namespace Swift { - class StreamResumed : public Element { + class StreamResumed : public ToplevelElement { public: StreamResumed(); ~StreamResumed(); void setResumeID(const std::string& id) { resumeID = id; } const std::string& getResumeID() const { return resumeID; } const boost::optional<unsigned int> getHandledStanzasCount() const { return handledStanzasCount; } void setHandledStanzasCount(unsigned int i) { handledStanzasCount = i; } private: std::string resumeID; boost::optional<unsigned int> handledStanzasCount; }; } diff --git a/Swiften/Elements/TLSProceed.h b/Swiften/Elements/TLSProceed.h index 4bd790a..27faf26 100644 --- a/Swiften/Elements/TLSProceed.h +++ b/Swiften/Elements/TLSProceed.h @@ -1,16 +1,16 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once -#include <Swiften/Elements/Element.h> +#include <Swiften/Elements/ToplevelElement.h> namespace Swift { - class TLSProceed : public Element { + class TLSProceed : public ToplevelElement { public: TLSProceed() {} }; } diff --git a/Swiften/Elements/Element.cpp b/Swiften/Elements/ToplevelElement.cpp index 94829ba..c58a914 100644 --- a/Swiften/Elements/Element.cpp +++ b/Swiften/Elements/ToplevelElement.cpp @@ -1,14 +1,14 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ -#include <Swiften/Elements/Element.h> +#include <Swiften/Elements/ToplevelElement.h> namespace Swift { -Element::~Element() { +ToplevelElement::~ToplevelElement() { } } diff --git a/Swiften/Elements/Element.h b/Swiften/Elements/ToplevelElement.h index 14539c1..b3f60c7 100644 --- a/Swiften/Elements/Element.h +++ b/Swiften/Elements/ToplevelElement.h @@ -1,18 +1,18 @@ /* * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <Swiften/Base/API.h> namespace Swift { - class SWIFTEN_API Element { + class SWIFTEN_API ToplevelElement { public: - Element() {} - SWIFTEN_DEFAULT_COPY_CONSTRUCTOR(Element) - virtual ~Element(); + ToplevelElement() {} + SWIFTEN_DEFAULT_COPY_CONSTRUCTOR(ToplevelElement) + virtual ~ToplevelElement(); }; } diff --git a/Swiften/Elements/UnknownElement.h b/Swiften/Elements/UnknownElement.h index 100ba92..48072ef 100644 --- a/Swiften/Elements/UnknownElement.h +++ b/Swiften/Elements/UnknownElement.h @@ -1,16 +1,16 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once -#include <Swiften/Elements/Element.h> +#include <Swiften/Elements/ToplevelElement.h> namespace Swift { - class UnknownElement : public Element { + class UnknownElement : public ToplevelElement { public: UnknownElement() {} }; } diff --git a/Swiften/Examples/ParserTester/ParserTester.cpp b/Swiften/Examples/ParserTester/ParserTester.cpp index 009eef4..5ce44ef 100644 --- a/Swiften/Examples/ParserTester/ParserTester.cpp +++ b/Swiften/Examples/ParserTester/ParserTester.cpp @@ -1,59 +1,59 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #include <iostream> #include <fstream> #include <typeinfo> #include <Swiften/Parser/UnitTest/ParserTester.h> #include <Swiften/Parser/XMPPParser.h> #include <Swiften/Parser/XMPPParserClient.h> #include <Swiften/Parser/PlatformXMLParserFactory.h> #include <Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h> using namespace Swift; class MyXMPPParserClient : public XMPPParserClient { public: virtual void handleStreamStart(const ProtocolHeader&) { std::cout << "-> Stream start" << std::endl; } - virtual void handleElement(boost::shared_ptr<Element> element) { + virtual void handleElement(boost::shared_ptr<ToplevelElement> element) { std::cout << "-> Element " << typeid(*element.get()).name() << std::endl; } virtual void handleStreamEnd() { std::cout << "-> Stream end" << std::endl; } }; int main(int argc, char* argv[]) { if (argc != 2) { std::cerr << "Usage: " << argv[0] << " file" << std::endl; return 0; } FullPayloadParserFactoryCollection factories; MyXMPPParserClient parserClient; PlatformXMLParserFactory xmlParserFactory; XMPPParser parser(&parserClient, &factories, &xmlParserFactory); ParserTester<XMLParserClient> tester(&parser); std::string line; std::ifstream myfile (argv[1]); if (myfile.is_open()) { while (!myfile.eof()) { getline (myfile,line); std::cout << "Parsing: " << line << std::endl; if (!tester.parse(line)) { std::cerr << "PARSE ERROR" << std::endl; return -1; } } myfile.close(); } else { std::cerr << "Unable to open file " << argv[1] << std::endl; } return 0; diff --git a/Swiften/LinkLocal/IncomingLinkLocalSession.cpp b/Swiften/LinkLocal/IncomingLinkLocalSession.cpp index 610b28b..63f3ca1 100644 --- a/Swiften/LinkLocal/IncomingLinkLocalSession.cpp +++ b/Swiften/LinkLocal/IncomingLinkLocalSession.cpp @@ -1,70 +1,70 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #include <Swiften/LinkLocal/IncomingLinkLocalSession.h> #include <boost/bind.hpp> #include <boost/smart_ptr/make_shared.hpp> #include <Swiften/Elements/ProtocolHeader.h> #include <Swiften/Network/Connection.h> #include <Swiften/StreamStack/StreamStack.h> #include <Swiften/StreamStack/ConnectionLayer.h> #include <Swiften/StreamStack/XMPPLayer.h> #include <Swiften/Elements/StreamFeatures.h> #include <Swiften/Elements/IQ.h> namespace Swift { IncomingLinkLocalSession::IncomingLinkLocalSession( const JID& localJID, boost::shared_ptr<Connection> connection, PayloadParserFactoryCollection* payloadParserFactories, PayloadSerializerCollection* payloadSerializers, XMLParserFactory* xmlParserFactory) : Session(connection, payloadParserFactories, payloadSerializers, xmlParserFactory), initialized(false) { setLocalJID(localJID); } void IncomingLinkLocalSession::handleStreamStart(const ProtocolHeader& incomingHeader) { setRemoteJID(JID(incomingHeader.getFrom())); if (!getRemoteJID().isValid()) { finishSession(); return; } ProtocolHeader header; header.setFrom(getLocalJID()); getXMPPLayer()->writeHeader(header); if (incomingHeader.getVersion() == "1.0") { getXMPPLayer()->writeElement(boost::make_shared<StreamFeatures>()); } else { setInitialized(); } } -void IncomingLinkLocalSession::handleElement(boost::shared_ptr<Element> element) { +void IncomingLinkLocalSession::handleElement(boost::shared_ptr<ToplevelElement> element) { boost::shared_ptr<Stanza> stanza = boost::dynamic_pointer_cast<Stanza>(element); // If we get our first stanza before streamfeatures, our session is implicitly // initialized if (stanza && !isInitialized()) { setInitialized(); } onElementReceived(element); } void IncomingLinkLocalSession::setInitialized() { initialized = true; onSessionStarted(); } } diff --git a/Swiften/LinkLocal/IncomingLinkLocalSession.h b/Swiften/LinkLocal/IncomingLinkLocalSession.h index f00c166..e10cd0a 100644 --- a/Swiften/LinkLocal/IncomingLinkLocalSession.h +++ b/Swiften/LinkLocal/IncomingLinkLocalSession.h @@ -1,44 +1,44 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <boost/shared_ptr.hpp> #include <Swiften/Base/boost_bsignals.h> #include <Swiften/Session/Session.h> #include <Swiften/JID/JID.h> #include <Swiften/Network/Connection.h> namespace Swift { class ProtocolHeader; class XMLParserFactory; - class Element; + class ToplevelElement; class PayloadParserFactoryCollection; class PayloadSerializerCollection; class IncomingLinkLocalSession : public Session { public: IncomingLinkLocalSession( const JID& localJID, boost::shared_ptr<Connection> connection, PayloadParserFactoryCollection* payloadParserFactories, PayloadSerializerCollection* payloadSerializers, XMLParserFactory* xmlParserFactory); boost::signal<void ()> onSessionStarted; private: - void handleElement(boost::shared_ptr<Element>); + void handleElement(boost::shared_ptr<ToplevelElement>); void handleStreamStart(const ProtocolHeader&); void setInitialized(); bool isInitialized() const { return initialized; } bool initialized; }; } diff --git a/Swiften/LinkLocal/LinkLocalConnector.cpp b/Swiften/LinkLocal/LinkLocalConnector.cpp index af96e65..6471ca7 100644 --- a/Swiften/LinkLocal/LinkLocalConnector.cpp +++ b/Swiften/LinkLocal/LinkLocalConnector.cpp @@ -1,37 +1,37 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #include <Swiften/LinkLocal/LinkLocalConnector.h> #include <boost/bind.hpp> #include <Swiften/Network/Connection.h> #include <Swiften/Network/ConnectionFactory.h> #include <Swiften/Network/HostAddress.h> #include <Swiften/Network/HostAddressPort.h> #include <Swiften/LinkLocal/DNSSD/DNSSDQuerier.h> #include <Swiften/LinkLocal/DNSSD/DNSSDResolveHostnameQuery.h> namespace Swift { LinkLocalConnector::LinkLocalConnector( const LinkLocalService& service, boost::shared_ptr<DNSSDQuerier> querier, boost::shared_ptr<Connection> connection) : service(service), querier(querier), connection(connection) { } LinkLocalConnector::~LinkLocalConnector() { assert(!resolveQuery); } void LinkLocalConnector::connect() { resolveQuery = querier->createResolveHostnameQuery( service.getHostname(), service.getID().getNetworkInterfaceID()); resolveQueryHostNameResolvedConnection = resolveQuery->onHostnameResolved.connect(boost::bind( @@ -39,41 +39,41 @@ void LinkLocalConnector::connect() { boost::dynamic_pointer_cast<LinkLocalConnector>(shared_from_this()), _1)); resolveQuery->run(); } void LinkLocalConnector::cancel() { if (resolveQuery) { resolveQuery->finish(); resolveQueryHostNameResolvedConnection.disconnect(); resolveQuery.reset(); } connectionConnectFinishedConnection.disconnect(); connection->disconnect(); } void LinkLocalConnector::handleHostnameResolved(const boost::optional<HostAddress>& address) { resolveQuery->finish(); resolveQueryHostNameResolvedConnection.disconnect(); resolveQuery.reset(); if (address) { connectionConnectFinishedConnection = connection->onConnectFinished.connect( boost::bind(&LinkLocalConnector::handleConnected, shared_from_this(), _1)); connection->connect(HostAddressPort(*address, service.getPort())); } else { onConnectFinished(true); } } void LinkLocalConnector::handleConnected(bool error) { onConnectFinished(error); assert(connectionConnectFinishedConnection.connected()); connectionConnectFinishedConnection.disconnect(); } -void LinkLocalConnector::queueElement(boost::shared_ptr<Element> element) { +void LinkLocalConnector::queueElement(boost::shared_ptr<ToplevelElement> element) { queuedElements.push_back(element); } } diff --git a/Swiften/LinkLocal/LinkLocalConnector.h b/Swiften/LinkLocal/LinkLocalConnector.h index 52692ef..367e972 100644 --- a/Swiften/LinkLocal/LinkLocalConnector.h +++ b/Swiften/LinkLocal/LinkLocalConnector.h @@ -1,66 +1,66 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <boost/shared_ptr.hpp> #include <Swiften/Base/boost_bsignals.h> #include <boost/enable_shared_from_this.hpp> #include <vector> #include <Swiften/Base/API.h> #include <Swiften/Network/Connection.h> #include <Swiften/LinkLocal/LinkLocalService.h> namespace Swift { class ConnectionFactory; class HostAddress; - class Element; + class ToplevelElement; class PayloadParserFactoryCollection; class PayloadSerializerCollection; class DNSSDQuerier; class DNSSDResolveHostnameQuery; class SWIFTEN_API LinkLocalConnector : public boost::enable_shared_from_this<LinkLocalConnector> { public: LinkLocalConnector( const LinkLocalService& service, boost::shared_ptr<DNSSDQuerier> querier, boost::shared_ptr<Connection> connection); ~LinkLocalConnector(); const LinkLocalService& getService() const { return service; } void connect(); void cancel(); - void queueElement(boost::shared_ptr<Element> element); + void queueElement(boost::shared_ptr<ToplevelElement> element); - const std::vector<boost::shared_ptr<Element> >& getQueuedElements() const { + const std::vector<boost::shared_ptr<ToplevelElement> >& getQueuedElements() const { return queuedElements; } boost::shared_ptr<Connection> getConnection() const { return connection; } boost::signal<void (bool)> onConnectFinished; private: void handleHostnameResolved(const boost::optional<HostAddress>& address); void handleConnected(bool error); private: LinkLocalService service; boost::shared_ptr<DNSSDQuerier> querier; boost::shared_ptr<DNSSDResolveHostnameQuery> resolveQuery; boost::bsignals::connection resolveQueryHostNameResolvedConnection; boost::shared_ptr<Connection> connection; boost::bsignals::connection connectionConnectFinishedConnection; - std::vector<boost::shared_ptr<Element> > queuedElements; + std::vector<boost::shared_ptr<ToplevelElement> > queuedElements; }; } diff --git a/Swiften/LinkLocal/OutgoingLinkLocalSession.cpp b/Swiften/LinkLocal/OutgoingLinkLocalSession.cpp index 7a59715..1d280ef 100644 --- a/Swiften/LinkLocal/OutgoingLinkLocalSession.cpp +++ b/Swiften/LinkLocal/OutgoingLinkLocalSession.cpp @@ -1,53 +1,53 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #include <Swiften/LinkLocal/OutgoingLinkLocalSession.h> #include <boost/bind.hpp> #include <Swiften/Base/foreach.h> #include <Swiften/StreamStack/XMPPLayer.h> #include <Swiften/Elements/ProtocolHeader.h> #include <Swiften/Elements/StreamFeatures.h> #include <Swiften/Elements/IQ.h> namespace Swift { OutgoingLinkLocalSession::OutgoingLinkLocalSession( const JID& localJID, const JID& remoteJID, boost::shared_ptr<Connection> connection, PayloadParserFactoryCollection* payloadParserFactories, PayloadSerializerCollection* payloadSerializers, XMLParserFactory* xmlParserFactory) : Session(connection, payloadParserFactories, payloadSerializers, xmlParserFactory) { setLocalJID(localJID); setRemoteJID(remoteJID); } void OutgoingLinkLocalSession::handleSessionStarted() { ProtocolHeader header; header.setFrom(getLocalJID()); getXMPPLayer()->writeHeader(header); } void OutgoingLinkLocalSession::handleStreamStart(const ProtocolHeader&) { - foreach(const boost::shared_ptr<Element>& stanza, queuedElements_) { + foreach(const boost::shared_ptr<ToplevelElement>& stanza, queuedElements_) { sendElement(stanza); } queuedElements_.clear(); } -void OutgoingLinkLocalSession::handleElement(boost::shared_ptr<Element> element) { +void OutgoingLinkLocalSession::handleElement(boost::shared_ptr<ToplevelElement> element) { onElementReceived(element); } -void OutgoingLinkLocalSession::queueElement(boost::shared_ptr<Element> element) { +void OutgoingLinkLocalSession::queueElement(boost::shared_ptr<ToplevelElement> element) { queuedElements_.push_back(element); } } diff --git a/Swiften/LinkLocal/OutgoingLinkLocalSession.h b/Swiften/LinkLocal/OutgoingLinkLocalSession.h index b97f2bf..4550ae4 100644 --- a/Swiften/LinkLocal/OutgoingLinkLocalSession.h +++ b/Swiften/LinkLocal/OutgoingLinkLocalSession.h @@ -1,44 +1,44 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <boost/shared_ptr.hpp> #include <Swiften/Base/boost_bsignals.h> #include <boost/enable_shared_from_this.hpp> #include <vector> #include <Swiften/Session/Session.h> #include <Swiften/JID/JID.h> namespace Swift { class ConnectionFactory; class XMLParserFactory; - class Element; + class ToplevelElement; class PayloadParserFactoryCollection; class PayloadSerializerCollection; class OutgoingLinkLocalSession : public Session { public: OutgoingLinkLocalSession( const JID& localJID, const JID& remoteJID, boost::shared_ptr<Connection> connection, PayloadParserFactoryCollection* payloadParserFactories, PayloadSerializerCollection* payloadSerializers, XMLParserFactory* xmlParserFactory); - void queueElement(boost::shared_ptr<Element> element); + void queueElement(boost::shared_ptr<ToplevelElement> element); private: void handleSessionStarted(); - void handleElement(boost::shared_ptr<Element>); + void handleElement(boost::shared_ptr<ToplevelElement>); void handleStreamStart(const ProtocolHeader&); private: - std::vector<boost::shared_ptr<Element> > queuedElements_; + std::vector<boost::shared_ptr<ToplevelElement> > queuedElements_; }; } diff --git a/Swiften/Parser/ElementParser.h b/Swiften/Parser/ElementParser.h index 1815240..256e2dc 100644 --- a/Swiften/Parser/ElementParser.h +++ b/Swiften/Parser/ElementParser.h @@ -1,27 +1,27 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <boost/shared_ptr.hpp> #include <string> #include <Swiften/Base/API.h> -#include <Swiften/Elements/Element.h> +#include <Swiften/Elements/ToplevelElement.h> #include <Swiften/Parser/AttributeMap.h> namespace Swift { class SWIFTEN_API ElementParser { public: virtual ~ElementParser(); virtual void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) = 0; virtual void handleEndElement(const std::string& element, const std::string& ns) = 0; virtual void handleCharacterData(const std::string& data) = 0; - virtual boost::shared_ptr<Element> getElement() const = 0; + virtual boost::shared_ptr<ToplevelElement> getElement() const = 0; }; } diff --git a/Swiften/Parser/GenericElementParser.h b/Swiften/Parser/GenericElementParser.h index 224c59e..4395622 100644 --- a/Swiften/Parser/GenericElementParser.h +++ b/Swiften/Parser/GenericElementParser.h @@ -1,46 +1,46 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <boost/shared_ptr.hpp> #include <boost/smart_ptr/make_shared.hpp> #include <Swiften/Parser/ElementParser.h> namespace Swift { class PayloadParserFactoryCollection; template<typename ElementType> class GenericElementParser : public ElementParser { public: GenericElementParser() { stanza_ = boost::make_shared<ElementType>(); } - virtual boost::shared_ptr<Element> getElement() const { + virtual boost::shared_ptr<ToplevelElement> getElement() const { return stanza_; } virtual boost::shared_ptr<ElementType> getElementGeneric() const { return stanza_; } private: virtual void handleStartElement(const std::string&, const std::string&, const AttributeMap&) { } virtual void handleEndElement(const std::string&, const std::string&) { } virtual void handleCharacterData(const std::string&) { } private: boost::shared_ptr<ElementType> stanza_; }; } diff --git a/Swiften/Parser/GenericStanzaParser.h b/Swiften/Parser/GenericStanzaParser.h index c756c9a..2aff4d5 100644 --- a/Swiften/Parser/GenericStanzaParser.h +++ b/Swiften/Parser/GenericStanzaParser.h @@ -1,37 +1,37 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <boost/shared_ptr.hpp> #include <boost/smart_ptr/make_shared.hpp> #include <Swiften/Parser/StanzaParser.h> namespace Swift { class PayloadParserFactoryCollection; template<typename STANZA_TYPE> class GenericStanzaParser : public StanzaParser { public: GenericStanzaParser(PayloadParserFactoryCollection* collection) : StanzaParser(collection) { stanza_ = boost::make_shared<STANZA_TYPE>(); } - virtual boost::shared_ptr<Element> getElement() const { + virtual boost::shared_ptr<ToplevelElement> getElement() const { return stanza_; } virtual boost::shared_ptr<STANZA_TYPE> getStanzaGeneric() const { return stanza_; } private: boost::shared_ptr<STANZA_TYPE> stanza_; }; } diff --git a/Swiften/Parser/StanzaParser.h b/Swiften/Parser/StanzaParser.h index 0af6b43..fc60b47 100644 --- a/Swiften/Parser/StanzaParser.h +++ b/Swiften/Parser/StanzaParser.h @@ -1,53 +1,53 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <boost/noncopyable.hpp> #include <boost/shared_ptr.hpp> #include <Swiften/Base/API.h> #include <string> #include <Swiften/Elements/Stanza.h> #include <Swiften/Parser/ElementParser.h> #include <Swiften/Parser/AttributeMap.h> namespace Swift { class PayloadParser; class PayloadParserFactoryCollection; class SWIFTEN_API StanzaParser : public ElementParser, public boost::noncopyable { public: StanzaParser(PayloadParserFactoryCollection* factories); ~StanzaParser(); void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes); void handleEndElement(const std::string& element, const std::string& ns); void handleCharacterData(const std::string& data); - virtual boost::shared_ptr<Element> getElement() const = 0; + virtual boost::shared_ptr<ToplevelElement> getElement() const = 0; virtual void handleStanzaAttributes(const AttributeMap&) {} virtual boost::shared_ptr<Stanza> getStanza() const { return boost::dynamic_pointer_cast<Stanza>(getElement()); } private: bool inPayload() const { return currentDepth_ > 1; } bool inStanza() const { return currentDepth_ > 0; } private: int currentDepth_; PayloadParserFactoryCollection* factories_; boost::shared_ptr<PayloadParser> currentPayloadParser_; }; } diff --git a/Swiften/Parser/UnitTest/StanzaParserTest.cpp b/Swiften/Parser/UnitTest/StanzaParserTest.cpp index 88e6dec..020f0ca 100644 --- a/Swiften/Parser/UnitTest/StanzaParserTest.cpp +++ b/Swiften/Parser/UnitTest/StanzaParserTest.cpp @@ -1,37 +1,37 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> #include <Swiften/Parser/StanzaParser.h> #include <Swiften/Parser/GenericPayloadParser.h> #include <Swiften/Parser/PayloadParserFactory.h> #include <Swiften/Parser/PayloadParserFactoryCollection.h> #include <Swiften/Elements/Stanza.h> #include <Swiften/Elements/Payload.h> using namespace Swift; class StanzaParserTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(StanzaParserTest); CPPUNIT_TEST(testHandleEndElement_OnePayload); CPPUNIT_TEST(testHandleEndElement_MultiplePayloads); CPPUNIT_TEST(testHandleEndElement_StrayCharacterData); CPPUNIT_TEST(testHandleEndElement_UnknownPayload); CPPUNIT_TEST(testHandleParse_BasicAttributes); CPPUNIT_TEST_SUITE_END(); public: void setUp() { factoryCollection_ = new PayloadParserFactoryCollection(); factoryCollection_->addFactory(&factory1_); factoryCollection_->addFactory(&factory2_); } void tearDown() { delete factoryCollection_; } @@ -164,49 +164,49 @@ class StanzaParserTest : public CppUnit::TestFixture { { public: MyPayload2Parser() {} virtual void handleStartElement(const std::string&, const std::string&, const AttributeMap&) {} virtual void handleEndElement(const std::string&, const std::string&) {} virtual void handleCharacterData(const std::string&) {} }; class MyPayload2ParserFactory : public PayloadParserFactory { public: MyPayload2ParserFactory() {} PayloadParser* createPayloadParser() { return new MyPayload2Parser(); } bool canParse(const std::string& element, const std::string&, const AttributeMap&) const { return element == "mypayload2"; } }; class MyStanza : public Stanza { public: MyStanza() {} }; class MyStanzaParser : public StanzaParser { public: MyStanzaParser(PayloadParserFactoryCollection* collection) : StanzaParser(collection) { stanza_ = boost::make_shared<MyStanza>(); } - virtual boost::shared_ptr<Element> getElement() const { + virtual boost::shared_ptr<ToplevelElement> getElement() const { return stanza_; } private: boost::shared_ptr<MyStanza> stanza_; }; MyPayload1ParserFactory factory1_; MyPayload2ParserFactory factory2_; PayloadParserFactoryCollection* factoryCollection_; }; CPPUNIT_TEST_SUITE_REGISTRATION(StanzaParserTest); diff --git a/Swiften/Parser/UnitTest/XMPPParserTest.cpp b/Swiften/Parser/UnitTest/XMPPParserTest.cpp index f8d60f2..7d2d3fa 100644 --- a/Swiften/Parser/UnitTest/XMPPParserTest.cpp +++ b/Swiften/Parser/UnitTest/XMPPParserTest.cpp @@ -1,37 +1,37 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> #include <vector> #include <Swiften/Elements/ProtocolHeader.h> #include <string> #include <Swiften/Parser/XMPPParser.h> #include <Swiften/Parser/ElementParser.h> #include <Swiften/Parser/XMPPParserClient.h> #include <Swiften/Parser/PayloadParserFactoryCollection.h> #include <Swiften/Parser/PlatformXMLParserFactory.h> #include <Swiften/Elements/Presence.h> #include <Swiften/Elements/IQ.h> #include <Swiften/Elements/Message.h> #include <Swiften/Elements/StreamFeatures.h> #include <Swiften/Elements/UnknownElement.h> using namespace Swift; class XMPPParserTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(XMPPParserTest); CPPUNIT_TEST(testParse_SimpleSession); CPPUNIT_TEST(testParse_SimpleClientFromServerSession); CPPUNIT_TEST(testParse_Presence); CPPUNIT_TEST(testParse_IQ); CPPUNIT_TEST(testParse_Message); CPPUNIT_TEST(testParse_StreamFeatures); CPPUNIT_TEST(testParse_UnknownElement); CPPUNIT_TEST(testParse_StrayCharacterData); CPPUNIT_TEST(testParse_InvalidStreamStart); CPPUNIT_TEST(testParse_ElementEndAfterInvalidStreamStart); @@ -130,67 +130,67 @@ class XMPPParserTest : public CppUnit::TestFixture { CPPUNIT_ASSERT(dynamic_cast<UnknownElement*>(client_.events[3].element.get())); CPPUNIT_ASSERT_EQUAL(Client::ElementEvent, client_.events[4].type); CPPUNIT_ASSERT(dynamic_cast<Presence*>(client_.events[4].element.get())); } void testParse_StrayCharacterData() { XMPPParser testling(&client_, &factories_, &xmlParserFactory_); CPPUNIT_ASSERT(testling.parse("<stream:stream xmlns:stream='http://etherx.jabber.org/streams'>")); CPPUNIT_ASSERT(testling.parse("<presence/>")); CPPUNIT_ASSERT(testling.parse("bla")); CPPUNIT_ASSERT(testling.parse("<iq/>")); CPPUNIT_ASSERT_EQUAL(3, static_cast<int>(client_.events.size())); CPPUNIT_ASSERT_EQUAL(Client::ElementEvent, client_.events[2].type); CPPUNIT_ASSERT(dynamic_cast<IQ*>(client_.events[2].element.get())); } void testParse_InvalidStreamStart() { XMPPParser testling(&client_, &factories_, &xmlParserFactory_); CPPUNIT_ASSERT(!testling.parse("<tream>")); } void testParse_ElementEndAfterInvalidStreamStart() { XMPPParser testling(&client_, &factories_, &xmlParserFactory_); CPPUNIT_ASSERT(!testling.parse("<tream/>")); } private: class Client : public XMPPParserClient { public: enum Type { StreamStart, ElementEvent, StreamEnd }; struct Event { - Event(Type type, boost::shared_ptr<Element> element) + Event(Type type, boost::shared_ptr<ToplevelElement> element) : type(type), element(element) {} Event(Type type, const ProtocolHeader& header) : type(type), header(header) {} Event(Type type) : type(type) {} Type type; boost::optional<ProtocolHeader> header; - boost::shared_ptr<Element> element; + boost::shared_ptr<ToplevelElement> element; }; Client() {} void handleStreamStart(const ProtocolHeader& header) { events.push_back(Event(StreamStart, header)); } - void handleElement(boost::shared_ptr<Element> element) { + void handleElement(boost::shared_ptr<ToplevelElement> element) { events.push_back(Event(ElementEvent, element)); } void handleStreamEnd() { events.push_back(Event(StreamEnd)); } std::vector<Event> events; } client_; PayloadParserFactoryCollection factories_; PlatformXMLParserFactory xmlParserFactory_; }; CPPUNIT_TEST_SUITE_REGISTRATION(XMPPParserTest); diff --git a/Swiften/Parser/XMPPParserClient.h b/Swiften/Parser/XMPPParserClient.h index 85e0f86..7d35968 100644 --- a/Swiften/Parser/XMPPParserClient.h +++ b/Swiften/Parser/XMPPParserClient.h @@ -1,26 +1,26 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <boost/shared_ptr.hpp> #include <Swiften/Base/API.h> -#include <Swiften/Elements/Element.h> +#include <Swiften/Elements/ToplevelElement.h> namespace Swift { class ProtocolHeader; class SWIFTEN_API XMPPParserClient { public: virtual ~XMPPParserClient(); virtual void handleStreamStart(const ProtocolHeader&) = 0; - virtual void handleElement(boost::shared_ptr<Element>) = 0; + virtual void handleElement(boost::shared_ptr<ToplevelElement>) = 0; virtual void handleStreamEnd() = 0; }; } diff --git a/Swiften/SConscript b/Swiften/SConscript index 574b7d8..d898bfa 100644 --- a/Swiften/SConscript +++ b/Swiften/SConscript @@ -90,71 +90,71 @@ if env["SCONS_STAGE"] == "build" : swiften_env.UseFlags(swiften_env["PLATFORM_FLAGS"]) if swiften_env["SWIFTEN_DLL"] : swiften_env.AddMethod(lambda e,l,o : e.SharedLibrary(l,o), "SwiftenLibrary") else : swiften_env.Append(CPPDEFINES = ["SWIFTEN_STATIC"]) swiften_env.AddMethod(lambda e,l,o : e.StaticLibrary(l,o), "SwiftenLibrary") Export("swiften_env") # TODO: Move all this to a submodule SConscript sources = [ "Chat/ChatStateTracker.cpp", "Chat/ChatStateNotifier.cpp", "Client/ClientSessionStanzaChannel.cpp", "Client/CoreClient.cpp", "Client/Client.cpp", "Client/ClientXMLTracer.cpp", "Client/ClientSession.cpp", "Client/BlockList.cpp", "Client/BlockListImpl.cpp", "Client/ClientBlockListManager.cpp", "Client/MemoryStorages.cpp", "Client/NickResolver.cpp", "Client/NickManager.cpp", "Client/NickManagerImpl.cpp", "Client/Storages.cpp", "Client/XMLBeautifier.cpp", "Compress/ZLibCodecompressor.cpp", "Compress/ZLibDecompressor.cpp", "Compress/ZLibCompressor.cpp", "Elements/DiscoInfo.cpp", "Elements/Presence.cpp", "Elements/Form.cpp", "Elements/FormField.cpp", "Elements/StreamFeatures.cpp", - "Elements/Element.cpp", + "Elements/ToplevelElement.cpp", "Elements/IQ.cpp", "Elements/Payload.cpp", "Elements/PubSubPayload.cpp", "Elements/PubSubOwnerPayload.cpp", "Elements/PubSubEventPayload.cpp", "Elements/RosterItemExchangePayload.cpp", "Elements/RosterPayload.cpp", "Elements/SecurityLabel.cpp", "Elements/Stanza.cpp", "Elements/StanzaAck.cpp", "Elements/StatusShow.cpp", "Elements/StreamManagementEnabled.cpp", "Elements/StreamResume.cpp", "Elements/StreamResumed.cpp", "Elements/UserLocation.cpp", "Elements/UserTune.cpp", "Elements/VCard.cpp", "Elements/MUCOccupant.cpp", "Elements/ResultSet.cpp", "Elements/Forwarded.cpp", "Elements/MAMResult.cpp", "Elements/MAMQuery.cpp", "Elements/MAMArchived.cpp", "Entity/Entity.cpp", "Entity/PayloadPersister.cpp", "MUC/MUC.cpp", "MUC/MUCImpl.cpp", "MUC/MUCManager.cpp", "MUC/MUCRegistry.cpp", "MUC/MUCBookmarkManager.cpp", "PubSub/PubSubManager.cpp", "PubSub/PubSubManagerImpl.cpp", "Queries/IQChannel.cpp", "Queries/IQHandler.cpp", "Queries/IQRouter.cpp", diff --git a/Swiften/Serializer/AuthChallengeSerializer.cpp b/Swiften/Serializer/AuthChallengeSerializer.cpp index 1ddc165..57a79e0 100644 --- a/Swiften/Serializer/AuthChallengeSerializer.cpp +++ b/Swiften/Serializer/AuthChallengeSerializer.cpp @@ -1,33 +1,33 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #include <Swiften/Serializer/AuthChallengeSerializer.h> #include <Swiften/Elements/AuthChallenge.h> #include <Swiften/StringCodecs/Base64.h> #include <Swiften/Base/ByteArray.h> namespace Swift { AuthChallengeSerializer::AuthChallengeSerializer() { } -SafeByteArray AuthChallengeSerializer::serialize(boost::shared_ptr<Element> element) const { +SafeByteArray AuthChallengeSerializer::serialize(boost::shared_ptr<ToplevelElement> element) const { boost::shared_ptr<AuthChallenge> authChallenge(boost::dynamic_pointer_cast<AuthChallenge>(element)); std::string value; boost::optional<std::vector<unsigned char> > message = authChallenge->getValue(); if (message) { if ((*message).empty()) { value = "="; } else { value = Base64::encode(ByteArray(*message)); } } return createSafeByteArray("<challenge xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">" + value + "</challenge>"); } } diff --git a/Swiften/Serializer/AuthChallengeSerializer.h b/Swiften/Serializer/AuthChallengeSerializer.h index 7d0b1b8..af77a5e 100644 --- a/Swiften/Serializer/AuthChallengeSerializer.h +++ b/Swiften/Serializer/AuthChallengeSerializer.h @@ -1,22 +1,22 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <boost/shared_ptr.hpp> #include <Swiften/Base/API.h> #include <Swiften/Elements/AuthChallenge.h> #include <Swiften/Serializer/GenericElementSerializer.h> namespace Swift { class SWIFTEN_API AuthChallengeSerializer : public GenericElementSerializer<AuthChallenge> { public: AuthChallengeSerializer(); - virtual SafeByteArray serialize(boost::shared_ptr<Element> element) const; + virtual SafeByteArray serialize(boost::shared_ptr<ToplevelElement> element) const; }; } diff --git a/Swiften/Serializer/AuthFailureSerializer.h b/Swiften/Serializer/AuthFailureSerializer.h index 090f0c4..f7e48f0 100644 --- a/Swiften/Serializer/AuthFailureSerializer.h +++ b/Swiften/Serializer/AuthFailureSerializer.h @@ -1,25 +1,25 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <boost/shared_ptr.hpp> #include <Swiften/Elements/AuthFailure.h> #include <Swiften/Serializer/GenericElementSerializer.h> #include <Swiften/Serializer/XML/XMLElement.h> namespace Swift { class AuthFailureSerializer : public GenericElementSerializer<AuthFailure> { public: AuthFailureSerializer() : GenericElementSerializer<AuthFailure>() { } - virtual SafeByteArray serialize(boost::shared_ptr<Element>) const { + virtual SafeByteArray serialize(boost::shared_ptr<ToplevelElement>) const { return createSafeByteArray(XMLElement("failure", "urn:ietf:params:xml:ns:xmpp-sasl").serialize()); } }; } diff --git a/Swiften/Serializer/AuthRequestSerializer.cpp b/Swiften/Serializer/AuthRequestSerializer.cpp index 7f25c93..5c78e48 100644 --- a/Swiften/Serializer/AuthRequestSerializer.cpp +++ b/Swiften/Serializer/AuthRequestSerializer.cpp @@ -1,34 +1,34 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #include <Swiften/Serializer/AuthRequestSerializer.h> #include <Swiften/Elements/AuthRequest.h> #include <Swiften/StringCodecs/Base64.h> #include <Swiften/Base/SafeByteArray.h> #include <Swiften/Base/Concat.h> namespace Swift { AuthRequestSerializer::AuthRequestSerializer() { } -SafeByteArray AuthRequestSerializer::serialize(boost::shared_ptr<Element> element) const { +SafeByteArray AuthRequestSerializer::serialize(boost::shared_ptr<ToplevelElement> element) const { boost::shared_ptr<AuthRequest> authRequest(boost::dynamic_pointer_cast<AuthRequest>(element)); SafeByteArray value; boost::optional<SafeByteArray> message = authRequest->getMessage(); if (message) { if ((*message).empty()) { value = createSafeByteArray("="); } else { value = Base64::encode(*message); } } return concat(createSafeByteArray("<auth xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\" mechanism=\"" + authRequest->getMechanism() + "\">"), value, createSafeByteArray("</auth>")); } } diff --git a/Swiften/Serializer/AuthRequestSerializer.h b/Swiften/Serializer/AuthRequestSerializer.h index 0b49384..45c2ff8 100644 --- a/Swiften/Serializer/AuthRequestSerializer.h +++ b/Swiften/Serializer/AuthRequestSerializer.h @@ -1,22 +1,22 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <boost/shared_ptr.hpp> #include <Swiften/Base/API.h> #include <Swiften/Elements/AuthRequest.h> #include <Swiften/Serializer/GenericElementSerializer.h> namespace Swift { class SWIFTEN_API AuthRequestSerializer : public GenericElementSerializer<AuthRequest> { public: AuthRequestSerializer(); - virtual SafeByteArray serialize(boost::shared_ptr<Element> element) const; + virtual SafeByteArray serialize(boost::shared_ptr<ToplevelElement> element) const; }; } diff --git a/Swiften/Serializer/AuthResponseSerializer.cpp b/Swiften/Serializer/AuthResponseSerializer.cpp index 86b7fbe..c04fed0 100644 --- a/Swiften/Serializer/AuthResponseSerializer.cpp +++ b/Swiften/Serializer/AuthResponseSerializer.cpp @@ -1,34 +1,34 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #include <Swiften/Serializer/AuthResponseSerializer.h> #include <Swiften/Elements/AuthResponse.h> #include <Swiften/StringCodecs/Base64.h> #include <Swiften/Base/SafeByteArray.h> #include <Swiften/Base/Concat.h> namespace Swift { AuthResponseSerializer::AuthResponseSerializer() { } -SafeByteArray AuthResponseSerializer::serialize(boost::shared_ptr<Element> element) const { +SafeByteArray AuthResponseSerializer::serialize(boost::shared_ptr<ToplevelElement> element) const { boost::shared_ptr<AuthResponse> authResponse(boost::dynamic_pointer_cast<AuthResponse>(element)); SafeByteArray value; boost::optional<SafeByteArray> message = authResponse->getValue(); if (message) { if ((*message).empty()) { value = createSafeByteArray("="); } else { value = Base64::encode(*message); } } return concat(createSafeByteArray("<response xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">"), value, createSafeByteArray("</response>")); } } diff --git a/Swiften/Serializer/AuthResponseSerializer.h b/Swiften/Serializer/AuthResponseSerializer.h index af71f59..9c9ae74 100644 --- a/Swiften/Serializer/AuthResponseSerializer.h +++ b/Swiften/Serializer/AuthResponseSerializer.h @@ -1,22 +1,22 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <boost/shared_ptr.hpp> #include <Swiften/Base/API.h> #include <Swiften/Elements/AuthResponse.h> #include <Swiften/Serializer/GenericElementSerializer.h> namespace Swift { class SWIFTEN_API AuthResponseSerializer : public GenericElementSerializer<AuthResponse> { public: AuthResponseSerializer(); - virtual SafeByteArray serialize(boost::shared_ptr<Element> element) const; + virtual SafeByteArray serialize(boost::shared_ptr<ToplevelElement> element) const; }; } diff --git a/Swiften/Serializer/AuthSuccessSerializer.cpp b/Swiften/Serializer/AuthSuccessSerializer.cpp index 26b58c3..0f4ef6e 100644 --- a/Swiften/Serializer/AuthSuccessSerializer.cpp +++ b/Swiften/Serializer/AuthSuccessSerializer.cpp @@ -1,33 +1,33 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #include <Swiften/Serializer/AuthSuccessSerializer.h> #include <Swiften/Elements/AuthSuccess.h> #include <Swiften/StringCodecs/Base64.h> #include <Swiften/Base/ByteArray.h> namespace Swift { AuthSuccessSerializer::AuthSuccessSerializer() { } -SafeByteArray AuthSuccessSerializer::serialize(boost::shared_ptr<Element> element) const { +SafeByteArray AuthSuccessSerializer::serialize(boost::shared_ptr<ToplevelElement> element) const { boost::shared_ptr<AuthSuccess> authSuccess(boost::dynamic_pointer_cast<AuthSuccess>(element)); std::string value; boost::optional<std::vector<unsigned char> > message = authSuccess->getValue(); if (message) { if ((*message).empty()) { value = "="; } else { value = Base64::encode(ByteArray(*message)); } } return createSafeByteArray("<success xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">" + value + "</success>"); } } diff --git a/Swiften/Serializer/AuthSuccessSerializer.h b/Swiften/Serializer/AuthSuccessSerializer.h index 370afaa..7aa934e 100644 --- a/Swiften/Serializer/AuthSuccessSerializer.h +++ b/Swiften/Serializer/AuthSuccessSerializer.h @@ -1,22 +1,22 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <boost/shared_ptr.hpp> #include <Swiften/Base/API.h> #include <Swiften/Elements/AuthSuccess.h> #include <Swiften/Serializer/GenericElementSerializer.h> namespace Swift { class SWIFTEN_API AuthSuccessSerializer : public GenericElementSerializer<AuthSuccess> { public: AuthSuccessSerializer(); - virtual SafeByteArray serialize(boost::shared_ptr<Element> element) const; + virtual SafeByteArray serialize(boost::shared_ptr<ToplevelElement> element) const; }; } diff --git a/Swiften/Serializer/ComponentHandshakeSerializer.cpp b/Swiften/Serializer/ComponentHandshakeSerializer.cpp index e7837d3..123798c 100644 --- a/Swiften/Serializer/ComponentHandshakeSerializer.cpp +++ b/Swiften/Serializer/ComponentHandshakeSerializer.cpp @@ -1,21 +1,21 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #include <Swiften/Serializer/ComponentHandshakeSerializer.h> #include <Swiften/Elements/ComponentHandshake.h> namespace Swift { ComponentHandshakeSerializer::ComponentHandshakeSerializer() { } -SafeByteArray ComponentHandshakeSerializer::serialize(boost::shared_ptr<Element> element) const { +SafeByteArray ComponentHandshakeSerializer::serialize(boost::shared_ptr<ToplevelElement> element) const { boost::shared_ptr<ComponentHandshake> handshake(boost::dynamic_pointer_cast<ComponentHandshake>(element)); return createSafeByteArray("<handshake>" + handshake->getData() + "</handshake>"); } } diff --git a/Swiften/Serializer/ComponentHandshakeSerializer.h b/Swiften/Serializer/ComponentHandshakeSerializer.h index 1145ed9..54cd7c8 100644 --- a/Swiften/Serializer/ComponentHandshakeSerializer.h +++ b/Swiften/Serializer/ComponentHandshakeSerializer.h @@ -1,21 +1,21 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <boost/shared_ptr.hpp> #include <Swiften/Elements/ComponentHandshake.h> #include <Swiften/Serializer/GenericElementSerializer.h> namespace Swift { class ComponentHandshakeSerializer : public GenericElementSerializer<ComponentHandshake> { public: ComponentHandshakeSerializer(); - virtual SafeByteArray serialize(boost::shared_ptr<Element> element) const; + virtual SafeByteArray serialize(boost::shared_ptr<ToplevelElement> element) const; }; } diff --git a/Swiften/Serializer/CompressFailureSerializer.h b/Swiften/Serializer/CompressFailureSerializer.h index 27a638f..2545608 100644 --- a/Swiften/Serializer/CompressFailureSerializer.h +++ b/Swiften/Serializer/CompressFailureSerializer.h @@ -1,25 +1,25 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <boost/shared_ptr.hpp> #include <Swiften/Elements/CompressFailure.h> #include <Swiften/Serializer/GenericElementSerializer.h> #include <Swiften/Serializer/XML/XMLElement.h> namespace Swift { class CompressFailureSerializer : public GenericElementSerializer<CompressFailure> { public: CompressFailureSerializer() : GenericElementSerializer<CompressFailure>() { } - virtual SafeByteArray serialize(boost::shared_ptr<Element>) const { + virtual SafeByteArray serialize(boost::shared_ptr<ToplevelElement>) const { return createSafeByteArray(XMLElement("failure", "http://jabber.org/protocol/compress").serialize()); } }; } diff --git a/Swiften/Serializer/CompressRequestSerializer.cpp b/Swiften/Serializer/CompressRequestSerializer.cpp index af7f7db..38f5b71 100644 --- a/Swiften/Serializer/CompressRequestSerializer.cpp +++ b/Swiften/Serializer/CompressRequestSerializer.cpp @@ -1,25 +1,25 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #include <Swiften/Serializer/CompressRequestSerializer.h> #include <Swiften/Elements/CompressRequest.h> namespace Swift { CompressRequestSerializer::CompressRequestSerializer() { } -SafeByteArray CompressRequestSerializer::serialize(boost::shared_ptr<Element> element) const { +SafeByteArray CompressRequestSerializer::serialize(boost::shared_ptr<ToplevelElement> element) const { boost::shared_ptr<CompressRequest> compressRequest(boost::dynamic_pointer_cast<CompressRequest>(element)); return createSafeByteArray("<compress xmlns='http://jabber.org/protocol/compress'><method>" + compressRequest->getMethod() + "</method></compress>"); } -bool CompressRequestSerializer::canSerialize(boost::shared_ptr<Element> element) const { +bool CompressRequestSerializer::canSerialize(boost::shared_ptr<ToplevelElement> element) const { return boost::dynamic_pointer_cast<CompressRequest>(element) != 0; } } diff --git a/Swiften/Serializer/CompressRequestSerializer.h b/Swiften/Serializer/CompressRequestSerializer.h index 4d68c98..a8610d1 100644 --- a/Swiften/Serializer/CompressRequestSerializer.h +++ b/Swiften/Serializer/CompressRequestSerializer.h @@ -1,21 +1,21 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <boost/shared_ptr.hpp> #include <Swiften/Serializer/ElementSerializer.h> namespace Swift { class CompressRequestSerializer : public ElementSerializer { public: CompressRequestSerializer(); - virtual SafeByteArray serialize(boost::shared_ptr<Element> element) const; - virtual bool canSerialize(boost::shared_ptr<Element> element) const; + virtual SafeByteArray serialize(boost::shared_ptr<ToplevelElement> element) const; + virtual bool canSerialize(boost::shared_ptr<ToplevelElement> element) const; }; } diff --git a/Swiften/Serializer/ElementSerializer.h b/Swiften/Serializer/ElementSerializer.h index ba59106..76c7d20 100644 --- a/Swiften/Serializer/ElementSerializer.h +++ b/Swiften/Serializer/ElementSerializer.h @@ -1,22 +1,22 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <boost/shared_ptr.hpp> -#include <Swiften/Elements/Element.h> +#include <Swiften/Elements/ToplevelElement.h> #include <Swiften/Base/SafeByteArray.h> namespace Swift { class ElementSerializer { public: virtual ~ElementSerializer(); - virtual SafeByteArray serialize(boost::shared_ptr<Element> element) const = 0; - virtual bool canSerialize(boost::shared_ptr<Element> element) const = 0; + virtual SafeByteArray serialize(boost::shared_ptr<ToplevelElement> element) const = 0; + virtual bool canSerialize(boost::shared_ptr<ToplevelElement> element) const = 0; }; } diff --git a/Swiften/Serializer/EnableStreamManagementSerializer.h b/Swiften/Serializer/EnableStreamManagementSerializer.h index 384753b..a41df81 100644 --- a/Swiften/Serializer/EnableStreamManagementSerializer.h +++ b/Swiften/Serializer/EnableStreamManagementSerializer.h @@ -1,25 +1,25 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <boost/shared_ptr.hpp> #include <Swiften/Elements/EnableStreamManagement.h> #include <Swiften/Serializer/GenericElementSerializer.h> #include <Swiften/Serializer/XML/XMLElement.h> namespace Swift { class EnableStreamManagementSerializer : public GenericElementSerializer<EnableStreamManagement> { public: EnableStreamManagementSerializer() : GenericElementSerializer<EnableStreamManagement>() { } - virtual SafeByteArray serialize(boost::shared_ptr<Element>) const { + virtual SafeByteArray serialize(boost::shared_ptr<ToplevelElement>) const { return createSafeByteArray(XMLElement("enable", "urn:xmpp:sm:2").serialize()); } }; } diff --git a/Swiften/Serializer/GenericElementSerializer.h b/Swiften/Serializer/GenericElementSerializer.h index 92f7737..620ae7b 100644 --- a/Swiften/Serializer/GenericElementSerializer.h +++ b/Swiften/Serializer/GenericElementSerializer.h @@ -1,23 +1,23 @@ /* * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <boost/shared_ptr.hpp> #include <Swiften/Serializer/ElementSerializer.h> namespace Swift { template<typename T> class GenericElementSerializer : public ElementSerializer { public: - virtual SafeByteArray serialize(boost::shared_ptr<Element> element) const = 0; + virtual SafeByteArray serialize(boost::shared_ptr<ToplevelElement> element) const = 0; - virtual bool canSerialize(boost::shared_ptr<Element> element) const { + virtual bool canSerialize(boost::shared_ptr<ToplevelElement> element) const { return !!boost::dynamic_pointer_cast<T>(element); } }; } diff --git a/Swiften/Serializer/GenericStanzaSerializer.h b/Swiften/Serializer/GenericStanzaSerializer.h index 4129ca8..a85d3ba 100644 --- a/Swiften/Serializer/GenericStanzaSerializer.h +++ b/Swiften/Serializer/GenericStanzaSerializer.h @@ -1,32 +1,32 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <Swiften/Serializer/StanzaSerializer.h> namespace Swift { template<typename STANZA_TYPE> class GenericStanzaSerializer : public StanzaSerializer { public: GenericStanzaSerializer(const std::string& tag, PayloadSerializerCollection* payloadSerializers) : StanzaSerializer(tag, payloadSerializers) {} - virtual bool canSerialize(boost::shared_ptr<Element> element) const { + virtual bool canSerialize(boost::shared_ptr<ToplevelElement> element) const { return dynamic_cast<STANZA_TYPE*>(element.get()) != 0; } virtual void setStanzaSpecificAttributes( - boost::shared_ptr<Element> stanza, + boost::shared_ptr<ToplevelElement> stanza, XMLElement& element) const { setStanzaSpecificAttributesGeneric( boost::dynamic_pointer_cast<STANZA_TYPE>(stanza), element); } virtual void setStanzaSpecificAttributesGeneric( boost::shared_ptr<STANZA_TYPE>, XMLElement&) const = 0; }; } diff --git a/Swiften/Serializer/StanzaAckRequestSerializer.h b/Swiften/Serializer/StanzaAckRequestSerializer.h index fff2a83..9766308 100644 --- a/Swiften/Serializer/StanzaAckRequestSerializer.h +++ b/Swiften/Serializer/StanzaAckRequestSerializer.h @@ -1,25 +1,25 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <boost/shared_ptr.hpp> #include <Swiften/Elements/StanzaAckRequest.h> #include <Swiften/Serializer/GenericElementSerializer.h> #include <Swiften/Serializer/XML/XMLElement.h> namespace Swift { class StanzaAckRequestSerializer : public GenericElementSerializer<StanzaAckRequest> { public: StanzaAckRequestSerializer() : GenericElementSerializer<StanzaAckRequest>() { } - virtual SafeByteArray serialize(boost::shared_ptr<Element>) const { + virtual SafeByteArray serialize(boost::shared_ptr<ToplevelElement>) const { return createSafeByteArray(XMLElement("r", "urn:xmpp:sm:2").serialize()); } }; } diff --git a/Swiften/Serializer/StanzaAckSerializer.h b/Swiften/Serializer/StanzaAckSerializer.h index ea1e8ad..ad2add6 100644 --- a/Swiften/Serializer/StanzaAckSerializer.h +++ b/Swiften/Serializer/StanzaAckSerializer.h @@ -1,30 +1,30 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <boost/shared_ptr.hpp> #include <boost/lexical_cast.hpp> #include <Swiften/Elements/StanzaAck.h> #include <Swiften/Serializer/GenericElementSerializer.h> #include <Swiften/Serializer/XML/XMLElement.h> namespace Swift { class StanzaAckSerializer : public GenericElementSerializer<StanzaAck> { public: StanzaAckSerializer() : GenericElementSerializer<StanzaAck>() { } - virtual SafeByteArray serialize(boost::shared_ptr<Element> element) const { + virtual SafeByteArray serialize(boost::shared_ptr<ToplevelElement> element) const { StanzaAck::ref stanzaAck(boost::dynamic_pointer_cast<StanzaAck>(element)); assert(stanzaAck->isValid()); XMLElement result("a", "urn:xmpp:sm:2"); result.setAttribute("h", std::string(boost::lexical_cast<std::string>(stanzaAck->getHandledStanzasCount()))); return createSafeByteArray(result.serialize()); } }; } diff --git a/Swiften/Serializer/StanzaSerializer.cpp b/Swiften/Serializer/StanzaSerializer.cpp index b5f0b22..358e4b8 100644 --- a/Swiften/Serializer/StanzaSerializer.cpp +++ b/Swiften/Serializer/StanzaSerializer.cpp @@ -1,61 +1,61 @@ /* * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #include <Swiften/Serializer/StanzaSerializer.h> #include <sstream> #include <typeinfo> #include <iostream> #include <Swiften/Base/foreach.h> #include <Swiften/Serializer/XML/XMLElement.h> #include <Swiften/Serializer/XML/XMLRawTextNode.h> #include <Swiften/Serializer/PayloadSerializer.h> #include <Swiften/Serializer/PayloadSerializerCollection.h> #include <Swiften/Elements/Stanza.h> namespace Swift { StanzaSerializer::StanzaSerializer(const std::string& tag, PayloadSerializerCollection* payloadSerializers) : tag_(tag), payloadSerializers_(payloadSerializers) { } -SafeByteArray StanzaSerializer::serialize(boost::shared_ptr<Element> element) const { +SafeByteArray StanzaSerializer::serialize(boost::shared_ptr<ToplevelElement> element) const { return serialize(element, ""); } -SafeByteArray StanzaSerializer::serialize(boost::shared_ptr<Element> element, const std::string& xmlns) const { +SafeByteArray StanzaSerializer::serialize(boost::shared_ptr<ToplevelElement> element, const std::string& xmlns) const { boost::shared_ptr<Stanza> stanza(boost::dynamic_pointer_cast<Stanza>(element)); XMLElement stanzaElement(tag_, xmlns); if (stanza->getFrom().isValid()) { stanzaElement.setAttribute("from", stanza->getFrom()); } if (stanza->getTo().isValid()) { stanzaElement.setAttribute("to", stanza->getTo()); } if (!stanza->getID().empty()) { stanzaElement.setAttribute("id", stanza->getID()); } setStanzaSpecificAttributes(stanza, stanzaElement); std::string serializedPayloads; foreach (const boost::shared_ptr<Payload>& payload, stanza->getPayloads()) { PayloadSerializer* serializer = payloadSerializers_->getPayloadSerializer(payload); if (serializer) { serializedPayloads += serializer->serialize(payload); } else { std::cerr << "Could not find serializer for " << typeid(*(payload.get())).name() << std::endl; } } if (!serializedPayloads.empty()) { stanzaElement.addNode(boost::shared_ptr<XMLNode>(new XMLRawTextNode(serializedPayloads))); } return createSafeByteArray(stanzaElement.serialize()); } } diff --git a/Swiften/Serializer/StanzaSerializer.h b/Swiften/Serializer/StanzaSerializer.h index d569d82..6b46670 100644 --- a/Swiften/Serializer/StanzaSerializer.h +++ b/Swiften/Serializer/StanzaSerializer.h @@ -1,29 +1,29 @@ /* * Copyright (c) 2013-2014 Kevin Smith and Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <Swiften/Elements/Stanza.h> #include <Swiften/Serializer/ElementSerializer.h> #include <string> namespace Swift { class PayloadSerializerCollection; class XMLElement; class StanzaSerializer : public ElementSerializer { public: StanzaSerializer(const std::string& tag, PayloadSerializerCollection* payloadSerializers); - virtual SafeByteArray serialize(boost::shared_ptr<Element> element) const; - virtual SafeByteArray serialize(boost::shared_ptr<Element> element, const std::string& xmlns) const; - virtual void setStanzaSpecificAttributes(boost::shared_ptr<Element>, XMLElement&) const = 0; + virtual SafeByteArray serialize(boost::shared_ptr<ToplevelElement> element) const; + virtual SafeByteArray serialize(boost::shared_ptr<ToplevelElement> element, const std::string& xmlns) const; + virtual void setStanzaSpecificAttributes(boost::shared_ptr<ToplevelElement>, XMLElement&) const = 0; private: std::string tag_; PayloadSerializerCollection* payloadSerializers_; }; } diff --git a/Swiften/Serializer/StartTLSFailureSerializer.h b/Swiften/Serializer/StartTLSFailureSerializer.h index 779be92..f924545 100644 --- a/Swiften/Serializer/StartTLSFailureSerializer.h +++ b/Swiften/Serializer/StartTLSFailureSerializer.h @@ -1,25 +1,25 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <boost/shared_ptr.hpp> #include <Swiften/Elements/StartTLSFailure.h> #include <Swiften/Serializer/GenericElementSerializer.h> #include <Swiften/Serializer/XML/XMLElement.h> namespace Swift { class StartTLSFailureSerializer : public GenericElementSerializer<StartTLSFailure> { public: StartTLSFailureSerializer() : GenericElementSerializer<StartTLSFailure>() { } - virtual SafeByteArray serialize(boost::shared_ptr<Element>) const { + virtual SafeByteArray serialize(boost::shared_ptr<ToplevelElement>) const { return createSafeByteArray(XMLElement("failure", "urn:ietf:params:xml:ns:xmpp-tls").serialize()); } }; } diff --git a/Swiften/Serializer/StartTLSRequestSerializer.h b/Swiften/Serializer/StartTLSRequestSerializer.h index df914ce..80745e3 100644 --- a/Swiften/Serializer/StartTLSRequestSerializer.h +++ b/Swiften/Serializer/StartTLSRequestSerializer.h @@ -1,25 +1,25 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <boost/shared_ptr.hpp> #include <Swiften/Elements/StartTLSRequest.h> #include <Swiften/Serializer/GenericElementSerializer.h> #include <Swiften/Serializer/XML/XMLElement.h> namespace Swift { class StartTLSRequestSerializer : public GenericElementSerializer<StartTLSRequest> { public: StartTLSRequestSerializer() : GenericElementSerializer<StartTLSRequest>() { } - virtual SafeByteArray serialize(boost::shared_ptr<Element>) const { + virtual SafeByteArray serialize(boost::shared_ptr<ToplevelElement>) const { return createSafeByteArray(XMLElement("starttls", "urn:ietf:params:xml:ns:xmpp-tls").serialize()); } }; } diff --git a/Swiften/Serializer/StreamErrorSerializer.cpp b/Swiften/Serializer/StreamErrorSerializer.cpp index b3d62a0..37ac3ca 100644 --- a/Swiften/Serializer/StreamErrorSerializer.cpp +++ b/Swiften/Serializer/StreamErrorSerializer.cpp @@ -1,53 +1,53 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #include <Swiften/Serializer/StreamErrorSerializer.h> #include <boost/smart_ptr/make_shared.hpp> #include <Swiften/Serializer/XML/XMLElement.h> namespace Swift { StreamErrorSerializer::StreamErrorSerializer() : GenericElementSerializer<StreamError>() { } -SafeByteArray StreamErrorSerializer::serialize(boost::shared_ptr<Element> element) const { +SafeByteArray StreamErrorSerializer::serialize(boost::shared_ptr<ToplevelElement> element) const { StreamError::ref error = boost::dynamic_pointer_cast<StreamError>(element); XMLElement errorElement("error", "http://etherx.jabber.org/streams"); std::string typeTag; switch (error->getType()) { case StreamError::BadFormat: typeTag = "bad-format"; break; case StreamError::BadNamespacePrefix: typeTag = "bad-namespace-prefix"; break; case StreamError::Conflict: typeTag = "conflict"; break; case StreamError::ConnectionTimeout: typeTag = "connection-timeout"; break; case StreamError::HostGone: typeTag = "host-gone"; break; case StreamError::HostUnknown: typeTag = "host-unknown"; break; case StreamError::ImproperAddressing: typeTag = "improper-addressing"; break; case StreamError::InternalServerError: typeTag = "internal-server-error"; break; case StreamError::InvalidFrom: typeTag = "invalid-from"; break; case StreamError::InvalidID: typeTag = "invalid-id"; break; case StreamError::InvalidNamespace: typeTag = "invalid-namespace"; break; case StreamError::InvalidXML: typeTag = "invalid-xml"; break; case StreamError::NotAuthorized: typeTag = "not-authorized"; break; case StreamError::NotWellFormed: typeTag = "not-well-formed"; break; case StreamError::PolicyViolation: typeTag = "policy-violation"; break; case StreamError::RemoteConnectionFailed: typeTag = "remote-connection-failed"; break; case StreamError::Reset: typeTag = "reset"; break; case StreamError::ResourceConstraint: typeTag = "resource-constraint"; break; case StreamError::RestrictedXML: typeTag = "restricted-xml"; break; case StreamError::SeeOtherHost: typeTag = "see-other-host"; break; case StreamError::SystemShutdown: typeTag = "system-shutdown"; break; case StreamError::UndefinedCondition: typeTag = "undefined-condition"; break; case StreamError::UnsupportedEncoding: typeTag = "unsupported-encoding"; break; case StreamError::UnsupportedStanzaType: typeTag = "unsupported-stanza-type"; break; case StreamError::UnsupportedVersion: typeTag = "unsupported-version"; break; } errorElement.addNode(boost::make_shared<XMLElement>(typeTag, "urn:ietf:params:xml:ns:xmpp-streams")); if (!error->getText().empty()) { errorElement.addNode(boost::make_shared<XMLElement>("text", "urn:ietf:params:xml:ns:xmpp-streams", error->getText())); diff --git a/Swiften/Serializer/StreamErrorSerializer.h b/Swiften/Serializer/StreamErrorSerializer.h index bdaa831..d82cd02 100644 --- a/Swiften/Serializer/StreamErrorSerializer.h +++ b/Swiften/Serializer/StreamErrorSerializer.h @@ -1,19 +1,19 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <Swiften/Serializer/GenericElementSerializer.h> #include <Swiften/Elements/StreamError.h> namespace Swift { class StreamErrorSerializer : public GenericElementSerializer<StreamError> { public: StreamErrorSerializer(); - virtual SafeByteArray serialize(boost::shared_ptr<Element> error) const; + virtual SafeByteArray serialize(boost::shared_ptr<ToplevelElement> error) const; }; } diff --git a/Swiften/Serializer/StreamFeaturesSerializer.cpp b/Swiften/Serializer/StreamFeaturesSerializer.cpp index 2344349..a93247a 100644 --- a/Swiften/Serializer/StreamFeaturesSerializer.cpp +++ b/Swiften/Serializer/StreamFeaturesSerializer.cpp @@ -1,55 +1,55 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #include <Swiften/Serializer/StreamFeaturesSerializer.h> #include <boost/smart_ptr/make_shared.hpp> #include <Swiften/Serializer/XML/XMLElement.h> #include <Swiften/Serializer/XML/XMLTextNode.h> #include <Swiften/Base/foreach.h> namespace Swift { StreamFeaturesSerializer::StreamFeaturesSerializer() { } -SafeByteArray StreamFeaturesSerializer::serialize(boost::shared_ptr<Element> element) const { +SafeByteArray StreamFeaturesSerializer::serialize(boost::shared_ptr<ToplevelElement> element) const { boost::shared_ptr<StreamFeatures> streamFeatures(boost::dynamic_pointer_cast<StreamFeatures>(element)); XMLElement streamFeaturesElement("stream:features"); if (streamFeatures->hasStartTLS()) { streamFeaturesElement.addNode(boost::make_shared<XMLElement>("starttls", "urn:ietf:params:xml:ns:xmpp-tls")); } if (!streamFeatures->getCompressionMethods().empty()) { boost::shared_ptr<XMLElement> compressionElement(new XMLElement("compression", "http://jabber.org/features/compress")); foreach(const std::string& method, streamFeatures->getCompressionMethods()) { boost::shared_ptr<XMLElement> methodElement(new XMLElement("method")); methodElement->addNode(boost::make_shared<XMLTextNode>(method)); compressionElement->addNode(methodElement); } streamFeaturesElement.addNode(compressionElement); } if (!streamFeatures->getAuthenticationMechanisms().empty()) { boost::shared_ptr<XMLElement> mechanismsElement(new XMLElement("mechanisms", "urn:ietf:params:xml:ns:xmpp-sasl")); foreach(const std::string& mechanism, streamFeatures->getAuthenticationMechanisms()) { boost::shared_ptr<XMLElement> mechanismElement(new XMLElement("mechanism")); mechanismElement->addNode(boost::make_shared<XMLTextNode>(mechanism)); mechanismsElement->addNode(mechanismElement); } streamFeaturesElement.addNode(mechanismsElement); } if (streamFeatures->hasResourceBind()) { streamFeaturesElement.addNode(boost::make_shared<XMLElement>("bind", "urn:ietf:params:xml:ns:xmpp-bind")); } if (streamFeatures->hasSession()) { streamFeaturesElement.addNode(boost::make_shared<XMLElement>("session", "urn:ietf:params:xml:ns:xmpp-session")); } if (streamFeatures->hasStreamManagement()) { streamFeaturesElement.addNode(boost::make_shared<XMLElement>("sm", "urn:xmpp:sm:2")); } if (streamFeatures->hasRosterVersioning()) { streamFeaturesElement.addNode(boost::make_shared<XMLElement>("ver", "urn:xmpp:features:rosterver")); diff --git a/Swiften/Serializer/StreamFeaturesSerializer.h b/Swiften/Serializer/StreamFeaturesSerializer.h index 1bd1136..b69a218 100644 --- a/Swiften/Serializer/StreamFeaturesSerializer.h +++ b/Swiften/Serializer/StreamFeaturesSerializer.h @@ -1,22 +1,22 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <boost/shared_ptr.hpp> #include <Swiften/Base/API.h> #include <Swiften/Elements/StreamFeatures.h> #include <Swiften/Serializer/GenericElementSerializer.h> namespace Swift { class SWIFTEN_API StreamFeaturesSerializer : public GenericElementSerializer<StreamFeatures> { public: StreamFeaturesSerializer(); - virtual SafeByteArray serialize(boost::shared_ptr<Element> element) const; + virtual SafeByteArray serialize(boost::shared_ptr<ToplevelElement> element) const; }; } diff --git a/Swiften/Serializer/StreamManagementEnabledSerializer.cpp b/Swiften/Serializer/StreamManagementEnabledSerializer.cpp index b559721..9d4ee94 100644 --- a/Swiften/Serializer/StreamManagementEnabledSerializer.cpp +++ b/Swiften/Serializer/StreamManagementEnabledSerializer.cpp @@ -1,29 +1,29 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #include <Swiften/Serializer/StreamManagementEnabledSerializer.h> #include <boost/shared_ptr.hpp> #include <Swiften/Elements/StreamManagementEnabled.h> #include <Swiften/Serializer/XML/XMLElement.h> using namespace Swift; StreamManagementEnabledSerializer::StreamManagementEnabledSerializer() : GenericElementSerializer<StreamManagementEnabled>() { } -SafeByteArray StreamManagementEnabledSerializer::serialize(boost::shared_ptr<Element> el) const { +SafeByteArray StreamManagementEnabledSerializer::serialize(boost::shared_ptr<ToplevelElement> el) const { boost::shared_ptr<StreamManagementEnabled> e(boost::dynamic_pointer_cast<StreamManagementEnabled>(el)); XMLElement element("enabled", "urn:xmpp:sm:2"); if (!e->getResumeID().empty()) { element.setAttribute("id", e->getResumeID()); } if (e->getResumeSupported()) { element.setAttribute("resume", "true"); } return createSafeByteArray(element.serialize()); } diff --git a/Swiften/Serializer/StreamManagementEnabledSerializer.h b/Swiften/Serializer/StreamManagementEnabledSerializer.h index 5f28a2b..ee2a980 100644 --- a/Swiften/Serializer/StreamManagementEnabledSerializer.h +++ b/Swiften/Serializer/StreamManagementEnabledSerializer.h @@ -1,21 +1,21 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <boost/shared_ptr.hpp> #include <Swiften/Elements/StreamManagementEnabled.h> #include <Swiften/Serializer/GenericElementSerializer.h> namespace Swift { class StreamManagementEnabledSerializer : public GenericElementSerializer<StreamManagementEnabled> { public: StreamManagementEnabledSerializer(); - virtual SafeByteArray serialize(boost::shared_ptr<Element>) const; + virtual SafeByteArray serialize(boost::shared_ptr<ToplevelElement>) const; }; } diff --git a/Swiften/Serializer/StreamManagementFailedSerializer.h b/Swiften/Serializer/StreamManagementFailedSerializer.h index f3dcce0..f6e7b0e 100644 --- a/Swiften/Serializer/StreamManagementFailedSerializer.h +++ b/Swiften/Serializer/StreamManagementFailedSerializer.h @@ -1,25 +1,25 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <boost/shared_ptr.hpp> #include <Swiften/Elements/StreamManagementFailed.h> #include <Swiften/Serializer/GenericElementSerializer.h> #include <Swiften/Serializer/XML/XMLElement.h> namespace Swift { class StreamManagementFailedSerializer : public GenericElementSerializer<StreamManagementFailed> { public: StreamManagementFailedSerializer() : GenericElementSerializer<StreamManagementFailed>() { } - virtual SafeByteArray serialize(boost::shared_ptr<Element>) const { + virtual SafeByteArray serialize(boost::shared_ptr<ToplevelElement>) const { return createSafeByteArray(XMLElement("failed", "urn:xmpp:sm:2").serialize()); } }; } diff --git a/Swiften/Serializer/StreamResumeSerializer.cpp b/Swiften/Serializer/StreamResumeSerializer.cpp index e9e520d..902ab21 100644 --- a/Swiften/Serializer/StreamResumeSerializer.cpp +++ b/Swiften/Serializer/StreamResumeSerializer.cpp @@ -1,28 +1,28 @@ /* - * Copyright (c) 2011 Remko Tronçon + * Copyright (c) 2011-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #include <Swiften/Serializer/StreamResumeSerializer.h> #include <boost/shared_ptr.hpp> #include <boost/lexical_cast.hpp> #include <Swiften/Elements/StreamResume.h> #include <Swiften/Serializer/XML/XMLElement.h> using namespace Swift; StreamResumeSerializer::StreamResumeSerializer() : GenericElementSerializer<StreamResume>() { } -SafeByteArray StreamResumeSerializer::serialize(boost::shared_ptr<Element> el) const { +SafeByteArray StreamResumeSerializer::serialize(boost::shared_ptr<ToplevelElement> el) const { boost::shared_ptr<StreamResume> e(boost::dynamic_pointer_cast<StreamResume>(el)); XMLElement element("resume", "urn:xmpp:sm:2"); element.setAttribute("previd", e->getResumeID()); if (e->getHandledStanzasCount()) { element.setAttribute("h", boost::lexical_cast<std::string>(e->getHandledStanzasCount())); } return createSafeByteArray(element.serialize()); } diff --git a/Swiften/Serializer/StreamResumeSerializer.h b/Swiften/Serializer/StreamResumeSerializer.h index 501d8b6..17baa44 100644 --- a/Swiften/Serializer/StreamResumeSerializer.h +++ b/Swiften/Serializer/StreamResumeSerializer.h @@ -1,21 +1,21 @@ /* - * Copyright (c) 2011 Remko Tronçon + * Copyright (c) 2011-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <boost/shared_ptr.hpp> #include <Swiften/Elements/StreamResume.h> #include <Swiften/Serializer/GenericElementSerializer.h> namespace Swift { class StreamResumeSerializer : public GenericElementSerializer<StreamResume> { public: StreamResumeSerializer(); - virtual SafeByteArray serialize(boost::shared_ptr<Element>) const; + virtual SafeByteArray serialize(boost::shared_ptr<ToplevelElement>) const; }; } diff --git a/Swiften/Serializer/StreamResumedSerializer.cpp b/Swiften/Serializer/StreamResumedSerializer.cpp index 7ae82d1..6477af9 100644 --- a/Swiften/Serializer/StreamResumedSerializer.cpp +++ b/Swiften/Serializer/StreamResumedSerializer.cpp @@ -1,28 +1,28 @@ /* - * Copyright (c) 2011 Remko Tronçon + * Copyright (c) 2011-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #include <Swiften/Serializer/StreamResumedSerializer.h> #include <boost/shared_ptr.hpp> #include <boost/lexical_cast.hpp> #include <Swiften/Elements/StreamResumed.h> #include <Swiften/Serializer/XML/XMLElement.h> using namespace Swift; StreamResumedSerializer::StreamResumedSerializer() : GenericElementSerializer<StreamResumed>() { } -SafeByteArray StreamResumedSerializer::serialize(boost::shared_ptr<Element> el) const { +SafeByteArray StreamResumedSerializer::serialize(boost::shared_ptr<ToplevelElement> el) const { boost::shared_ptr<StreamResumed> e(boost::dynamic_pointer_cast<StreamResumed>(el)); XMLElement element("resumed", "urn:xmpp:sm:2"); element.setAttribute("previd", e->getResumeID()); if (e->getHandledStanzasCount()) { element.setAttribute("h", boost::lexical_cast<std::string>(e->getHandledStanzasCount())); } return createSafeByteArray(element.serialize()); } diff --git a/Swiften/Serializer/StreamResumedSerializer.h b/Swiften/Serializer/StreamResumedSerializer.h index 7828694..bdca891 100644 --- a/Swiften/Serializer/StreamResumedSerializer.h +++ b/Swiften/Serializer/StreamResumedSerializer.h @@ -1,21 +1,21 @@ /* - * Copyright (c) 2011 Remko Tronçon + * Copyright (c) 2011-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <boost/shared_ptr.hpp> #include <Swiften/Elements/StreamResumed.h> #include <Swiften/Serializer/GenericElementSerializer.h> namespace Swift { class StreamResumedSerializer : public GenericElementSerializer<StreamResumed> { public: StreamResumedSerializer(); - virtual SafeByteArray serialize(boost::shared_ptr<Element>) const; + virtual SafeByteArray serialize(boost::shared_ptr<ToplevelElement>) const; }; } diff --git a/Swiften/Serializer/TLSProceedSerializer.h b/Swiften/Serializer/TLSProceedSerializer.h index 21a8420..15db3dc 100644 --- a/Swiften/Serializer/TLSProceedSerializer.h +++ b/Swiften/Serializer/TLSProceedSerializer.h @@ -1,25 +1,25 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <boost/shared_ptr.hpp> #include <Swiften/Elements/TLSProceed.h> #include <Swiften/Serializer/GenericElementSerializer.h> #include <Swiften/Serializer/XML/XMLElement.h> namespace Swift { class TLSProceedSerializer : public GenericElementSerializer<TLSProceed> { public: TLSProceedSerializer() : GenericElementSerializer<TLSProceed>() { } - virtual SafeByteArray serialize(boost::shared_ptr<Element>) const { + virtual SafeByteArray serialize(boost::shared_ptr<ToplevelElement>) const { return createSafeByteArray(XMLElement("proceed", "urn:ietf:params:xml:ns:xmpp-tls").serialize()); } }; } diff --git a/Swiften/Serializer/XMPPSerializer.cpp b/Swiften/Serializer/XMPPSerializer.cpp index 389f7cc..e3f43cd 100644 --- a/Swiften/Serializer/XMPPSerializer.cpp +++ b/Swiften/Serializer/XMPPSerializer.cpp @@ -1,37 +1,37 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #include <Swiften/Serializer/XMPPSerializer.h> #include <boost/bind.hpp> #include <boost/smart_ptr/make_shared.hpp> #include <iostream> #include <cassert> #include <Swiften/Elements/ProtocolHeader.h> #include <Swiften/Base/foreach.h> #include <Swiften/Serializer/CompressRequestSerializer.h> #include <Swiften/Serializer/CompressFailureSerializer.h> #include <Swiften/Serializer/StreamErrorSerializer.h> #include <Swiften/Serializer/StreamFeaturesSerializer.h> #include <Swiften/Serializer/AuthRequestSerializer.h> #include <Swiften/Serializer/AuthFailureSerializer.h> #include <Swiften/Serializer/AuthSuccessSerializer.h> #include <Swiften/Serializer/AuthChallengeSerializer.h> #include <Swiften/Serializer/AuthResponseSerializer.h> #include <Swiften/Serializer/EnableStreamManagementSerializer.h> #include <Swiften/Serializer/StreamManagementEnabledSerializer.h> #include <Swiften/Serializer/StreamResumeSerializer.h> #include <Swiften/Serializer/StreamResumedSerializer.h> #include <Swiften/Serializer/StreamManagementFailedSerializer.h> #include <Swiften/Serializer/StanzaAckSerializer.h> #include <Swiften/Serializer/StanzaAckRequestSerializer.h> #include <Swiften/Serializer/StartTLSRequestSerializer.h> #include <Swiften/Serializer/StartTLSFailureSerializer.h> #include <Swiften/Serializer/TLSProceedSerializer.h> #include <Swiften/Serializer/MessageSerializer.h> #include <Swiften/Serializer/PresenceSerializer.h> #include <Swiften/Serializer/IQSerializer.h> @@ -51,61 +51,61 @@ XMPPSerializer::XMPPSerializer(PayloadSerializerCollection* payloadSerializers, serializers_.push_back(boost::make_shared<AuthChallengeSerializer>()); serializers_.push_back(boost::make_shared<AuthResponseSerializer>()); serializers_.push_back(boost::make_shared<StartTLSRequestSerializer>()); serializers_.push_back(boost::make_shared<StartTLSFailureSerializer>()); serializers_.push_back(boost::make_shared<TLSProceedSerializer>()); serializers_.push_back(boost::make_shared<StreamFeaturesSerializer>()); serializers_.push_back(boost::make_shared<StreamErrorSerializer>()); serializers_.push_back(boost::make_shared<EnableStreamManagementSerializer>()); serializers_.push_back(boost::make_shared<StreamManagementEnabledSerializer>()); serializers_.push_back(boost::make_shared<StreamManagementFailedSerializer>()); serializers_.push_back(boost::make_shared<StreamResumeSerializer>()); serializers_.push_back(boost::make_shared<StreamResumedSerializer>()); serializers_.push_back(boost::make_shared<StanzaAckSerializer>()); serializers_.push_back(boost::make_shared<StanzaAckRequestSerializer>()); serializers_.push_back(boost::make_shared<ComponentHandshakeSerializer>()); } std::string XMPPSerializer::serializeHeader(const ProtocolHeader& header) const { std::string result = "<?xml version=\"1.0\"?><stream:stream xmlns=\"" + getDefaultNamespace() + "\" xmlns:stream=\"http://etherx.jabber.org/streams\""; if (!header.getFrom().empty()) { result += " from=\"" + header.getFrom() + "\""; } if (!header.getTo().empty()) { result += " to=\"" + header.getTo() + "\""; } if (!header.getID().empty()) { result += " id=\"" + header.getID() + "\""; } if (!header.getVersion().empty()) { result += " version=\"" + header.getVersion() + "\""; } result += ">"; return result; } -SafeByteArray XMPPSerializer::serializeElement(boost::shared_ptr<Element> element) const { +SafeByteArray XMPPSerializer::serializeElement(boost::shared_ptr<ToplevelElement> element) const { std::vector< boost::shared_ptr<ElementSerializer> >::const_iterator i = std::find_if(serializers_.begin(), serializers_.end(), boost::bind(&ElementSerializer::canSerialize, _1, element)); if (i != serializers_.end()) { return (*i)->serialize(element); } else { std::cerr << "Could not find serializer for " << typeid(*(element.get())).name() << std::endl; return createSafeByteArray(""); } } std::string XMPPSerializer::serializeFooter() const { return "</stream:stream>"; } std::string XMPPSerializer::getDefaultNamespace() const { switch (type_) { case ClientStreamType: return "jabber:client"; case ServerStreamType: return "jabber:server"; case ComponentStreamType: return "jabber:component:accept"; } assert(false); return ""; } } diff --git a/Swiften/Serializer/XMPPSerializer.h b/Swiften/Serializer/XMPPSerializer.h index 5b5c9d6..cbcdccb 100644 --- a/Swiften/Serializer/XMPPSerializer.h +++ b/Swiften/Serializer/XMPPSerializer.h @@ -1,38 +1,38 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <boost/shared_ptr.hpp> #include <vector> #include <Swiften/Base/API.h> -#include <Swiften/Elements/Element.h> +#include <Swiften/Elements/ToplevelElement.h> #include <Swiften/Elements/StreamType.h> #include <string> #include <Swiften/Serializer/ElementSerializer.h> namespace Swift { class PayloadSerializerCollection; class CompressRequestSerializer; class ProtocolHeader; class SWIFTEN_API XMPPSerializer { public: XMPPSerializer(PayloadSerializerCollection*, StreamType type); std::string serializeHeader(const ProtocolHeader&) const; - SafeByteArray serializeElement(boost::shared_ptr<Element> stanza) const; + SafeByteArray serializeElement(boost::shared_ptr<ToplevelElement> stanza) const; std::string serializeFooter() const; private: std::string getDefaultNamespace() const; private: StreamType type_; std::vector< boost::shared_ptr<ElementSerializer> > serializers_; }; } diff --git a/Swiften/Session/BOSHSessionStream.cpp b/Swiften/Session/BOSHSessionStream.cpp index 62261d0..8cdbdb0 100644 --- a/Swiften/Session/BOSHSessionStream.cpp +++ b/Swiften/Session/BOSHSessionStream.cpp @@ -1,37 +1,37 @@ /* - * Copyright (c) 2011 Kevin Smith + * Copyright (c) 2011-2014 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #include <Swiften/Session/BOSHSessionStream.h> #include <boost/bind.hpp> #include <boost/random/mersenne_twister.hpp> #include <boost/random/uniform_int.hpp> #include <boost/random/variate_generator.hpp> #include <Swiften/Base/foreach.h> #include <Swiften/Elements/StreamType.h> #include <Swiften/StreamStack/XMPPLayer.h> #include <Swiften/StreamStack/StreamStack.h> #include <Swiften/StreamStack/ConnectionLayer.h> #include <Swiften/StreamStack/WhitespacePingLayer.h> #include <Swiften/StreamStack/CompressionLayer.h> #include <Swiften/StreamStack/TLSLayer.h> #include <Swiften/TLS/TLSContextFactory.h> #include <Swiften/TLS/TLSContext.h> #include <Swiften/EventLoop/EventLoop.h> namespace Swift { BOSHSessionStream::BOSHSessionStream( const URL& boshURL, PayloadParserFactoryCollection* payloadParserFactories, PayloadSerializerCollection* payloadSerializers, ConnectionFactory* connectionFactory, TLSContextFactory* tlsContextFactory, TimerFactory* timerFactory, XMLParserFactory* xmlParserFactory, EventLoop* eventLoop, @@ -54,141 +54,141 @@ BOSHSessionStream::BOSHSessionStream( connectionPool->onSessionStarted.connect(boost::bind(&BOSHSessionStream::handlePoolSessionStarted, this)); connectionPool->onXMPPDataRead.connect(boost::bind(&BOSHSessionStream::handlePoolXMPPDataRead, this, _1)); connectionPool->onBOSHDataRead.connect(boost::bind(&BOSHSessionStream::handlePoolBOSHDataRead, this, _1)); connectionPool->onBOSHDataWritten.connect(boost::bind(&BOSHSessionStream::handlePoolBOSHDataWritten, this, _1)); xmppLayer = new XMPPLayer(payloadParserFactories, payloadSerializers, xmlParserFactory, ClientStreamType); xmppLayer->onStreamStart.connect(boost::bind(&BOSHSessionStream::handleStreamStartReceived, this, _1)); xmppLayer->onElement.connect(boost::bind(&BOSHSessionStream::handleElementReceived, this, _1)); xmppLayer->onError.connect(boost::bind(&BOSHSessionStream::handleXMPPError, this)); xmppLayer->onWriteData.connect(boost::bind(&BOSHSessionStream::handleXMPPLayerDataWritten, this, _1)); available = true; } BOSHSessionStream::~BOSHSessionStream() { close(); connectionPool->onSessionTerminated.disconnect(boost::bind(&BOSHSessionStream::handlePoolSessionTerminated, this, _1)); connectionPool->onSessionStarted.disconnect(boost::bind(&BOSHSessionStream::handlePoolSessionStarted, this)); connectionPool->onXMPPDataRead.disconnect(boost::bind(&BOSHSessionStream::handlePoolXMPPDataRead, this, _1)); connectionPool->onBOSHDataRead.disconnect(boost::bind(&BOSHSessionStream::handlePoolBOSHDataRead, this, _1)); connectionPool->onBOSHDataWritten.disconnect(boost::bind(&BOSHSessionStream::handlePoolBOSHDataWritten, this, _1)); delete connectionPool; connectionPool = NULL; xmppLayer->onStreamStart.disconnect(boost::bind(&BOSHSessionStream::handleStreamStartReceived, this, _1)); xmppLayer->onElement.disconnect(boost::bind(&BOSHSessionStream::handleElementReceived, this, _1)); xmppLayer->onError.disconnect(boost::bind(&BOSHSessionStream::handleXMPPError, this)); xmppLayer->onWriteData.disconnect(boost::bind(&BOSHSessionStream::handleXMPPLayerDataWritten, this, _1)); delete xmppLayer; xmppLayer = NULL; } void BOSHSessionStream::handlePoolXMPPDataRead(const SafeByteArray& data) { xmppLayer->handleDataRead(data); } -void BOSHSessionStream::writeElement(boost::shared_ptr<Element> element) { +void BOSHSessionStream::writeElement(boost::shared_ptr<ToplevelElement> element) { assert(available); xmppLayer->writeElement(element); } void BOSHSessionStream::writeFooter() { connectionPool->writeFooter(); } void BOSHSessionStream::writeData(const std::string& data) { assert(available); xmppLayer->writeData(data); } void BOSHSessionStream::close() { connectionPool->close(); } bool BOSHSessionStream::isOpen() { return available; } bool BOSHSessionStream::supportsTLSEncryption() { return false; } void BOSHSessionStream::addTLSEncryption() { assert(available); } bool BOSHSessionStream::isTLSEncrypted() { return false; } Certificate::ref BOSHSessionStream::getPeerCertificate() const { return Certificate::ref(); } std::vector<Certificate::ref> BOSHSessionStream::getPeerCertificateChain() const { return std::vector<Certificate::ref>(); } boost::shared_ptr<CertificateVerificationError> BOSHSessionStream::getPeerCertificateVerificationError() const { return boost::shared_ptr<CertificateVerificationError>(); } ByteArray BOSHSessionStream::getTLSFinishMessage() const { return ByteArray(); } bool BOSHSessionStream::supportsZLibCompression() { return false; } void BOSHSessionStream::addZLibCompression() { } void BOSHSessionStream::setWhitespacePingEnabled(bool /*enabled*/) { return; } void BOSHSessionStream::resetXMPPParser() { xmppLayer->resetParser(); } void BOSHSessionStream::handleStreamStartReceived(const ProtocolHeader& header) { onStreamStartReceived(header); } -void BOSHSessionStream::handleElementReceived(boost::shared_ptr<Element> element) { +void BOSHSessionStream::handleElementReceived(boost::shared_ptr<ToplevelElement> element) { onElementReceived(element); } void BOSHSessionStream::handleXMPPError() { available = false; onClosed(boost::make_shared<SessionStreamError>(SessionStreamError::ParseError)); } void BOSHSessionStream::handlePoolSessionStarted() { fakeStreamHeaderReceipt(); } void BOSHSessionStream::handlePoolSessionTerminated(BOSHError::ref error) { eventLoop->postEvent(boost::bind(&BOSHSessionStream::fakeStreamFooterReceipt, this, error), shared_from_this()); } void BOSHSessionStream::writeHeader(const ProtocolHeader& header) { streamHeader = header; /*First time we're told to do this, don't (the sending of the initial header is handled on connect) On subsequent requests we should restart the stream the BOSH way. */ if (!firstHeader) { eventLoop->postEvent(boost::bind(&BOSHSessionStream::fakeStreamHeaderReceipt, this), shared_from_this()); eventLoop->postEvent(boost::bind(&BOSHConnectionPool::restartStream, connectionPool), shared_from_this()); } firstHeader = false; } void BOSHSessionStream::fakeStreamHeaderReceipt() { std::stringstream header; header << "<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' from='"; header << streamHeader.getTo() << "' id='dummy' version='1.0'>"; xmppLayer->handleDataRead(createSafeByteArray(header.str())); diff --git a/Swiften/Session/BOSHSessionStream.h b/Swiften/Session/BOSHSessionStream.h index 290a4c5..e74d534 100644 --- a/Swiften/Session/BOSHSessionStream.h +++ b/Swiften/Session/BOSHSessionStream.h @@ -1,96 +1,96 @@ /* - * Copyright (c) 2011 Kevin Smith + * Copyright (c) 2011-2014 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <boost/shared_ptr.hpp> #include <Swiften/Base/SafeString.h> #include <Swiften/Base/SafeByteArray.h> #include <Swiften/Network/BOSHConnectionPool.h> #include <Swiften/Session/SessionStream.h> #include <Swiften/Elements/StreamType.h> #include <Swiften/EventLoop/EventOwner.h> namespace Swift { class TimerFactory; class PayloadParserFactoryCollection; class PayloadSerializerCollection; class StreamStack; class XMPPLayer; class ConnectionLayer; class CompressionLayer; class XMLParserFactory; class TLSContextFactory; class EventLoop; class BOSHSessionStream : public SessionStream, public EventOwner, public boost::enable_shared_from_this<BOSHSessionStream> { public: BOSHSessionStream( const URL& boshURL, PayloadParserFactoryCollection* payloadParserFactories, PayloadSerializerCollection* payloadSerializers, ConnectionFactory* connectionFactory, TLSContextFactory* tlsContextFactory, TimerFactory* whitespacePingLayerFactory, XMLParserFactory* xmlParserFactory, EventLoop* eventLoop, DomainNameResolver* resolver, const std::string& to, const URL& boshHTTPConnectProxyURL, const SafeString& boshHTTPConnectProxyAuthID, const SafeString& boshHTTPConnectProxyAuthPassword ); ~BOSHSessionStream(); virtual void close(); virtual bool isOpen(); virtual void writeHeader(const ProtocolHeader& header); - virtual void writeElement(boost::shared_ptr<Element>); + virtual void writeElement(boost::shared_ptr<ToplevelElement>); virtual void writeFooter(); virtual void writeData(const std::string& data); virtual bool supportsZLibCompression(); virtual void addZLibCompression(); virtual bool supportsTLSEncryption(); virtual void addTLSEncryption(); virtual bool isTLSEncrypted(); virtual Certificate::ref getPeerCertificate() const; virtual std::vector<Certificate::ref> getPeerCertificateChain() const; virtual boost::shared_ptr<CertificateVerificationError> getPeerCertificateVerificationError() const; virtual ByteArray getTLSFinishMessage() const; virtual void setWhitespacePingEnabled(bool); virtual void resetXMPPParser(); private: void handleXMPPError(); void handleStreamStartReceived(const ProtocolHeader&); - void handleElementReceived(boost::shared_ptr<Element>); + void handleElementReceived(boost::shared_ptr<ToplevelElement>); void handlePoolXMPPDataRead(const SafeByteArray& data); void handleXMPPLayerDataWritten(const SafeByteArray& data); void handlePoolSessionStarted(); void handlePoolBOSHDataRead(const SafeByteArray& data); void handlePoolBOSHDataWritten(const SafeByteArray& data); void handlePoolSessionTerminated(BOSHError::ref condition); private: void fakeStreamHeaderReceipt(); void fakeStreamFooterReceipt(BOSHError::ref error); private: BOSHConnectionPool* connectionPool; bool available; XMPPLayer* xmppLayer; ProtocolHeader streamHeader; EventLoop* eventLoop; bool firstHeader; }; } diff --git a/Swiften/Session/BasicSessionStream.cpp b/Swiften/Session/BasicSessionStream.cpp index 2bd8d66..7aaa5c2 100644 --- a/Swiften/Session/BasicSessionStream.cpp +++ b/Swiften/Session/BasicSessionStream.cpp @@ -1,37 +1,37 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #include <Swiften/Session/BasicSessionStream.h> #include <boost/bind.hpp> #include <boost/smart_ptr/make_shared.hpp> #include <Swiften/StreamStack/XMPPLayer.h> #include <Swiften/StreamStack/StreamStack.h> #include <Swiften/StreamStack/ConnectionLayer.h> #include <Swiften/StreamStack/WhitespacePingLayer.h> #include <Swiften/StreamStack/CompressionLayer.h> #include <Swiften/StreamStack/TLSLayer.h> #include <Swiften/TLS/TLSContextFactory.h> #include <Swiften/TLS/TLSContext.h> namespace Swift { BasicSessionStream::BasicSessionStream( StreamType streamType, boost::shared_ptr<Connection> connection, PayloadParserFactoryCollection* payloadParserFactories, PayloadSerializerCollection* payloadSerializers, TLSContextFactory* tlsContextFactory, TimerFactory* timerFactory, XMLParserFactory* xmlParserFactory) : available(false), connection(connection), tlsContextFactory(tlsContextFactory), timerFactory(timerFactory), compressionLayer(NULL), tlsLayer(NULL), whitespacePingLayer(NULL) { @@ -45,71 +45,71 @@ BasicSessionStream::BasicSessionStream( connection->onDisconnected.connect(boost::bind(&BasicSessionStream::handleConnectionFinished, this, _1)); connectionLayer = new ConnectionLayer(connection); streamStack = new StreamStack(xmppLayer, connectionLayer); available = true; } BasicSessionStream::~BasicSessionStream() { delete compressionLayer; if (tlsLayer) { tlsLayer->onError.disconnect(boost::bind(&BasicSessionStream::handleTLSError, this)); tlsLayer->onConnected.disconnect(boost::bind(&BasicSessionStream::handleTLSConnected, this)); delete tlsLayer; } delete whitespacePingLayer; delete streamStack; connection->onDisconnected.disconnect(boost::bind(&BasicSessionStream::handleConnectionFinished, this, _1)); delete connectionLayer; xmppLayer->onStreamStart.disconnect(boost::bind(&BasicSessionStream::handleStreamStartReceived, this, _1)); xmppLayer->onElement.disconnect(boost::bind(&BasicSessionStream::handleElementReceived, this, _1)); xmppLayer->onError.disconnect(boost::bind(&BasicSessionStream::handleXMPPError, this)); xmppLayer->onDataRead.disconnect(boost::bind(&BasicSessionStream::handleDataRead, this, _1)); xmppLayer->onWriteData.disconnect(boost::bind(&BasicSessionStream::handleDataWritten, this, _1)); delete xmppLayer; } void BasicSessionStream::writeHeader(const ProtocolHeader& header) { assert(available); xmppLayer->writeHeader(header); } -void BasicSessionStream::writeElement(boost::shared_ptr<Element> element) { +void BasicSessionStream::writeElement(boost::shared_ptr<ToplevelElement> element) { assert(available); xmppLayer->writeElement(element); } void BasicSessionStream::writeFooter() { assert(available); xmppLayer->writeFooter(); } void BasicSessionStream::writeData(const std::string& data) { assert(available); xmppLayer->writeData(data); } void BasicSessionStream::close() { connection->disconnect(); } bool BasicSessionStream::isOpen() { return available; } bool BasicSessionStream::supportsTLSEncryption() { return tlsContextFactory && tlsContextFactory->canCreate(); } void BasicSessionStream::addTLSEncryption() { assert(available); tlsLayer = new TLSLayer(tlsContextFactory); if (hasTLSCertificate() && !tlsLayer->setClientCertificate(getTLSCertificate())) { onClosed(boost::make_shared<SessionStreamError>(SessionStreamError::InvalidTLSCertificateError)); } else { streamStack->addLayer(tlsLayer); tlsLayer->onError.connect(boost::bind(&BasicSessionStream::handleTLSError, this, _1)); @@ -136,71 +136,71 @@ boost::shared_ptr<CertificateVerificationError> BasicSessionStream::getPeerCerti ByteArray BasicSessionStream::getTLSFinishMessage() const { return tlsLayer->getContext()->getFinishMessage(); } bool BasicSessionStream::supportsZLibCompression() { return true; } void BasicSessionStream::addZLibCompression() { compressionLayer = new CompressionLayer(); streamStack->addLayer(compressionLayer); } void BasicSessionStream::setWhitespacePingEnabled(bool enabled) { if (enabled) { if (!whitespacePingLayer) { whitespacePingLayer = new WhitespacePingLayer(timerFactory); streamStack->addLayer(whitespacePingLayer); } whitespacePingLayer->setActive(); } else if (whitespacePingLayer) { whitespacePingLayer->setInactive(); } } void BasicSessionStream::resetXMPPParser() { xmppLayer->resetParser(); } void BasicSessionStream::handleStreamStartReceived(const ProtocolHeader& header) { onStreamStartReceived(header); } -void BasicSessionStream::handleElementReceived(boost::shared_ptr<Element> element) { +void BasicSessionStream::handleElementReceived(boost::shared_ptr<ToplevelElement> element) { onElementReceived(element); } void BasicSessionStream::handleXMPPError() { available = false; onClosed(boost::make_shared<SessionStreamError>(SessionStreamError::ParseError)); } void BasicSessionStream::handleTLSConnected() { onTLSEncrypted(); } void BasicSessionStream::handleTLSError(boost::shared_ptr<TLSError> error) { available = false; onClosed(error); } void BasicSessionStream::handleConnectionFinished(const boost::optional<Connection::Error>& error) { available = false; if (error == Connection::ReadError) { onClosed(boost::make_shared<SessionStreamError>(SessionStreamError::ConnectionReadError)); } else if (error) { onClosed(boost::make_shared<SessionStreamError>(SessionStreamError::ConnectionWriteError)); } else { onClosed(boost::shared_ptr<SessionStreamError>()); } } void BasicSessionStream::handleDataRead(const SafeByteArray& data) { onDataRead(data); } void BasicSessionStream::handleDataWritten(const SafeByteArray& data) { diff --git a/Swiften/Session/BasicSessionStream.h b/Swiften/Session/BasicSessionStream.h index 389ecbe..e5f8004 100644 --- a/Swiften/Session/BasicSessionStream.h +++ b/Swiften/Session/BasicSessionStream.h @@ -1,90 +1,90 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <boost/shared_ptr.hpp> #include <Swiften/Base/SafeByteArray.h> #include <Swiften/Network/Connection.h> #include <Swiften/Session/SessionStream.h> #include <Swiften/Elements/StreamType.h> #include <Swiften/TLS/TLSError.h> namespace Swift { class TLSContextFactory; class TLSLayer; class TimerFactory; class WhitespacePingLayer; class PayloadParserFactoryCollection; class PayloadSerializerCollection; class StreamStack; class XMPPLayer; class ConnectionLayer; class CompressionLayer; class XMLParserFactory; class BasicSessionStream : public SessionStream { public: BasicSessionStream( StreamType streamType, boost::shared_ptr<Connection> connection, PayloadParserFactoryCollection* payloadParserFactories, PayloadSerializerCollection* payloadSerializers, TLSContextFactory* tlsContextFactory, TimerFactory* whitespacePingLayerFactory, XMLParserFactory* xmlParserFactory ); ~BasicSessionStream(); virtual void close(); virtual bool isOpen(); virtual void writeHeader(const ProtocolHeader& header); - virtual void writeElement(boost::shared_ptr<Element>); + virtual void writeElement(boost::shared_ptr<ToplevelElement>); virtual void writeFooter(); virtual void writeData(const std::string& data); virtual bool supportsZLibCompression(); virtual void addZLibCompression(); virtual bool supportsTLSEncryption(); virtual void addTLSEncryption(); virtual bool isTLSEncrypted(); virtual Certificate::ref getPeerCertificate() const; virtual std::vector<Certificate::ref> getPeerCertificateChain() const; virtual boost::shared_ptr<CertificateVerificationError> getPeerCertificateVerificationError() const; virtual ByteArray getTLSFinishMessage() const; virtual void setWhitespacePingEnabled(bool); virtual void resetXMPPParser(); private: void handleConnectionFinished(const boost::optional<Connection::Error>& error); void handleXMPPError(); void handleTLSConnected(); void handleTLSError(boost::shared_ptr<TLSError>); void handleStreamStartReceived(const ProtocolHeader&); - void handleElementReceived(boost::shared_ptr<Element>); + void handleElementReceived(boost::shared_ptr<ToplevelElement>); void handleDataRead(const SafeByteArray& data); void handleDataWritten(const SafeByteArray& data); private: bool available; boost::shared_ptr<Connection> connection; TLSContextFactory* tlsContextFactory; TimerFactory* timerFactory; XMPPLayer* xmppLayer; ConnectionLayer* connectionLayer; CompressionLayer* compressionLayer; TLSLayer* tlsLayer; WhitespacePingLayer* whitespacePingLayer; StreamStack* streamStack; }; } diff --git a/Swiften/Session/Session.cpp b/Swiften/Session/Session.cpp index acc73f1..de54c5f 100644 --- a/Swiften/Session/Session.cpp +++ b/Swiften/Session/Session.cpp @@ -1,37 +1,37 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #include <Swiften/Session/Session.h> #include <boost/bind.hpp> #include <Swiften/StreamStack/XMPPLayer.h> #include <Swiften/StreamStack/StreamStack.h> namespace Swift { Session::Session( boost::shared_ptr<Connection> connection, PayloadParserFactoryCollection* payloadParserFactories, PayloadSerializerCollection* payloadSerializers, XMLParserFactory* xmlParserFactory) : connection(connection), payloadParserFactories(payloadParserFactories), payloadSerializers(payloadSerializers), xmlParserFactory(xmlParserFactory), xmppLayer(NULL), connectionLayer(NULL), streamStack(0), finishing(false) { } Session::~Session() { delete streamStack; delete connectionLayer; delete xmppLayer; } void Session::startSession() { @@ -44,62 +44,62 @@ void Session::finishSession() { return; } finishing = true; if (xmppLayer) { xmppLayer->writeFooter(); } connection->disconnect(); } void Session::finishSession(const SessionError& /*error*/) { if (finishing) { return; } finishing = true; if (xmppLayer) { xmppLayer->writeFooter(); } connection->disconnect(); } void Session::initializeStreamStack() { xmppLayer = new XMPPLayer(payloadParserFactories, payloadSerializers, xmlParserFactory, ClientStreamType); xmppLayer->onStreamStart.connect( boost::bind(&Session::handleStreamStart, this, _1)); xmppLayer->onElement.connect(boost::bind(&Session::handleElement, this, _1)); xmppLayer->onError.connect( boost::bind(&Session::finishSession, this, XMLError)); xmppLayer->onDataRead.connect(boost::bind(boost::ref(onDataRead), _1)); xmppLayer->onWriteData.connect(boost::bind(boost::ref(onDataWritten), _1)); connection->onDisconnected.connect( boost::bind(&Session::handleDisconnected, this, _1)); connectionLayer = new ConnectionLayer(connection); streamStack = new StreamStack(xmppLayer, connectionLayer); } -void Session::sendElement(boost::shared_ptr<Element> stanza) { +void Session::sendElement(boost::shared_ptr<ToplevelElement> stanza) { xmppLayer->writeElement(stanza); } void Session::handleDisconnected(const boost::optional<Connection::Error>& connectionError) { connection->onDisconnected.disconnect( boost::bind(&Session::handleDisconnected, this, _1)); if (connectionError) { switch (*connectionError) { case Connection::ReadError: handleSessionFinished(ConnectionReadError); onSessionFinished(ConnectionReadError); break; case Connection::WriteError: handleSessionFinished(ConnectionWriteError); onSessionFinished(ConnectionWriteError); break; } } else { boost::optional<SessionError> error; handleSessionFinished(error); onSessionFinished(error); } } } diff --git a/Swiften/Session/Session.h b/Swiften/Session/Session.h index 4becebf..63a6a02 100644 --- a/Swiften/Session/Session.h +++ b/Swiften/Session/Session.h @@ -1,115 +1,115 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <boost/shared_ptr.hpp> #include <Swiften/Base/boost_bsignals.h> #include <boost/optional.hpp> #include <boost/enable_shared_from_this.hpp> #include <Swiften/Base/API.h> #include <Swiften/JID/JID.h> -#include <Swiften/Elements/Element.h> +#include <Swiften/Elements/ToplevelElement.h> #include <Swiften/Network/Connection.h> #include <Swiften/StreamStack/ConnectionLayer.h> #include <Swiften/Base/SafeByteArray.h> namespace Swift { class ProtocolHeader; class StreamStack; class JID; class Element; class PayloadParserFactoryCollection; class PayloadSerializerCollection; class XMPPLayer; class XMLParserFactory; class SWIFTEN_API Session : public boost::enable_shared_from_this<Session> { public: enum SessionError { ConnectionReadError, ConnectionWriteError, XMLError, AuthenticationFailedError, NoSupportedAuthMechanismsError, UnexpectedElementError, ResourceBindError, SessionStartError, TLSError, ClientCertificateLoadError, ClientCertificateError }; Session( boost::shared_ptr<Connection> connection, PayloadParserFactoryCollection* payloadParserFactories, PayloadSerializerCollection* payloadSerializers, XMLParserFactory* xmlParserFactory); virtual ~Session(); void startSession(); void finishSession(); - void sendElement(boost::shared_ptr<Element>); + void sendElement(boost::shared_ptr<ToplevelElement>); const JID& getLocalJID() const { return localJID; } const JID& getRemoteJID() const { return remoteJID; } - boost::signal<void (boost::shared_ptr<Element>)> onElementReceived; + boost::signal<void (boost::shared_ptr<ToplevelElement>)> onElementReceived; boost::signal<void (const boost::optional<SessionError>&)> onSessionFinished; boost::signal<void (const SafeByteArray&)> onDataWritten; boost::signal<void (const SafeByteArray&)> onDataRead; protected: void setRemoteJID(const JID& j) { remoteJID = j; } void setLocalJID(const JID& j) { localJID = j; } void finishSession(const SessionError&); virtual void handleSessionStarted() {} virtual void handleSessionFinished(const boost::optional<SessionError>&) {} - virtual void handleElement(boost::shared_ptr<Element>) = 0; + virtual void handleElement(boost::shared_ptr<ToplevelElement>) = 0; virtual void handleStreamStart(const ProtocolHeader&) = 0; void initializeStreamStack(); XMPPLayer* getXMPPLayer() const { return xmppLayer; } StreamStack* getStreamStack() const { return streamStack; } void setFinished(); private: void handleDisconnected(const boost::optional<Connection::Error>& error); private: JID localJID; JID remoteJID; boost::shared_ptr<Connection> connection; PayloadParserFactoryCollection* payloadParserFactories; PayloadSerializerCollection* payloadSerializers; XMLParserFactory* xmlParserFactory; XMPPLayer* xmppLayer; ConnectionLayer* connectionLayer; StreamStack* streamStack; bool finishing; }; } diff --git a/Swiften/Session/SessionStream.h b/Swiften/Session/SessionStream.h index 501f588..2394295 100644 --- a/Swiften/Session/SessionStream.h +++ b/Swiften/Session/SessionStream.h @@ -1,91 +1,91 @@ /* - * Copyright (c) 2010-2012 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <Swiften/Base/boost_bsignals.h> #include <boost/shared_ptr.hpp> #include <boost/optional.hpp> #include <Swiften/Base/API.h> #include <Swiften/Elements/ProtocolHeader.h> -#include <Swiften/Elements/Element.h> +#include <Swiften/Elements/ToplevelElement.h> #include <Swiften/Base/Error.h> #include <Swiften/Base/SafeByteArray.h> #include <Swiften/TLS/CertificateWithKey.h> #include <Swiften/TLS/Certificate.h> #include <Swiften/TLS/CertificateVerificationError.h> namespace Swift { class SWIFTEN_API SessionStream { public: class SessionStreamError : public Swift::Error { public: enum Type { ParseError, TLSError, InvalidTLSCertificateError, ConnectionReadError, ConnectionWriteError }; SessionStreamError(Type type) : type(type) {} Type type; }; SessionStream(): certificate() {} virtual ~SessionStream(); virtual void close() = 0; virtual bool isOpen() = 0; virtual void writeHeader(const ProtocolHeader& header) = 0; virtual void writeFooter() = 0; - virtual void writeElement(boost::shared_ptr<Element>) = 0; + virtual void writeElement(boost::shared_ptr<ToplevelElement>) = 0; virtual void writeData(const std::string& data) = 0; virtual bool supportsZLibCompression() = 0; virtual void addZLibCompression() = 0; virtual bool supportsTLSEncryption() = 0; virtual void addTLSEncryption() = 0; virtual bool isTLSEncrypted() = 0; virtual void setWhitespacePingEnabled(bool enabled) = 0; virtual void resetXMPPParser() = 0; void setTLSCertificate(CertificateWithKey::ref cert) { certificate = cert; } virtual bool hasTLSCertificate() { return certificate && !certificate->isNull(); } virtual Certificate::ref getPeerCertificate() const = 0; virtual std::vector<Certificate::ref> getPeerCertificateChain() const = 0; virtual boost::shared_ptr<CertificateVerificationError> getPeerCertificateVerificationError() const = 0; virtual ByteArray getTLSFinishMessage() const = 0; boost::signal<void (const ProtocolHeader&)> onStreamStartReceived; - boost::signal<void (boost::shared_ptr<Element>)> onElementReceived; + boost::signal<void (boost::shared_ptr<ToplevelElement>)> onElementReceived; boost::signal<void (boost::shared_ptr<Error>)> onClosed; boost::signal<void ()> onTLSEncrypted; boost::signal<void (const SafeByteArray&)> onDataRead; boost::signal<void (const SafeByteArray&)> onDataWritten; protected: CertificateWithKey::ref getTLSCertificate() const { return certificate; } private: CertificateWithKey::ref certificate; }; } diff --git a/Swiften/StreamStack/UnitTest/StreamStackTest.cpp b/Swiften/StreamStack/UnitTest/StreamStackTest.cpp index 213948a..35146d6 100644 --- a/Swiften/StreamStack/UnitTest/StreamStackTest.cpp +++ b/Swiften/StreamStack/UnitTest/StreamStackTest.cpp @@ -1,37 +1,37 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #include <Swiften/Base/ByteArray.h> #include <QA/Checker/IO.h> #include <vector> #include <boost/bind.hpp> #include <boost/smart_ptr.hpp> #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> #include <Swiften/Base/ByteArray.h> #include <Swiften/Base/Concat.h> #include <Swiften/StreamStack/StreamStack.h> #include <Swiften/StreamStack/LowLayer.h> #include <Swiften/StreamStack/XMPPLayer.h> #include <Swiften/StreamStack/StreamLayer.h> #include <Swiften/Parser/PlatformXMLParserFactory.h> #include <Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h> #include <Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h> using namespace Swift; class StreamStackTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(StreamStackTest); CPPUNIT_TEST(testWriteData_NoIntermediateStreamStack); CPPUNIT_TEST(testWriteData_OneIntermediateStream); CPPUNIT_TEST(testWriteData_TwoIntermediateStreamStack); CPPUNIT_TEST(testReadData_NoIntermediateStreamStack); CPPUNIT_TEST(testReadData_OneIntermediateStream); CPPUNIT_TEST(testReadData_TwoIntermediateStreamStack); CPPUNIT_TEST(testAddLayer_ExistingOnWriteDataSlot); CPPUNIT_TEST_SUITE_END(); @@ -94,71 +94,71 @@ class StreamStackTest : public CppUnit::TestFixture { void testReadData_OneIntermediateStream() { StreamStack testling(xmppStream_, physicalStream_); xmppStream_->onElement.connect(boost::bind(&StreamStackTest::handleElement, this, _1)); boost::shared_ptr<MyStreamLayer> xStream(new MyStreamLayer("<")); testling.addLayer(xStream.get()); physicalStream_->onDataRead(createSafeByteArray("stream:stream xmlns:stream='http://etherx.jabber.org/streams'><presence/>")); CPPUNIT_ASSERT_EQUAL(1, elementsReceived_); } void testReadData_TwoIntermediateStreamStack() { StreamStack testling(xmppStream_, physicalStream_); xmppStream_->onElement.connect(boost::bind(&StreamStackTest::handleElement, this, _1)); boost::shared_ptr<MyStreamLayer> xStream(new MyStreamLayer("s")); boost::shared_ptr<MyStreamLayer> yStream(new MyStreamLayer("<")); testling.addLayer(xStream.get()); testling.addLayer(yStream.get()); physicalStream_->onDataRead(createSafeByteArray("tream:stream xmlns:stream='http://etherx.jabber.org/streams'><presence/>")); CPPUNIT_ASSERT_EQUAL(1, elementsReceived_); } void testAddLayer_ExistingOnWriteDataSlot() { StreamStack testling(xmppStream_, physicalStream_); xmppStream_->onWriteData.connect(boost::bind(&StreamStackTest::handleWriteData, this, _1)); boost::shared_ptr<MyStreamLayer> xStream(new MyStreamLayer("X")); testling.addLayer(xStream.get()); xmppStream_->writeData("foo"); CPPUNIT_ASSERT_EQUAL(1, dataWriteReceived_); } - void handleElement(boost::shared_ptr<Element>) { + void handleElement(boost::shared_ptr<ToplevelElement>) { ++elementsReceived_; } void handleWriteData(const SafeByteArray&) { ++dataWriteReceived_; } private: class MyStreamLayer : public StreamLayer { public: MyStreamLayer(const std::string& prepend) : prepend_(prepend) { } virtual void writeData(const SafeByteArray& data) { writeDataToChildLayer(concat(createSafeByteArray(prepend_), data)); } virtual void handleDataRead(const SafeByteArray& data) { writeDataToParentLayer(concat(createSafeByteArray(prepend_), data)); } private: std::string prepend_; }; class TestLowLayer : public LowLayer { public: TestLowLayer() { } virtual void writeData(const SafeByteArray& data) { data_.push_back(data); } void onDataRead(const SafeByteArray& data) { diff --git a/Swiften/StreamStack/UnitTest/XMPPLayerTest.cpp b/Swiften/StreamStack/UnitTest/XMPPLayerTest.cpp index a6098f1..ced9ec3 100644 --- a/Swiften/StreamStack/UnitTest/XMPPLayerTest.cpp +++ b/Swiften/StreamStack/UnitTest/XMPPLayerTest.cpp @@ -1,37 +1,37 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #include <vector> #include <boost/bind.hpp> #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> #include <Swiften/Elements/ProtocolHeader.h> #include <Swiften/Elements/Presence.h> #include <Swiften/Base/ByteArray.h> #include <Swiften/StreamStack/XMPPLayer.h> #include <Swiften/StreamStack/LowLayer.h> #include <Swiften/Parser/PlatformXMLParserFactory.h> #include <Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h> #include <Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h> using namespace Swift; class XMPPLayerTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(XMPPLayerTest); CPPUNIT_TEST(testParseData_Error); CPPUNIT_TEST(testResetParser); CPPUNIT_TEST(testResetParser_FromSlot); CPPUNIT_TEST(testWriteHeader); CPPUNIT_TEST(testWriteElement); CPPUNIT_TEST(testWriteFooter); CPPUNIT_TEST_SUITE_END(); public: void setUp() { lowLayer_ = new DummyLowLayer(); testling_ = new XMPPLayerExposed(&parserFactories_, &serializers_, &xmlParserFactory_, ClientStreamType); testling_->setChildLayer(lowLayer_); @@ -62,75 +62,75 @@ class XMPPLayerTest : public CppUnit::TestFixture { testling_->handleDataRead(createSafeByteArray("<presence/>")); CPPUNIT_ASSERT_EQUAL(1, elementsReceived_); CPPUNIT_ASSERT_EQUAL(0, errorReceived_); } void testResetParser_FromSlot() { testling_->onElement.connect(boost::bind(&XMPPLayerTest::handleElementAndReset, this, _1)); testling_->handleDataRead(createSafeByteArray("<stream:stream to=\"example.com\" xmlns=\"jabber:client\" xmlns:stream=\"http://etherx.jabber.org/streams\" ><presence/>")); testling_->handleDataRead(createSafeByteArray("<stream:stream to=\"example.com\" xmlns=\"jabber:client\" xmlns:stream=\"http://etherx.jabber.org/streams\" ><presence/>")); CPPUNIT_ASSERT_EQUAL(2, elementsReceived_); CPPUNIT_ASSERT_EQUAL(0, errorReceived_); } void testWriteHeader() { ProtocolHeader header; header.setTo("example.com"); testling_->writeHeader(header); CPPUNIT_ASSERT_EQUAL(std::string("<?xml version=\"1.0\"?><stream:stream xmlns=\"jabber:client\" xmlns:stream=\"http://etherx.jabber.org/streams\" to=\"example.com\" version=\"1.0\">"), lowLayer_->writtenData); } void testWriteElement() { testling_->writeElement(boost::make_shared<Presence>()); CPPUNIT_ASSERT_EQUAL(std::string("<presence/>"), lowLayer_->writtenData); } void testWriteFooter() { testling_->writeFooter(); CPPUNIT_ASSERT_EQUAL(std::string("</stream:stream>"), lowLayer_->writtenData); } - void handleElement(boost::shared_ptr<Element>) { + void handleElement(boost::shared_ptr<ToplevelElement>) { ++elementsReceived_; } - void handleElementAndReset(boost::shared_ptr<Element>) { + void handleElementAndReset(boost::shared_ptr<ToplevelElement>) { ++elementsReceived_; testling_->resetParser(); } void handleError() { ++errorReceived_; } private: class XMPPLayerExposed : public XMPPLayer { public: XMPPLayerExposed( PayloadParserFactoryCollection* payloadParserFactories, PayloadSerializerCollection* payloadSerializers, XMLParserFactory* xmlParserFactory, StreamType streamType) : XMPPLayer(payloadParserFactories, payloadSerializers, xmlParserFactory, streamType) {} using XMPPLayer::handleDataRead; using HighLayer::setChildLayer; }; class DummyLowLayer : public LowLayer { public: virtual void writeData(const SafeByteArray& data) { writtenData += byteArrayToString(ByteArray(data.begin(), data.end())); } std::string writtenData; }; FullPayloadParserFactoryCollection parserFactories_; FullPayloadSerializerCollection serializers_; DummyLowLayer* lowLayer_; XMPPLayerExposed* testling_; PlatformXMLParserFactory xmlParserFactory_; diff --git a/Swiften/StreamStack/XMPPLayer.cpp b/Swiften/StreamStack/XMPPLayer.cpp index 94afcf9..59418a2 100644 --- a/Swiften/StreamStack/XMPPLayer.cpp +++ b/Swiften/StreamStack/XMPPLayer.cpp @@ -1,97 +1,97 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #include <Swiften/StreamStack/XMPPLayer.h> #include <Swiften/Parser/XMPPParser.h> #include <Swiften/Serializer/XMPPSerializer.h> #include <Swiften/Elements/ProtocolHeader.h> namespace Swift { XMPPLayer::XMPPLayer( PayloadParserFactoryCollection* payloadParserFactories, PayloadSerializerCollection* payloadSerializers, XMLParserFactory* xmlParserFactory, StreamType streamType) : payloadParserFactories_(payloadParserFactories), payloadSerializers_(payloadSerializers), xmlParserFactory_(xmlParserFactory), resetParserAfterParse_(false), inParser_(false) { xmppParser_ = new XMPPParser(this, payloadParserFactories_, xmlParserFactory); xmppSerializer_ = new XMPPSerializer(payloadSerializers_, streamType); } XMPPLayer::~XMPPLayer() { delete xmppSerializer_; delete xmppParser_; } void XMPPLayer::writeHeader(const ProtocolHeader& header) { writeDataInternal(createSafeByteArray(xmppSerializer_->serializeHeader(header))); } void XMPPLayer::writeFooter() { writeDataInternal(createSafeByteArray(xmppSerializer_->serializeFooter())); } -void XMPPLayer::writeElement(boost::shared_ptr<Element> element) { +void XMPPLayer::writeElement(boost::shared_ptr<ToplevelElement> element) { writeDataInternal(xmppSerializer_->serializeElement(element)); } void XMPPLayer::writeData(const std::string& data) { writeDataInternal(createSafeByteArray(data)); } void XMPPLayer::writeDataInternal(const SafeByteArray& data) { onWriteData(data); writeDataToChildLayer(data); } void XMPPLayer::handleDataRead(const SafeByteArray& data) { onDataRead(data); inParser_ = true; // FIXME: Converting to unsafe string. Should be ok, since we don't take passwords // from the stream in clients. If servers start using this, and require safe storage, // we need to fix this. if (!xmppParser_->parse(byteArrayToString(ByteArray(data.begin(), data.end())))) { inParser_ = false; onError(); return; } inParser_ = false; if (resetParserAfterParse_) { doResetParser(); } } void XMPPLayer::doResetParser() { delete xmppParser_; xmppParser_ = new XMPPParser(this, payloadParserFactories_, xmlParserFactory_); resetParserAfterParse_ = false; } void XMPPLayer::handleStreamStart(const ProtocolHeader& header) { onStreamStart(header); } -void XMPPLayer::handleElement(boost::shared_ptr<Element> stanza) { +void XMPPLayer::handleElement(boost::shared_ptr<ToplevelElement> stanza) { onElement(stanza); } void XMPPLayer::handleStreamEnd() { } void XMPPLayer::resetParser() { if (inParser_) { resetParserAfterParse_ = true; } else { doResetParser(); } } } diff --git a/Swiften/StreamStack/XMPPLayer.h b/Swiften/StreamStack/XMPPLayer.h index f0e88aa..bb0e498 100644 --- a/Swiften/StreamStack/XMPPLayer.h +++ b/Swiften/StreamStack/XMPPLayer.h @@ -1,73 +1,73 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <boost/shared_ptr.hpp> #include <Swiften/Base/boost_bsignals.h> #include <boost/noncopyable.hpp> #include <Swiften/Base/API.h> #include <Swiften/StreamStack/HighLayer.h> #include <Swiften/Base/SafeByteArray.h> -#include <Swiften/Elements/Element.h> +#include <Swiften/Elements/ToplevelElement.h> #include <Swiften/Elements/StreamType.h> #include <Swiften/Parser/XMPPParserClient.h> namespace Swift { class ProtocolHeader; class XMPPParser; class PayloadParserFactoryCollection; class XMPPSerializer; class PayloadSerializerCollection; class XMLParserFactory; class BOSHSessionStream; class SWIFTEN_API XMPPLayer : public XMPPParserClient, public HighLayer, boost::noncopyable { friend class BOSHSessionStream; public: XMPPLayer( PayloadParserFactoryCollection* payloadParserFactories, PayloadSerializerCollection* payloadSerializers, XMLParserFactory* xmlParserFactory, StreamType streamType); ~XMPPLayer(); void writeHeader(const ProtocolHeader& header); void writeFooter(); - void writeElement(boost::shared_ptr<Element>); + void writeElement(boost::shared_ptr<ToplevelElement>); void writeData(const std::string& data); void resetParser(); protected: void handleDataRead(const SafeByteArray& data); void writeDataInternal(const SafeByteArray& data); public: boost::signal<void (const ProtocolHeader&)> onStreamStart; - boost::signal<void (boost::shared_ptr<Element>)> onElement; + boost::signal<void (boost::shared_ptr<ToplevelElement>)> onElement; boost::signal<void (const SafeByteArray&)> onWriteData; boost::signal<void (const SafeByteArray&)> onDataRead; boost::signal<void ()> onError; private: void handleStreamStart(const ProtocolHeader&); - void handleElement(boost::shared_ptr<Element>); + void handleElement(boost::shared_ptr<ToplevelElement>); void handleStreamEnd(); void doResetParser(); private: PayloadParserFactoryCollection* payloadParserFactories_; XMPPParser* xmppParser_; PayloadSerializerCollection* payloadSerializers_; XMLParserFactory* xmlParserFactory_; XMPPSerializer* xmppSerializer_; bool resetParserAfterParse_; bool inParser_; }; } |
Swift