summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-07-13 20:40:40 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-07-13 20:43:34 (GMT)
commit7f9c693b3d90ebd5bbb7a99d99ba0dc6213dcb47 (patch)
tree8c332e98b7fbfeeee6df5c82f3cdd2307db4008f /Limber/main.cpp
parent43eadfb5d884407c54ccd41cf46881ae374fdf15 (diff)
downloadswift-contrib-7f9c693b3d90ebd5bbb7a99d99ba0dc6213dcb47.zip
swift-contrib-7f9c693b3d90ebd5bbb7a99d99ba0dc6213dcb47.tar.bz2
Implement a clean full login procedure.
Diffstat (limited to 'Limber/main.cpp')
-rw-r--r--Limber/main.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/Limber/main.cpp b/Limber/main.cpp
index c3db296..be7387e 100644
--- a/Limber/main.cpp
+++ b/Limber/main.cpp
@@ -8,11 +8,15 @@
#include <boost/enable_shared_from_this.hpp>
#include <boost/thread.hpp>
+#include "Swiften/Elements/IQ.h"
+#include "Swiften/Elements/RosterPayload.h"
+#include "Swiften/Elements/VCard.h"
#include "Swiften/Server/SimpleUserRegistry.h"
#include "Swiften/Base/ByteArray.h"
#include "Swiften/Base/IDGenerator.h"
#include "Swiften/EventLoop/MainEventLoop.h"
#include "Swiften/EventLoop/SimpleEventLoop.h"
+#include "Swiften/Elements/Stanza.h"
#include "Swiften/Network/ConnectionServer.h"
#include "Swiften/Network/BoostIOServiceThread.h"
#include "Swiften/Server/ServerFromClientSession.h"
@@ -136,6 +140,7 @@ class Server {
void handleNewConnection(boost::shared_ptr<IncomingConnection> c) {
ServerFromClientSession* session = new ServerFromClientSession(idGenerator_.generateID(), c, &payloadParserFactories_, &payloadSerializers_, userRegistry_);
serverFromClientSessions_.push_back(session);
+ session->onStanzaReceived.connect(boost::bind(&Server::handleStanzaReceived, this, _1, session));
session->onSessionFinished.connect(boost::bind(&Server::handleSessionFinished, this, session));
}
@@ -144,6 +149,33 @@ class Server {
delete session;
}
+ void handleStanzaReceived(boost::shared_ptr<Stanza> stanza, ServerFromClientSession* session) {
+ stanza->setFrom(session->getJID());
+ if (!stanza->getTo().isValid()) {
+ stanza->setTo(JID(session->getDomain()));
+ }
+ if (!stanza->getTo().isValid() || stanza->getTo() == session->getDomain() || stanza->getTo() == session->getJID().toBare()) {
+ if (boost::shared_ptr<IQ> iq = boost::dynamic_pointer_cast<IQ>(stanza)) {
+ if (iq->getPayload<RosterPayload>()) {
+ session->sendStanza(IQ::createResult(iq->getFrom(), iq->getID(), boost::shared_ptr<RosterPayload>(new RosterPayload())));
+ }
+ if (iq->getPayload<VCard>()) {
+ if (iq->getType() == IQ::Get) {
+ boost::shared_ptr<VCard> vcard(new VCard());
+ vcard->setNickname(iq->getFrom().getNode());
+ session->sendStanza(IQ::createResult(iq->getFrom(), iq->getID(), vcard));
+ }
+ else {
+ session->sendStanza(IQ::createError(iq->getFrom(), iq->getID(), Error::Forbidden, Error::Cancel));
+ }
+ }
+ else {
+ session->sendStanza(IQ::createError(iq->getFrom(), iq->getID(), Error::FeatureNotImplemented, Error::Cancel));
+ }
+ }
+ }
+ }
+
private:
IDGenerator idGenerator_;
UserRegistry* userRegistry_;