summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
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
@@ -10,24 +10,25 @@
#include "Swiften/Elements/AuthRequest.h"
#include "Swiften/Elements/AuthSuccess.h"
#include "Swiften/Elements/AuthFailure.h"
#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 {
ClientSession::ClientSession(
const JID& jid,
boost::shared_ptr<SessionStream> stream) :
localJID(jid),
state(Initial),
stream(stream),
- needSessionStart(false) {
+ needSessionStart(false),
+ authenticator(NULL) {
}
void ClientSession::start() {
stream->onStreamStartReceived.connect(boost::bind(&ClientSession::handleStreamStart, shared_from_this(), _1));
stream->onElementReceived.connect(boost::bind(&ClientSession::handleElement, shared_from_this(), _1));
stream->onError.connect(boost::bind(&ClientSession::handleStreamError, shared_from_this(), _1));
@@ -74,12 +75,13 @@ void ClientSession::handleElement(boost::shared_ptr<Element> element) {
}
else {
finishSession(Error::TLSClientCertificateError);
}
}
else if (streamFeatures->hasAuthenticationMechanism("PLAIN")) {
+ authenticator = new PLAINClientAuthenticator();
state = WaitingForCredentials;
onNeedCredentials();
}
else {
finishSession(Error::NoSupportedAuthMechanismsError);
}
@@ -109,16 +111,20 @@ 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())) {
checkState(WaitingForEncrypt);
state = Encrypting;
stream->addTLSEncryption();
@@ -187,13 +193,14 @@ bool ClientSession::checkState(State state) {
return true;
}
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() {
checkState(WaitingForEncrypt);
state = WaitingForStreamStart;
stream->resetXMPPParser();
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
@@ -9,12 +9,14 @@
#include "Swiften/Session/BasicSessionStream.h"
#include "Swiften/Base/String.h"
#include "Swiften/JID/JID.h"
#include "Swiften/Elements/Element.h"
namespace Swift {
+ class ClientAuthenticator;
+
class ClientSession : public boost::enable_shared_from_this<ClientSession> {
public:
enum State {
Initial,
WaitingForStreamStart,
Negotiating,
@@ -87,8 +89,9 @@ namespace Swift {
private:
JID localJID;
State state;
boost::shared_ptr<SessionStream> stream;
bool needSessionStart;
+ ClientAuthenticator* authenticator;
};
}