diff options
Diffstat (limited to 'Limber')
| -rw-r--r-- | Limber/Server/ServerFromClientSession.cpp | 4 | ||||
| -rw-r--r-- | Limber/Server/ServerFromClientSession.h | 6 | ||||
| -rw-r--r-- | Limber/main.cpp | 4 |
3 files changed, 7 insertions, 7 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_; |
Swift