summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-11-20 21:14:01 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-11-20 21:25:03 (GMT)
commitc84fb752cc881dfca9727b69fcdb3230830b7cc4 (patch)
treeede286a20ccf8daf109f2d1b03c610d6d97f9b8a /Swiften/Client
parent8149107ade43f9c9fff8fe134f1bce5b5e8b2234 (diff)
downloadswift-c84fb752cc881dfca9727b69fcdb3230830b7cc4.zip
swift-c84fb752cc881dfca9727b69fcdb3230830b7cc4.tar.bz2
Abstracting authenticators.
Diffstat (limited to 'Swiften/Client')
-rw-r--r--Swiften/Client/ClientSession.cpp13
-rw-r--r--Swiften/Client/ClientSession.h3
2 files changed, 13 insertions, 3 deletions
diff --git a/Swiften/Client/ClientSession.cpp b/Swiften/Client/ClientSession.cpp
index a95c058..06a7617 100644
--- a/Swiften/Client/ClientSession.cpp
+++ b/Swiften/Client/ClientSession.cpp
@@ -13,7 +13,7 @@
#include "Swiften/Elements/StartSession.h"
#include "Swiften/Elements/IQ.h"
#include "Swiften/Elements/ResourceBind.h"
-#include "Swiften/SASL/PLAINMessage.h"
+#include "Swiften/SASL/PLAINClientAuthenticator.h"
#include "Swiften/Session/SessionStream.h"
namespace Swift {
@@ -24,7 +24,8 @@ ClientSession::ClientSession(
localJID(jid),
state(Initial),
stream(stream),
- needSessionStart(false) {
+ needSessionStart(false),
+ authenticator(NULL) {
}
void ClientSession::start() {
@@ -77,6 +78,7 @@ void ClientSession::handleElement(boost::shared_ptr<Element> element) {
}
}
else if (streamFeatures->hasAuthenticationMechanism("PLAIN")) {
+ authenticator = new PLAINClientAuthenticator();
state = WaitingForCredentials;
onNeedCredentials();
}
@@ -112,10 +114,14 @@ void ClientSession::handleElement(boost::shared_ptr<Element> element) {
else if (dynamic_cast<AuthSuccess*>(element.get())) {
checkState(Authenticating);
state = WaitingForStreamStart;
+ delete authenticator;
+ authenticator = NULL;
stream->resetXMPPParser();
sendStreamHeader();
}
else if (dynamic_cast<AuthFailure*>(element.get())) {
+ delete authenticator;
+ authenticator = NULL;
finishSession(Error::AuthenticationFailedError);
}
else if (dynamic_cast<TLSProceed*>(element.get())) {
@@ -190,7 +196,8 @@ bool ClientSession::checkState(State state) {
void ClientSession::sendCredentials(const String& password) {
assert(WaitingForCredentials);
state = Authenticating;
- stream->writeElement(boost::shared_ptr<Element>(new AuthRequest("PLAIN", PLAINMessage(localJID.getNode(), password).getValue())));
+ authenticator->setCredentials(localJID.getNode(), password);
+ stream->writeElement(boost::shared_ptr<AuthRequest>(new AuthRequest(authenticator->getName(), authenticator->getResponse())));
}
void ClientSession::handleTLSEncrypted() {
diff --git a/Swiften/Client/ClientSession.h b/Swiften/Client/ClientSession.h
index f980a9e..f3bc119 100644
--- a/Swiften/Client/ClientSession.h
+++ b/Swiften/Client/ClientSession.h
@@ -12,6 +12,8 @@
#include "Swiften/Elements/Element.h"
namespace Swift {
+ class ClientAuthenticator;
+
class ClientSession : public boost::enable_shared_from_this<ClientSession> {
public:
enum State {
@@ -90,5 +92,6 @@ namespace Swift {
State state;
boost::shared_ptr<SessionStream> stream;
bool needSessionStart;
+ ClientAuthenticator* authenticator;
};
}