summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Client/CoreClient.cpp')
-rw-r--r--Swiften/Client/CoreClient.cpp38
1 files changed, 34 insertions, 4 deletions
diff --git a/Swiften/Client/CoreClient.cpp b/Swiften/Client/CoreClient.cpp
index 1de1d61..d3711cb 100644
--- a/Swiften/Client/CoreClient.cpp
+++ b/Swiften/Client/CoreClient.cpp
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2010-2016 Isode Limited. 2 * Copyright (c) 2010-2018 Isode Limited.
3 * All rights reserved. 3 * All rights reserved.
4 * See the COPYING file for more information. 4 * See the COPYING file for more information.
5 */ 5 */
@@ -85,7 +85,17 @@ void CoreClient::connect(const ClientOptions& o) {
85 case ClientOptions::SOCKS5Proxy: { 85 case ClientOptions::SOCKS5Proxy: {
86 SWIFT_LOG(debug) << " with manual configured SOCKS5 proxy" << std::endl; 86 SWIFT_LOG(debug) << " with manual configured SOCKS5 proxy" << std::endl;
87 std::string proxyHostname = o.manualProxyHostname.empty() ? systemSOCKS5Proxy.getAddress().toString() : o.manualProxyHostname; 87 std::string proxyHostname = o.manualProxyHostname.empty() ? systemSOCKS5Proxy.getAddress().toString() : o.manualProxyHostname;
88 int proxyPort = o.manualProxyPort == -1 ? systemSOCKS5Proxy.getPort() : o.manualProxyPort; 88 auto proxyPort = systemSOCKS5Proxy.getPort();
89 if (o.manualProxyPort != -1) {
90 try {
91 proxyPort = boost::numeric_cast<unsigned short>(o.manualProxyPort);
92 }
93 catch (const boost::numeric::bad_numeric_cast& e) {
94 SWIFT_LOG(warning) << "Manual proxy port " << o.manualProxyPort << " is invalid: " << e.what() << std::endl;
95 onDisconnected(boost::optional<ClientError>(ClientError::ConnectionError));
96 return;
97 }
98 }
89 SWIFT_LOG(debug) << "Proxy: " << proxyHostname << ":" << proxyPort << std::endl; 99 SWIFT_LOG(debug) << "Proxy: " << proxyHostname << ":" << proxyPort << std::endl;
90 proxyConnectionFactories.push_back(new SOCKS5ProxiedConnectionFactory(networkFactories->getDomainNameResolver(), networkFactories->getConnectionFactory(), networkFactories->getTimerFactory(), proxyHostname, proxyPort)); 100 proxyConnectionFactories.push_back(new SOCKS5ProxiedConnectionFactory(networkFactories->getDomainNameResolver(), networkFactories->getConnectionFactory(), networkFactories->getTimerFactory(), proxyHostname, proxyPort));
91 useDirectConnection = false; 101 useDirectConnection = false;
@@ -94,7 +104,17 @@ void CoreClient::connect(const ClientOptions& o) {
94 case ClientOptions::HTTPConnectProxy: { 104 case ClientOptions::HTTPConnectProxy: {
95 SWIFT_LOG(debug) << " with manual configured HTTPConnect proxy" << std::endl; 105 SWIFT_LOG(debug) << " with manual configured HTTPConnect proxy" << std::endl;
96 std::string proxyHostname = o.manualProxyHostname.empty() ? systemHTTPConnectProxy.getAddress().toString() : o.manualProxyHostname; 106 std::string proxyHostname = o.manualProxyHostname.empty() ? systemHTTPConnectProxy.getAddress().toString() : o.manualProxyHostname;
97 int proxyPort = o.manualProxyPort == -1 ? systemHTTPConnectProxy.getPort() : o.manualProxyPort; 107 unsigned short proxyPort = systemHTTPConnectProxy.getPort();
108 if (o.manualProxyPort != -1) {
109 try {
110 proxyPort = boost::numeric_cast<unsigned short>(o.manualProxyPort);
111 }
112 catch (const boost::numeric::bad_numeric_cast& e) {
113 SWIFT_LOG(warning) << "Manual proxy port " << o.manualProxyPort << " is invalid: " << e.what() << std::endl;
114 onDisconnected(boost::optional<ClientError>(ClientError::ConnectionError));
115 return;
116 }
117 }
98 SWIFT_LOG(debug) << "Proxy: " << proxyHostname << ":" << proxyPort << std::endl; 118 SWIFT_LOG(debug) << "Proxy: " << proxyHostname << ":" << proxyPort << std::endl;
99 proxyConnectionFactories.push_back(new HTTPConnectProxiedConnectionFactory(networkFactories->getDomainNameResolver(), networkFactories->getConnectionFactory(), networkFactories->getTimerFactory(), proxyHostname, proxyPort, o.httpTrafficFilter)); 119 proxyConnectionFactories.push_back(new HTTPConnectProxiedConnectionFactory(networkFactories->getDomainNameResolver(), networkFactories->getConnectionFactory(), networkFactories->getTimerFactory(), proxyHostname, proxyPort, o.httpTrafficFilter));
100 useDirectConnection = false; 120 useDirectConnection = false;
@@ -108,7 +128,17 @@ void CoreClient::connect(const ClientOptions& o) {
108 128
109 // Create connector 129 // Create connector
110 std::string host = o.manualHostname.empty() ? jid_.getDomain() : o.manualHostname; 130 std::string host = o.manualHostname.empty() ? jid_.getDomain() : o.manualHostname;
111 int port = o.manualPort; 131 unsigned short port = 0;
132 if (o.manualPort != -1) {
133 try {
134 port = boost::numeric_cast<unsigned short>(o.manualPort);
135 }
136 catch (const boost::numeric::bad_numeric_cast& e) {
137 SWIFT_LOG(warning) << "Invalid manual port " << o.manualPort << ": " << e.what() << std::endl;
138 onDisconnected(boost::optional<ClientError>(ClientError::ConnectionError));
139 return;
140 }
141 }
112 boost::optional<std::string> serviceLookupPrefix; 142 boost::optional<std::string> serviceLookupPrefix;
113 if (o.manualHostname.empty()) { 143 if (o.manualHostname.empty()) {
114 serviceLookupPrefix = "_xmpp-client._tcp."; 144 serviceLookupPrefix = "_xmpp-client._tcp.";