diff options
author | Remko Tronçon <git@el-tramo.be> | 2011-06-18 10:34:41 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2011-06-18 10:41:11 (GMT) |
commit | 362b2d147e4050e997104c24b2ed2e818adab5ed (patch) | |
tree | 63340cf49072e2cc0d9d876859249eb22fd540d3 /Swiften/Server/ServerFromClientSession.cpp | |
parent | 0328d98d29b383ecfcb5ffb66df0a9b7b4d85654 (diff) | |
parent | 7af8a078c57d94ff63eb81f26de2f55eca6b5c00 (diff) | |
download | swift-contrib-362b2d147e4050e997104c24b2ed2e818adab5ed.zip swift-contrib-362b2d147e4050e997104c24b2ed2e818adab5ed.tar.bz2 |
Merge branch 'swift-1.x'
* swift-1.x:
Moving unused server code out of Swiften into Limber.
Conflicts:
Limber/Server/ServerFromClientSession.cpp
Limber/Server/ServerSession.cpp
Limber/Server/ServerStanzaRouter.cpp
Limber/Server/SimpleUserRegistry.cpp
Limber/Server/SimpleUserRegistry.h
Limber/Server/UnitTest/ServerStanzaRouterTest.cpp
Limber/Server/UserRegistry.cpp
Limber/main.cpp
Slimber/Server.cpp
Slimber/Server.h
Diffstat (limited to 'Swiften/Server/ServerFromClientSession.cpp')
-rw-r--r-- | Swiften/Server/ServerFromClientSession.cpp | 117 |
1 files changed, 0 insertions, 117 deletions
diff --git a/Swiften/Server/ServerFromClientSession.cpp b/Swiften/Server/ServerFromClientSession.cpp deleted file mode 100644 index dbe9745..0000000 --- a/Swiften/Server/ServerFromClientSession.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. - */ - -#include <Swiften/Server/ServerFromClientSession.h> - -#include <boost/bind.hpp> - -#include <Swiften/Elements/ProtocolHeader.h> -#include <Swiften/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, - UserRegistry* userRegistry) : - Session(connection, payloadParserFactories, payloadSerializers), - id_(id), - userRegistry_(userRegistry), - authenticated_(false), - initialized(false), - allowSASLEXTERNAL(false) { -} - - -void ServerFromClientSession::handleElement(boost::shared_ptr<Element> 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::shared_ptr<AuthSuccess>(new 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::shared_ptr<AuthSuccess>(new 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()); - getXMPPLayer()->writeElement(IQ::createResult(JID(), iq->getID(), resultResourceBind)); - } - else if (iq->getPayload<StartSession>()) { - getXMPPLayer()->writeElement(IQ::createResult(getRemoteJID(), iq->getID())); - setInitialized(); - } - } - } -} - -void ServerFromClientSession::handleStreamStart(const ProtocolHeader& incomingHeader) { - setLocalJID(JID("", incomingHeader.getTo())); - ProtocolHeader header; - header.setFrom(incomingHeader.getTo()); - header.setID(id_); - getXMPPLayer()->writeHeader(header); - - boost::shared_ptr<StreamFeatures> features(new StreamFeatures()); - if (!authenticated_) { - features->addAuthenticationMechanism("PLAIN"); - if (allowSASLEXTERNAL) { - features->addAuthenticationMechanism("EXTERNAL"); - } - } - else { - features->setHasResourceBind(); - features->setHasSession(); - } - getXMPPLayer()->writeElement(features); -} - -void ServerFromClientSession::setInitialized() { - initialized = true; - onSessionStarted(); -} - -void ServerFromClientSession::setAllowSASLEXTERNAL() { - allowSASLEXTERNAL = true; -} - -} |