summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdwin Mons <edwin.mons@isode.com>2018-10-29 16:28:14 (GMT)
committerEdwin Mons <edwin.mons@isode.com>2018-11-08 11:31:20 (GMT)
commitcf3d517763a3d74a2ec9fd6f7bdee8cbaee3550f (patch)
tree69e11e13ff2e5127d2cbfcc164be761cf104a1b2 /Swiften/Client/CoreClient.cpp
parent5ce9e19ef0744f530a797c30a82e9723eb7ea306 (diff)
downloadswift-cf3d517763a3d74a2ec9fd6f7bdee8cbaee3550f.zip
swift-cf3d517763a3d74a2ec9fd6f7bdee8cbaee3550f.tar.bz2
Consistently use unsigned short for network ports
Network ports are now consistently stored as unsigned shorts, apart from the options and user interface, where -1 is still used to denote the use of default ports. Test-Information: Unit tests pass on macOS 10.13 and Debian 9 On macOS: tested the UI with various proxy and manual ports, behaviour as expected. Change-Id: I7a65f40083022887aa30ed7b21eadc56d0c52be1
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 @@
/*
- * Copyright (c) 2010-2016 Isode Limited.
+ * Copyright (c) 2010-2018 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -85,7 +85,17 @@ void CoreClient::connect(const ClientOptions& o) {
case ClientOptions::SOCKS5Proxy: {
SWIFT_LOG(debug) << " with manual configured SOCKS5 proxy" << std::endl;
std::string proxyHostname = o.manualProxyHostname.empty() ? systemSOCKS5Proxy.getAddress().toString() : o.manualProxyHostname;
- int proxyPort = o.manualProxyPort == -1 ? systemSOCKS5Proxy.getPort() : o.manualProxyPort;
+ auto proxyPort = systemSOCKS5Proxy.getPort();
+ if (o.manualProxyPort != -1) {
+ try {
+ proxyPort = boost::numeric_cast<unsigned short>(o.manualProxyPort);
+ }
+ catch (const boost::numeric::bad_numeric_cast& e) {
+ SWIFT_LOG(warning) << "Manual proxy port " << o.manualProxyPort << " is invalid: " << e.what() << std::endl;
+ onDisconnected(boost::optional<ClientError>(ClientError::ConnectionError));
+ return;
+ }
+ }
SWIFT_LOG(debug) << "Proxy: " << proxyHostname << ":" << proxyPort << std::endl;
proxyConnectionFactories.push_back(new SOCKS5ProxiedConnectionFactory(networkFactories->getDomainNameResolver(), networkFactories->getConnectionFactory(), networkFactories->getTimerFactory(), proxyHostname, proxyPort));
useDirectConnection = false;
@@ -94,7 +104,17 @@ void CoreClient::connect(const ClientOptions& o) {
case ClientOptions::HTTPConnectProxy: {
SWIFT_LOG(debug) << " with manual configured HTTPConnect proxy" << std::endl;
std::string proxyHostname = o.manualProxyHostname.empty() ? systemHTTPConnectProxy.getAddress().toString() : o.manualProxyHostname;
- int proxyPort = o.manualProxyPort == -1 ? systemHTTPConnectProxy.getPort() : o.manualProxyPort;
+ unsigned short proxyPort = systemHTTPConnectProxy.getPort();
+ if (o.manualProxyPort != -1) {
+ try {
+ proxyPort = boost::numeric_cast<unsigned short>(o.manualProxyPort);
+ }
+ catch (const boost::numeric::bad_numeric_cast& e) {
+ SWIFT_LOG(warning) << "Manual proxy port " << o.manualProxyPort << " is invalid: " << e.what() << std::endl;
+ onDisconnected(boost::optional<ClientError>(ClientError::ConnectionError));
+ return;
+ }
+ }
SWIFT_LOG(debug) << "Proxy: " << proxyHostname << ":" << proxyPort << std::endl;
proxyConnectionFactories.push_back(new HTTPConnectProxiedConnectionFactory(networkFactories->getDomainNameResolver(), networkFactories->getConnectionFactory(), networkFactories->getTimerFactory(), proxyHostname, proxyPort, o.httpTrafficFilter));
useDirectConnection = false;
@@ -108,7 +128,17 @@ void CoreClient::connect(const ClientOptions& o) {
// Create connector
std::string host = o.manualHostname.empty() ? jid_.getDomain() : o.manualHostname;
- int port = o.manualPort;
+ unsigned short port = 0;
+ if (o.manualPort != -1) {
+ try {
+ port = boost::numeric_cast<unsigned short>(o.manualPort);
+ }
+ catch (const boost::numeric::bad_numeric_cast& e) {
+ SWIFT_LOG(warning) << "Invalid manual port " << o.manualPort << ": " << e.what() << std::endl;
+ onDisconnected(boost::optional<ClientError>(ClientError::ConnectionError));
+ return;
+ }
+ }
boost::optional<std::string> serviceLookupPrefix;
if (o.manualHostname.empty()) {
serviceLookupPrefix = "_xmpp-client._tcp.";