From 0adf0ba15f8217ac760cfafa355f8d712b3c0b6d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Remko=20Tron=C3=A7on?= <git@el-tramo.be>
Date: Wed, 20 Apr 2011 20:18:52 +0200
Subject: Introduce ClientOptions struct.


diff --git a/Sluift/sluift.cpp b/Sluift/sluift.cpp
index 260c923..b911772 100644
--- a/Sluift/sluift.cpp
+++ b/Sluift/sluift.cpp
@@ -62,6 +62,10 @@ class SluiftClient {
 			return client;
 		}
 
+		ClientOptions& getOptions() {
+			return options;
+		}
+
 		void connect() {
 			rosterReceived = false;
 			client->connect();
@@ -178,6 +182,7 @@ class SluiftClient {
 	
 	private:
 		Client* client;
+		ClientOptions options;
 		ClientXMLTracer* tracer;
 		bool rosterReceived;
 		std::deque<Stanza::ref> pendingEvents;
@@ -452,12 +457,12 @@ static int sluift_client_set_options(lua_State* L) {
 	luaL_checktype(L, 2, LUA_TTABLE);
 	lua_getfield(L, 2, "compress");
 	if (!lua_isnil(L, -1)) {
-		client->getClient()->setUseStreamCompression(lua_toboolean(L, -1));
+		client->getOptions().useStreamCompression = lua_toboolean(L, -1);
 	}
 	lua_getfield(L, 2, "tls");
 	if (!lua_isnil(L, -1)) {
 		bool useTLS = lua_toboolean(L, -1);
-		client->getClient()->setUseTLS(useTLS ? Client::UseTLSWhenAvailable : Client::NeverUseTLS);
+		client->getOptions().useTLS = (useTLS ? ClientOptions::UseTLSWhenAvailable : ClientOptions::NeverUseTLS);
 	}
 	lua_pushvalue(L, 1);
 	return 0;
diff --git a/Swiften/Client/CoreClient.cpp b/Swiften/Client/CoreClient.cpp
index f4baca9..de40517 100644
--- a/Swiften/Client/CoreClient.cpp
+++ b/Swiften/Client/CoreClient.cpp
@@ -27,7 +27,7 @@
 
 namespace Swift {
 
-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) {
+CoreClient::CoreClient(const JID& jid, const std::string& password, NetworkFactories* networkFactories) : jid_(jid), password_(password), networkFactories(networkFactories), 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));
@@ -52,8 +52,9 @@ CoreClient::~CoreClient() {
 	delete stanzaChannel_;
 }
 
-void CoreClient::connect() {
+void CoreClient::connect(const ClientOptions& o) {
 	SWIFT_LOG(debug) << "Connecting" << std::endl;
+	options = o;
 	connect(jid_.getDomain());
 }
 
@@ -103,12 +104,12 @@ void CoreClient::handleConnectorFinished(boost::shared_ptr<Connection> connectio
 
 		session_ = ClientSession::create(jid_, sessionStream_);
 		session_->setCertificateTrustChecker(certificateTrustChecker);
-		session_->setUseStreamCompression(useStreamCompression);
-		switch(useTLS) {
-			case UseTLSWhenAvailable:
+		session_->setUseStreamCompression(options.useStreamCompression);
+		switch(options.useTLS) {
+			case ClientOptions::UseTLSWhenAvailable:
 				session_->setUseTLS(ClientSession::UseTLSWhenAvailable);
 				break;
-			case NeverUseTLS:
+			case ClientOptions::NeverUseTLS:
 				session_->setUseTLS(ClientSession::NeverUseTLS);
 				break;
 		}
@@ -296,14 +297,6 @@ void CoreClient::handleStanzaAcked(Stanza::ref stanza) {
 	onStanzaAcked(stanza);
 }
 
-void CoreClient::setUseStreamCompression(bool b) {
-	useStreamCompression = b;
-}
-
-void CoreClient::setUseTLS(UseTLS b) {
-	useTLS = b;
-}
-
 bool CoreClient::isAvailable() const {
 	return stanzaChannel_->isAvailable();
 }
diff --git a/Swiften/Client/CoreClient.h b/Swiften/Client/CoreClient.h
index d7c165f..7c46fe7 100644
--- a/Swiften/Client/CoreClient.h
+++ b/Swiften/Client/CoreClient.h
@@ -13,6 +13,7 @@
 #include <Swiften/Entity/Entity.h>
 #include <Swiften/JID/JID.h>
 #include <Swiften/Client/ClientError.h>
+#include <Swiften/Client/ClientOptions.h>
 
 namespace Swift {
 	class ChainedConnector;
@@ -45,11 +46,6 @@ 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.
@@ -65,7 +61,7 @@ namespace Swift {
 			 * After the connection is established, the client will set 
 			 * initialize the stream and authenticate.
 			 */
-			void connect();
+			void connect(const ClientOptions& = ClientOptions());
 
 			/**
 			 * Disconnects the client from the server.
@@ -137,16 +133,6 @@ namespace Swift {
 			 */
 			void setCertificateTrustChecker(CertificateTrustChecker*);
 
-			/**
-			 * Sets whether ZLib stream compression should be used when available.
-			 */
-			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.
@@ -216,10 +202,9 @@ namespace Swift {
 			JID jid_;
 			std::string password_;
 			NetworkFactories* networkFactories;
-			bool useStreamCompression;
-			UseTLS useTLS;
 			ClientSessionStanzaChannel* stanzaChannel_;
 			IQRouter* iqRouter_;
+			ClientOptions options;
 			boost::shared_ptr<ChainedConnector> connector_;
 			std::vector<ConnectionFactory*> proxyConnectionFactories;
 			PlatformTLSFactories* tlsFactories;
-- 
cgit v0.10.2-6-g49f6