diff options
author | Remko Tronçon <git@el-tramo.be> | 2011-03-01 20:17:23 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2011-03-01 20:17:23 (GMT) |
commit | ca3f25d09a703ff7c27267a5591ce5379886e1c9 (patch) | |
tree | b14c38655ea3c61beb79f8a895fc7e6ce2989a9e /Swiften/Client | |
parent | 5ad284705760c451012a5d896251af538e7bcede (diff) | |
download | swift-contrib-ca3f25d09a703ff7c27267a5591ce5379886e1c9.zip swift-contrib-ca3f25d09a703ff7c27267a5591ce5379886e1c9.tar.bz2 |
Some more Sluift enhancements.
Diffstat (limited to 'Swiften/Client')
-rw-r--r-- | Swiften/Client/ClientSession.cpp | 3 | ||||
-rw-r--r-- | Swiften/Client/ClientSession.h | 11 | ||||
-rw-r--r-- | Swiften/Client/CoreClient.cpp | 18 | ||||
-rw-r--r-- | Swiften/Client/CoreClient.h | 16 | ||||
-rw-r--r-- | Swiften/Client/UnitTest/ClientSessionTest.cpp | 3 |
5 files changed, 49 insertions, 2 deletions
diff --git a/Swiften/Client/ClientSession.cpp b/Swiften/Client/ClientSession.cpp index 8d9e678..e1c1d8e 100644 --- a/Swiften/Client/ClientSession.cpp +++ b/Swiften/Client/ClientSession.cpp @@ -50,6 +50,7 @@ ClientSession::ClientSession( stream(stream), allowPLAINOverNonTLS(false), useStreamCompression(true), + useTLS(UseTLSWhenAvailable), needSessionStart(false), needResourceBind(false), needAcking(false), @@ -170,7 +171,7 @@ void ClientSession::handleElement(boost::shared_ptr<Element> element) { return; } - if (streamFeatures->hasStartTLS() && stream->supportsTLSEncryption()) { + if (streamFeatures->hasStartTLS() && stream->supportsTLSEncryption() && useTLS != NeverUseTLS) { state = WaitingForEncrypt; stream->writeElement(boost::shared_ptr<StartTLSRequest>(new StartTLSRequest())); } diff --git a/Swiften/Client/ClientSession.h b/Swiften/Client/ClientSession.h index ee3992d..25ee694 100644 --- a/Swiften/Client/ClientSession.h +++ b/Swiften/Client/ClientSession.h @@ -57,6 +57,11 @@ namespace Swift { Error(Type type) : type(type) {} }; + enum UseTLS { + NeverUseTLS, + UseTLSWhenAvailable + }; + ~ClientSession(); static boost::shared_ptr<ClientSession> create(const JID& jid, boost::shared_ptr<SessionStream> stream) { @@ -75,6 +80,11 @@ namespace Swift { useStreamCompression = b; } + void setUseTLS(UseTLS b) { + useTLS = b; + } + + bool getStreamManagementEnabled() const { return stanzaAckRequester_; } @@ -139,6 +149,7 @@ namespace Swift { boost::shared_ptr<SessionStream> stream; bool allowPLAINOverNonTLS; bool useStreamCompression; + UseTLS useTLS; bool needSessionStart; bool needResourceBind; bool needAcking; diff --git a/Swiften/Client/CoreClient.cpp b/Swiften/Client/CoreClient.cpp index a199b16..f0c5333 100644 --- a/Swiften/Client/CoreClient.cpp +++ b/Swiften/Client/CoreClient.cpp @@ -22,7 +22,7 @@ namespace Swift { -CoreClient::CoreClient(const JID& jid, const std::string& password, NetworkFactories* networkFactories) : jid_(jid), password_(password), networkFactories(networkFactories), useStreamCompression(true), disconnectRequested_(false), certificateTrustChecker(NULL) { +CoreClient::CoreClient(const JID& jid, const std::string& password, NetworkFactories* networkFactories) : jid_(jid), password_(password), networkFactories(networkFactories), useStreamCompression(true), useTLS(UseTLSWhenAvailable), disconnectRequested_(false), certificateTrustChecker(NULL) { stanzaChannel_ = new ClientSessionStanzaChannel(); stanzaChannel_->onMessageReceived.connect(boost::bind(&CoreClient::handleMessageReceived, this, _1)); stanzaChannel_->onPresenceReceived.connect(boost::bind(&CoreClient::handlePresenceReceived, this, _1)); @@ -83,6 +83,14 @@ void CoreClient::handleConnectorFinished(boost::shared_ptr<Connection> connectio session_ = ClientSession::create(jid_, sessionStream_); session_->setCertificateTrustChecker(certificateTrustChecker); session_->setUseStreamCompression(useStreamCompression); + switch(useTLS) { + case UseTLSWhenAvailable: + session_->setUseTLS(ClientSession::UseTLSWhenAvailable); + break; + case NeverUseTLS: + session_->setUseTLS(ClientSession::NeverUseTLS); + break; + } stanzaChannel_->setSession(session_); session_->onFinished.connect(boost::bind(&CoreClient::handleSessionFinished, this, _1)); session_->onNeedCredentials.connect(boost::bind(&CoreClient::handleNeedCredentials, this)); @@ -242,6 +250,10 @@ void CoreClient::sendPresence(boost::shared_ptr<Presence> presence) { stanzaChannel_->sendPresence(presence); } +void CoreClient::sendData(const std::string& data) { + sessionStream_->writeData(data); +} + bool CoreClient::isActive() const { return (session_ && !session_->isFinished()) || connector_; } @@ -267,5 +279,9 @@ void CoreClient::setUseStreamCompression(bool b) { useStreamCompression = b; } +void CoreClient::setUseTLS(UseTLS b) { + useTLS = b; +} + } diff --git a/Swiften/Client/CoreClient.h b/Swiften/Client/CoreClient.h index ee73396..eb9c42c 100644 --- a/Swiften/Client/CoreClient.h +++ b/Swiften/Client/CoreClient.h @@ -48,6 +48,11 @@ namespace Swift { */ class CoreClient : public Entity { public: + enum UseTLS { + NeverUseTLS, + UseTLSWhenAvailable + }; + /** * Constructs a client for the given JID with the given password. * The given eventLoop will be used to post events to. @@ -83,6 +88,11 @@ namespace Swift { void sendPresence(Presence::ref); /** + * Sends raw, unchecked data. + */ + void sendData(const std::string& data); + + /** * Returns the IQ router for this client. */ IQRouter* getIQRouter() const { @@ -148,6 +158,11 @@ namespace Swift { */ void setUseStreamCompression(bool b); + /** + * Sets whether TLS encryption should be used. + */ + void setUseTLS(UseTLS useTLS); + public: /** * Emitted when the client was disconnected from the network. @@ -213,6 +228,7 @@ namespace Swift { std::string password_; NetworkFactories* networkFactories; bool useStreamCompression; + UseTLS useTLS; ClientSessionStanzaChannel* stanzaChannel_; IQRouter* iqRouter_; Connector::ref connector_; diff --git a/Swiften/Client/UnitTest/ClientSessionTest.cpp b/Swiften/Client/UnitTest/ClientSessionTest.cpp index 21c0ffb..756287c 100644 --- a/Swiften/Client/UnitTest/ClientSessionTest.cpp +++ b/Swiften/Client/UnitTest/ClientSessionTest.cpp @@ -329,6 +329,9 @@ class ClientSessionTest : public CppUnit::TestFixture { receivedEvents.push_back(Event(element)); } + virtual void writeData(const std::string&) { + } + virtual bool supportsTLSEncryption() { return canTLSEncrypt; } |