summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Server')
-rw-r--r--Swiften/Server/ServerFromClientSession.cpp21
-rw-r--r--Swiften/Server/ServerFromClientSession.h15
2 files changed, 29 insertions, 7 deletions
diff --git a/Swiften/Server/ServerFromClientSession.cpp b/Swiften/Server/ServerFromClientSession.cpp
index 4fc517f..e6ba28a 100644
--- a/Swiften/Server/ServerFromClientSession.cpp
+++ b/Swiften/Server/ServerFromClientSession.cpp
@@ -54,7 +54,12 @@ ServerFromClientSession::~ServerFromClientSession() {
void ServerFromClientSession::handleElement(boost::shared_ptr<Element> element) {
if (initialized_) {
- onElementReceived(element);
+ if (boost::shared_ptr<Stanza> stanza = boost::dynamic_pointer_cast<Stanza>(element)) {
+ onStanzaReceived(stanza);
+ }
+ else {
+ std::cerr << "Received unexpected element" << std::endl;
+ }
}
else {
if (AuthRequest* authRequest = dynamic_cast<AuthRequest*>(element.get())) {
@@ -64,8 +69,9 @@ void ServerFromClientSession::handleElement(boost::shared_ptr<Element> element)
}
else {
PLAINMessage plainMessage(authRequest->getMessage());
- if (userRegistry_->isValidUserPassword(JID(plainMessage.getAuthenticationID(), domain_), plainMessage.getPassword())) {
+ if (userRegistry_->isValidUserPassword(JID(plainMessage.getAuthenticationID(), domain_.getDomain()), plainMessage.getPassword())) {
xmppLayer_->writeElement(boost::shared_ptr<AuthSuccess>(new AuthSuccess()));
+ user_ = plainMessage.getAuthenticationID();
authenticated_ = true;
xmppLayer_->resetParser();
}
@@ -77,7 +83,7 @@ void ServerFromClientSession::handleElement(boost::shared_ptr<Element> element)
}
else if (IQ* iq = dynamic_cast<IQ*>(element.get())) {
if (boost::shared_ptr<ResourceBind> resourceBind = iq->getPayload<ResourceBind>()) {
- jid_ = JID(user_, domain_, resourceBind->getResource());
+ jid_ = JID(user_, domain_.getDomain(), resourceBind->getResource());
boost::shared_ptr<ResourceBind> resultResourceBind(new ResourceBind());
resultResourceBind->setJID(jid_);
xmppLayer_->writeElement(IQ::createResult(JID(), iq->getID(), resultResourceBind));
@@ -91,8 +97,8 @@ void ServerFromClientSession::handleElement(boost::shared_ptr<Element> element)
}
void ServerFromClientSession::handleStreamStart(const String& domain) {
- domain_ = domain;
- xmppLayer_->writeHeader(domain_, id_);
+ domain_ = JID("", domain);
+ xmppLayer_->writeHeader(domain, id_);
boost::shared_ptr<StreamFeatures> features(new StreamFeatures());
if (!authenticated_) {
@@ -105,4 +111,9 @@ void ServerFromClientSession::handleStreamStart(const String& domain) {
xmppLayer_->writeElement(features);
}
+void ServerFromClientSession::sendStanza(boost::shared_ptr<Stanza> stanza) {
+ xmppLayer_->writeElement(stanza);
+}
+
+
}
diff --git a/Swiften/Server/ServerFromClientSession.h b/Swiften/Server/ServerFromClientSession.h
index 9b340bc..6c74093 100644
--- a/Swiften/Server/ServerFromClientSession.h
+++ b/Swiften/Server/ServerFromClientSession.h
@@ -8,6 +8,7 @@
namespace Swift {
class Element;
+ class Stanza;
class PayloadParserFactoryCollection;
class PayloadSerializerCollection;
class StreamStack;
@@ -27,7 +28,17 @@ namespace Swift {
UserRegistry* userRegistry);
~ServerFromClientSession();
- boost::signal<void (boost::shared_ptr<Element>)> onElementReceived;
+ void sendStanza(boost::shared_ptr<Stanza>);
+
+ const JID& getJID() const {
+ return jid_;
+ }
+
+ const JID& getDomain() const {
+ return domain_;
+ }
+
+ boost::signal<void (boost::shared_ptr<Stanza>)> onStanzaReceived;
boost::signal<void ()> onSessionFinished;
boost::signal<void (const ByteArray&)> onDataWritten;
boost::signal<void (const ByteArray&)> onDataRead;
@@ -47,7 +58,7 @@ namespace Swift {
IncomingConnectionLayer* connectionLayer_;
StreamStack* streamStack_;
XMPPLayer* xmppLayer_;
- String domain_;
+ JID domain_;
String user_;
JID jid_;
};