summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2012-06-02 16:40:22 (GMT)
committerRemko Tronçon <git@el-tramo.be>2012-06-17 07:34:57 (GMT)
commitf171bc207c2a7371ac6924ff467049dd0258aa00 (patch)
treeeda5b5feb94dea264ea26b839b6f9ef5e32c915f /Swiften/Client
parent5a1bdf2f6a4842176be5938f8db5cb9d151aceb5 (diff)
downloadswift-f171bc207c2a7371ac6924ff467049dd0258aa00.zip
swift-f171bc207c2a7371ac6924ff467049dd0258aa00.tar.bz2
Allow different connection methods for Client.
Diffstat (limited to 'Swiften/Client')
-rw-r--r--Swiften/Client/ClientOptions.h51
-rw-r--r--Swiften/Client/CoreClient.cpp56
-rw-r--r--Swiften/Client/CoreClient.h2
3 files changed, 92 insertions, 17 deletions
diff --git a/Swiften/Client/ClientOptions.h b/Swiften/Client/ClientOptions.h
index fbec272..e5fcda9 100644
--- a/Swiften/Client/ClientOptions.h
+++ b/Swiften/Client/ClientOptions.h
@@ -17,7 +17,27 @@ namespace Swift {
RequireTLS
};
- ClientOptions() : useStreamCompression(true), useTLS(UseTLSWhenAvailable), allowPLAINWithoutTLS(false), useStreamResumption(false), forgetPassword(false), useAcks(true), boshHTTPConnectProxyAuthID(""), boshHTTPConnectProxyAuthPassword("") {
+ enum ProxyType {
+ NoProxy,
+ SystemConfiguredProxy,
+ SOCKS5Proxy,
+ HTTPConnectProxy
+ };
+
+ ClientOptions() :
+ useStreamCompression(true),
+ useTLS(UseTLSWhenAvailable),
+ allowPLAINWithoutTLS(false),
+ useStreamResumption(false),
+ forgetPassword(false),
+ useAcks(true),
+ manualHostname(""),
+ manualPort(-1),
+ proxyType(SystemConfiguredProxy),
+ manualProxyHostname(""),
+ manualProxyPort(-1),
+ boshHTTPConnectProxyAuthID(""),
+ boshHTTPConnectProxyAuthPassword("") {
}
/**
@@ -66,6 +86,35 @@ namespace Swift {
bool useAcks;
/**
+ * The hostname to connect to.
+ * Leave this empty for standard XMPP connection, based on the JID domain.
+ */
+ std::string manualHostname;
+
+ /**
+ * The port to connect to.
+ * Leave this to -1 to use the port discovered by SRV lookups, and 5222 as a
+ * fallback.
+ */
+ int manualPort;
+
+ /**
+ * The type of proxy to use for connecting to the XMPP
+ * server.
+ */
+ ProxyType proxyType;
+
+ /**
+ * Override the system-configured proxy hostname.
+ */
+ std::string manualProxyHostname;
+
+ /**
+ * Override the system-configured proxy port.
+ */
+ int manualProxyPort;
+
+ /**
* If non-empty, use BOSH instead of direct TCP, with the given URL.
* Default: empty (no BOSH)
*/
diff --git a/Swiften/Client/CoreClient.cpp b/Swiften/Client/CoreClient.cpp
index 36e27eb..64c0bab 100644
--- a/Swiften/Client/CoreClient.cpp
+++ b/Swiften/Client/CoreClient.cpp
@@ -54,27 +54,55 @@ CoreClient::~CoreClient() {
void CoreClient::connect(const ClientOptions& o) {
SWIFT_LOG(debug) << "Connecting" << std::endl;
- options = o;
- connect(jid_.getDomain());
-}
-void CoreClient::connect(const std::string& host) {
forceReset();
-
- SWIFT_LOG(debug) << "Connecting to host " << host << std::endl;
disconnectRequested_ = false;
- assert(!connector_);
+
+ options = o;
+
+
+ // Determine connection types to use
assert(proxyConnectionFactories.empty());
- if (networkFactories->getProxyProvider()->getSOCKS5Proxy().isValid()) {
- proxyConnectionFactories.push_back(new SOCKS5ProxiedConnectionFactory(networkFactories->getConnectionFactory(), networkFactories->getProxyProvider()->getSOCKS5Proxy()));
- }
- if(networkFactories->getProxyProvider()->getHTTPConnectProxy().isValid()) {
- proxyConnectionFactories.push_back(new HTTPConnectProxiedConnectionFactory(networkFactories->getDomainNameResolver(), networkFactories->getConnectionFactory(), networkFactories->getTimerFactory(), networkFactories->getEventLoop(), networkFactories->getProxyProvider()->getHTTPConnectProxy().getAddress().toString(), networkFactories->getProxyProvider()->getHTTPConnectProxy().getPort()));
+ bool useDirectConnection = true;
+ HostAddressPort systemSOCKS5Proxy = networkFactories->getProxyProvider()->getSOCKS5Proxy();
+ HostAddressPort systemHTTPConnectProxy = networkFactories->getProxyProvider()->getHTTPConnectProxy();
+ switch (o.proxyType) {
+ case ClientOptions::NoProxy:
+ break;
+ case ClientOptions::SystemConfiguredProxy:
+ if (systemSOCKS5Proxy.isValid()) {
+ proxyConnectionFactories.push_back(new SOCKS5ProxiedConnectionFactory(networkFactories->getDomainNameResolver(), networkFactories->getConnectionFactory(), networkFactories->getTimerFactory(), systemSOCKS5Proxy.getAddress().toString(), systemHTTPConnectProxy.getPort()));
+ }
+ if (systemHTTPConnectProxy.isValid()) {
+ proxyConnectionFactories.push_back(new HTTPConnectProxiedConnectionFactory(networkFactories->getDomainNameResolver(), networkFactories->getConnectionFactory(), networkFactories->getTimerFactory(), systemHTTPConnectProxy.getAddress().toString(), systemHTTPConnectProxy.getPort()));
+ }
+ break;
+ case ClientOptions::SOCKS5Proxy: {
+ std::string proxyHostname = o.manualProxyHostname.empty() ? systemSOCKS5Proxy.getAddress().toString() : o.manualProxyHostname;
+ int proxyPort = o.manualProxyPort == -1 ? systemSOCKS5Proxy.getPort() : o.manualProxyPort;
+ proxyConnectionFactories.push_back(new SOCKS5ProxiedConnectionFactory(networkFactories->getDomainNameResolver(), networkFactories->getConnectionFactory(), networkFactories->getTimerFactory(), proxyHostname, proxyPort));
+ useDirectConnection = false;
+ break;
+ }
+ case ClientOptions::HTTPConnectProxy: {
+ std::string proxyHostname = o.manualProxyHostname.empty() ? systemSOCKS5Proxy.getAddress().toString() : o.manualProxyHostname;
+ int proxyPort = o.manualProxyPort == -1 ? systemSOCKS5Proxy.getPort() : o.manualProxyPort;
+ proxyConnectionFactories.push_back(new HTTPConnectProxiedConnectionFactory(networkFactories->getDomainNameResolver(), networkFactories->getConnectionFactory(), networkFactories->getTimerFactory(), proxyHostname, proxyPort));
+ useDirectConnection = false;
+ break;
+ }
}
std::vector<ConnectionFactory*> connectionFactories(proxyConnectionFactories);
- if (options.boshURL.empty()) {
+ if (useDirectConnection) {
connectionFactories.push_back(networkFactories->getConnectionFactory());
- connector_ = boost::make_shared<ChainedConnector>(host, networkFactories->getDomainNameResolver(), connectionFactories, networkFactories->getTimerFactory());
+ }
+
+ // Create connector
+ std::string host = o.manualHostname.empty() ? jid_.getDomain() : o.manualHostname;
+ int port = o.manualPort;
+ assert(!connector_);
+ if (options.boshURL.empty()) {
+ connector_ = boost::make_shared<ChainedConnector>(host, port, o.manualHostname.empty(), networkFactories->getDomainNameResolver(), connectionFactories, networkFactories->getTimerFactory());
connector_->onConnectFinished.connect(boost::bind(&CoreClient::handleConnectorFinished, this, _1, _2));
connector_->setTimeoutMilliseconds(60*1000);
connector_->start();
diff --git a/Swiften/Client/CoreClient.h b/Swiften/Client/CoreClient.h
index 985bf7f..4bb04e2 100644
--- a/Swiften/Client/CoreClient.h
+++ b/Swiften/Client/CoreClient.h
@@ -74,8 +74,6 @@ namespace Swift {
*/
void disconnect();
- void connect(const std::string& host);
-
/**
* Sends a message.
*/