summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-07-19 14:06:18 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-07-19 14:06:18 (GMT)
commitd66658252e70abfc2d4eb7cf5f694ba5dc824291 (patch)
tree516515e36150034a1142aaf9e69e4b1d2058fe70 /Swiften/Client
parent958fe81b045e54ed6dadfe1fa9b14ac317811abf (diff)
downloadswift-d66658252e70abfc2d4eb7cf5f694ba5dc824291.zip
swift-d66658252e70abfc2d4eb7cf5f694ba5dc824291.tar.bz2
Factor out remote & local JID into Session.
Diffstat (limited to 'Swiften/Client')
-rw-r--r--Swiften/Client/ClientSession.cpp15
-rw-r--r--Swiften/Client/ClientSession.h5
-rw-r--r--Swiften/Client/UnitTest/ClientSessionTest.cpp6
3 files changed, 11 insertions, 15 deletions
diff --git a/Swiften/Client/ClientSession.cpp b/Swiften/Client/ClientSession.cpp
index 4fcf1f8..802ac0a 100644
--- a/Swiften/Client/ClientSession.cpp
+++ b/Swiften/Client/ClientSession.cpp
@@ -31,10 +31,11 @@ ClientSession::ClientSession(
PayloadParserFactoryCollection* payloadParserFactories,
PayloadSerializerCollection* payloadSerializers) :
Session(connection, payloadParserFactories, payloadSerializers),
- jid_(jid),
tlsLayerFactory_(tlsLayerFactory),
state_(Initial),
needSessionStart_(false) {
+ setLocalJID(jid);
+ setRemoteJID(JID("", jid.getDomain()));
}
void ClientSession::handleSessionStarted() {
@@ -45,7 +46,7 @@ void ClientSession::handleSessionStarted() {
void ClientSession::sendStreamHeader() {
ProtocolHeader header;
- header.setTo(jid_.getDomain());
+ header.setTo(getRemoteJID());
getXMPPLayer()->writeHeader(header);
}
@@ -103,8 +104,8 @@ void ClientSession::handleElement(boost::shared_ptr<Element> element) {
if (streamFeatures->hasResourceBind()) {
state_ = BindingResource;
boost::shared_ptr<ResourceBind> resourceBind(new ResourceBind());
- if (!jid_.getResource().isEmpty()) {
- resourceBind->setResource(jid_.getResource());
+ if (!getLocalJID().getResource().isEmpty()) {
+ resourceBind->setResource(getLocalJID().getResource());
}
getXMPPLayer()->writeElement(IQ::createRequest(IQ::Set, JID(), "session-bind", resourceBind));
}
@@ -151,8 +152,8 @@ void ClientSession::handleElement(boost::shared_ptr<Element> element) {
finishSession(UnexpectedElementError);
}
else if (iq->getType() == IQ::Result) {
- jid_ = resourceBind->getJID();
- if (!jid_.isValid()) {
+ setLocalJID(resourceBind->getJID());
+ if (!getLocalJID().isValid()) {
finishSession(ResourceBindError);
}
if (needSessionStart_) {
@@ -216,7 +217,7 @@ bool ClientSession::checkState(State state) {
void ClientSession::sendCredentials(const String& password) {
assert(WaitingForCredentials);
state_ = Authenticating;
- getXMPPLayer()->writeElement(boost::shared_ptr<Element>(new AuthRequest("PLAIN", PLAINMessage(jid_.getNode(), password).getValue())));
+ getXMPPLayer()->writeElement(boost::shared_ptr<Element>(new AuthRequest("PLAIN", PLAINMessage(getLocalJID().getNode(), password).getValue())));
}
void ClientSession::handleTLSConnected() {
diff --git a/Swiften/Client/ClientSession.h b/Swiften/Client/ClientSession.h
index 22e4a88..cb1e098 100644
--- a/Swiften/Client/ClientSession.h
+++ b/Swiften/Client/ClientSession.h
@@ -54,10 +54,6 @@ namespace Swift {
return error_;
}
- const JID& getJID() const {
- return jid_;
- }
-
void sendCredentials(const String& password);
void setCertificate(const PKCS12Certificate& certificate);
@@ -80,7 +76,6 @@ namespace Swift {
boost::signal<void ()> onNeedCredentials;
private:
- JID jid_;
TLSLayerFactory* tlsLayerFactory_;
State state_;
boost::optional<SessionError> error_;
diff --git a/Swiften/Client/UnitTest/ClientSessionTest.cpp b/Swiften/Client/UnitTest/ClientSessionTest.cpp
index c86442d..a44b0df 100644
--- a/Swiften/Client/UnitTest/ClientSessionTest.cpp
+++ b/Swiften/Client/UnitTest/ClientSessionTest.cpp
@@ -259,7 +259,7 @@ class ClientSessionTest : public CppUnit::TestFixture {
processEvents();
CPPUNIT_ASSERT_EQUAL(ClientSession::SessionStarted, session->getState());
- CPPUNIT_ASSERT_EQUAL(JID("me@foo.com/Bar"), session->getJID());
+ CPPUNIT_ASSERT_EQUAL(JID("me@foo.com/Bar"), session->getLocalJID());
}
void testResourceBind_ChangeResource() {
@@ -273,7 +273,7 @@ class ClientSessionTest : public CppUnit::TestFixture {
processEvents();
CPPUNIT_ASSERT_EQUAL(ClientSession::SessionStarted, session->getState());
- CPPUNIT_ASSERT_EQUAL(JID("me@foo.com/Bar123"), session->getJID());
+ CPPUNIT_ASSERT_EQUAL(JID("me@foo.com/Bar123"), session->getLocalJID());
}
void testResourceBind_EmptyResource() {
@@ -287,7 +287,7 @@ class ClientSessionTest : public CppUnit::TestFixture {
processEvents();
CPPUNIT_ASSERT_EQUAL(ClientSession::SessionStarted, session->getState());
- CPPUNIT_ASSERT_EQUAL(JID("me@foo.com/NewResource"), session->getJID());
+ CPPUNIT_ASSERT_EQUAL(JID("me@foo.com/NewResource"), session->getLocalJID());
}
void testResourceBind_Error() {