summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Slimber/Server.cpp6
-rw-r--r--Slimber/Server.h14
-rw-r--r--Sluift/SluiftClient.h1
-rw-r--r--Sluift/SluiftComponent.cpp2
-rw-r--r--Sluift/SluiftComponent.h2
-rw-r--r--Sluift/component.cpp4
-rw-r--r--Swiften/Base/URL.cpp12
-rw-r--r--Swiften/Base/URL.h10
-rw-r--r--Swiften/Base/UnitTest/URLTest.cpp26
-rw-r--r--Swiften/Client/CoreClient.cpp38
-rw-r--r--Swiften/Component/ComponentConnector.cpp4
-rw-r--r--Swiften/Component/ComponentConnector.h8
-rw-r--r--Swiften/Component/CoreComponent.cpp2
-rw-r--r--Swiften/Component/CoreComponent.h2
-rw-r--r--Swiften/Component/UnitTest/ComponentConnectorTest.cpp4
-rw-r--r--Swiften/Elements/Bytestreams.h6
-rw-r--r--Swiften/Elements/S5BProxyRequest.h4
-rw-r--r--Swiften/FileTransfer/SOCKS5BytestreamServerManager.cpp6
-rw-r--r--Swiften/FileTransfer/SOCKS5BytestreamServerManager.h4
-rw-r--r--Swiften/LinkLocal/DNSSD/Avahi/AvahiQuerier.cpp4
-rw-r--r--Swiften/LinkLocal/DNSSD/Avahi/AvahiQuerier.h4
-rw-r--r--Swiften/LinkLocal/DNSSD/Avahi/AvahiRegisterQuery.h6
-rw-r--r--Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.cpp5
-rw-r--r--Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.h4
-rw-r--r--Swiften/LinkLocal/DNSSD/Bonjour/BonjourRegisterQuery.h24
-rw-r--r--Swiften/LinkLocal/DNSSD/DNSSDQuerier.h4
-rw-r--r--Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.h6
-rw-r--r--Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.cpp6
-rw-r--r--Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.h6
-rw-r--r--Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDRegisterQuery.h6
-rw-r--r--Swiften/LinkLocal/LinkLocalService.h4
-rw-r--r--Swiften/LinkLocal/LinkLocalServiceBrowser.cpp4
-rw-r--r--Swiften/LinkLocal/LinkLocalServiceBrowser.h4
-rw-r--r--Swiften/LinkLocal/LinkLocalServiceInfo.cpp10
-rw-r--r--Swiften/LinkLocal/LinkLocalServiceInfo.h8
-rw-r--r--Swiften/LinkLocal/UnitTest/LinkLocalConnectorTest.cpp6
-rw-r--r--Swiften/Network/BoostConnectionServer.cpp10
-rw-r--r--Swiften/Network/BoostConnectionServer.h12
-rw-r--r--Swiften/Network/BoostConnectionServerFactory.cpp4
-rw-r--r--Swiften/Network/BoostConnectionServerFactory.h6
-rw-r--r--Swiften/Network/ChainedConnector.cpp4
-rw-r--r--Swiften/Network/ChainedConnector.h6
-rw-r--r--Swiften/Network/ConnectionServerFactory.h6
-rw-r--r--Swiften/Network/Connector.cpp4
-rw-r--r--Swiften/Network/Connector.h8
-rw-r--r--Swiften/Network/DomainNameServiceQuery.cpp25
-rw-r--r--Swiften/Network/DomainNameServiceQuery.h6
-rw-r--r--Swiften/Network/DummyConnectionServer.h6
-rw-r--r--Swiften/Network/DummyConnectionServerFactory.h6
-rw-r--r--Swiften/Network/EnvironmentProxyProvider.cpp10
-rw-r--r--Swiften/Network/GConfProxyProvider.cpp12
-rw-r--r--Swiften/Network/HTTPConnectProxiedConnection.cpp4
-rw-r--r--Swiften/Network/HTTPConnectProxiedConnection.h6
-rw-r--r--Swiften/Network/HTTPConnectProxiedConnectionFactory.cpp6
-rw-r--r--Swiften/Network/HTTPConnectProxiedConnectionFactory.h8
-rw-r--r--Swiften/Network/HostAddressPort.cpp4
-rw-r--r--Swiften/Network/HostAddressPort.h8
-rw-r--r--Swiften/Network/MacOSXProxyProvider.cpp8
-rw-r--r--Swiften/Network/MiniUPnPInterface.cpp4
-rw-r--r--Swiften/Network/MiniUPnPInterface.h4
-rw-r--r--Swiften/Network/NATPMPInterface.cpp8
-rw-r--r--Swiften/Network/NATPMPInterface.h4
-rw-r--r--Swiften/Network/NATPortMapping.h10
-rw-r--r--Swiften/Network/NATTraversalInterface.h4
-rw-r--r--Swiften/Network/NATTraversalRemovePortForwardingRequest.h6
-rw-r--r--Swiften/Network/NATTraverser.h6
-rw-r--r--Swiften/Network/NullNATTraversalInterface.h2
-rw-r--r--Swiften/Network/NullNATTraverser.cpp6
-rw-r--r--Swiften/Network/NullNATTraverser.h6
-rw-r--r--Swiften/Network/PlatformDomainNameServiceQuery.cpp57
-rw-r--r--Swiften/Network/PlatformNATTraversalWorker.cpp12
-rw-r--r--Swiften/Network/PlatformNATTraversalWorker.h6
-rw-r--r--Swiften/Network/ProxiedConnection.cpp4
-rw-r--r--Swiften/Network/ProxiedConnection.h6
-rw-r--r--Swiften/Network/SOCKS5ProxiedConnection.cpp4
-rw-r--r--Swiften/Network/SOCKS5ProxiedConnection.h6
-rw-r--r--Swiften/Network/SOCKS5ProxiedConnectionFactory.cpp2
-rw-r--r--Swiften/Network/SOCKS5ProxiedConnectionFactory.h6
-rw-r--r--Swiften/Network/StaticDomainNameResolver.cpp4
-rw-r--r--Swiften/Network/StaticDomainNameResolver.h4
-rw-r--r--Swiften/Network/UnitTest/ConnectorTest.cpp8
-rw-r--r--Swiften/Network/UnitTest/HTTPConnectProxiedConnectionTest.cpp4
-rw-r--r--Swiften/Network/WindowsProxyProvider.cpp5
-rw-r--r--Swiften/Parser/PayloadParsers/BytestreamsParser.cpp7
-rw-r--r--Swiften/Parser/PayloadParsers/JingleS5BTransportMethodPayloadParser.cpp9
-rw-r--r--Swiften/Parser/PayloadParsers/S5BProxyRequestParser.cpp12
-rw-r--r--Swiften/QA/ClientTest/ClientTest.cpp15
-rw-r--r--Swiften/QA/NetworkTest/DomainNameResolverTest.cpp10
88 files changed, 384 insertions, 292 deletions
diff --git a/Slimber/Server.cpp b/Slimber/Server.cpp
index 3bc3112..bfa34f5 100644
--- a/Slimber/Server.cpp
+++ b/Slimber/Server.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 */
@@ -39,8 +39,8 @@
39namespace Swift { 39namespace Swift {
40 40
41Server::Server( 41Server::Server(
42 int clientConnectionPort, 42 unsigned short clientConnectionPort,
43 int linkLocalConnectionPort, 43 unsigned short linkLocalConnectionPort,
44 LinkLocalServiceBrowser* linkLocalServiceBrowser, 44 LinkLocalServiceBrowser* linkLocalServiceBrowser,
45 VCardCollection* vCardCollection, 45 VCardCollection* vCardCollection,
46 EventLoop* eventLoop) : 46 EventLoop* eventLoop) :
diff --git a/Slimber/Server.h b/Slimber/Server.h
index 4842cd9..2ee5a4a 100644
--- a/Slimber/Server.h
+++ b/Slimber/Server.h
@@ -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 */
@@ -41,8 +41,8 @@ namespace Swift {
41 class Server { 41 class Server {
42 public: 42 public:
43 Server( 43 Server(
44 int clientConnectionPort, 44 unsigned short clientConnectionPort,
45 int linkLocalConnectionPort, 45 unsigned short linkLocalConnectionPort,
46 LinkLocalServiceBrowser* browser, 46 LinkLocalServiceBrowser* browser,
47 VCardCollection* vCardCollection, 47 VCardCollection* vCardCollection,
48 EventLoop* eventLoop); 48 EventLoop* eventLoop);
@@ -51,11 +51,11 @@ namespace Swift {
51 void start(); 51 void start();
52 void stop(); 52 void stop();
53 53
54 int getLinkLocalPort() const { 54 unsigned short getLinkLocalPort() const {
55 return linkLocalConnectionPort; 55 return linkLocalConnectionPort;
56 } 56 }
57 57
58 int getClientToServerPort() const { 58 unsigned short getClientToServerPort() const {
59 return clientConnectionPort; 59 return clientConnectionPort;
60 } 60 }
61 61
@@ -105,8 +105,8 @@ namespace Swift {
105 PlatformXMLParserFactory xmlParserFactory; 105 PlatformXMLParserFactory xmlParserFactory;
106 bool linkLocalServiceRegistered; 106 bool linkLocalServiceRegistered;
107 bool rosterRequested; 107 bool rosterRequested;
108 int clientConnectionPort; 108 unsigned short clientConnectionPort;
109 int linkLocalConnectionPort; 109 unsigned short linkLocalConnectionPort;
110 LinkLocalServiceBrowser* linkLocalServiceBrowser; 110 LinkLocalServiceBrowser* linkLocalServiceBrowser;
111 VCardCollection* vCardCollection; 111 VCardCollection* vCardCollection;
112 EventLoop* eventLoop; 112 EventLoop* eventLoop;
diff --git a/Sluift/SluiftClient.h b/Sluift/SluiftClient.h
index 8cc815d..39ff0a8 100644
--- a/Sluift/SluiftClient.h
+++ b/Sluift/SluiftClient.h
@@ -81,7 +81,6 @@ namespace Swift {
81 } 81 }
82 82
83 void connect(); 83 void connect();
84 void connect(const std::string& host, int port);
85 void waitConnected(int timeout); 84 void waitConnected(int timeout);
86 bool isConnected() const; 85 bool isConnected() const;
87 void setTraceEnabled(bool b); 86 void setTraceEnabled(bool b);
diff --git a/Sluift/SluiftComponent.cpp b/Sluift/SluiftComponent.cpp
index ee09380..74728ee 100644
--- a/Sluift/SluiftComponent.cpp
+++ b/Sluift/SluiftComponent.cpp
@@ -40,7 +40,7 @@ SluiftComponent::~SluiftComponent() {
40 delete component; 40 delete component;
41} 41}
42 42
43void SluiftComponent::connect(const std::string& host, int port) { 43void SluiftComponent::connect(const std::string& host, unsigned short port) {
44 if (component->isActive()) { 44 if (component->isActive()) {
45 throw Lua::Exception("Component is already connecting or connected"); 45 throw Lua::Exception("Component is already connecting or connected");
46 } 46 }
diff --git a/Sluift/SluiftComponent.h b/Sluift/SluiftComponent.h
index 9fc7101..586a94e 100644
--- a/Sluift/SluiftComponent.h
+++ b/Sluift/SluiftComponent.h
@@ -63,7 +63,7 @@ namespace Swift {
63 return component; 63 return component;
64 } 64 }
65 65
66 void connect(const std::string& host, int port); 66 void connect(const std::string& host, unsigned short port);
67 void waitConnected(int timeout); 67 void waitConnected(int timeout);
68 bool isConnected() const; 68 bool isConnected() const;
69 void setTraceEnabled(bool b); 69 void setTraceEnabled(bool b);
diff --git a/Sluift/component.cpp b/Sluift/component.cpp
index f3c2e37..c1b1da4 100644
--- a/Sluift/component.cpp
+++ b/Sluift/component.cpp
@@ -96,13 +96,13 @@ SLUIFT_LUA_FUNCTION(Component, async_connect) {
96 SluiftComponent* component = getComponent(L); 96 SluiftComponent* component = getComponent(L);
97 97
98 std::string host; 98 std::string host;
99 int port = 0; 99 unsigned short port = 0;
100 if (lua_istable(L, 2)) { 100 if (lua_istable(L, 2)) {
101 if (boost::optional<std::string> hostString = Lua::getStringField(L, 2, "host")) { 101 if (boost::optional<std::string> hostString = Lua::getStringField(L, 2, "host")) {
102 host = *hostString; 102 host = *hostString;
103 } 103 }
104 if (boost::optional<int> portInt = Lua::getIntField(L, 2, "port")) { 104 if (boost::optional<int> portInt = Lua::getIntField(L, 2, "port")) {
105 port = *portInt; 105 port = boost::numeric_cast<unsigned short>(*portInt);
106 } 106 }
107 } 107 }
108 component->connect(host, port); 108 component->connect(host, port);
diff --git a/Swiften/Base/URL.cpp b/Swiften/Base/URL.cpp
index 3bc97ba..5c0f0d7 100644
--- a/Swiften/Base/URL.cpp
+++ b/Swiften/Base/URL.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 */
@@ -11,7 +11,7 @@
11 11
12namespace Swift { 12namespace Swift {
13 13
14int URL::getPortOrDefaultPort(const URL& url) { 14unsigned short URL::getPortOrDefaultPort(const URL& url) {
15 if (url.getPort()) { 15 if (url.getPort()) {
16 return *url.getPort(); 16 return *url.getPort();
17 } 17 }
@@ -62,7 +62,7 @@ URL URL::fromString(const std::string& urlString) {
62 } 62 }
63 63
64 std::string host; 64 std::string host;
65 boost::optional<int> port; 65 boost::optional<unsigned short> port;
66 if (hostAndPort[0] == '[') { 66 if (hostAndPort[0] == '[') {
67 // handle IPv6 address literals 67 // handle IPv6 address literals
68 size_t addressEndIndex = hostAndPort.find(']'); 68 size_t addressEndIndex = hostAndPort.find(']');
@@ -71,9 +71,9 @@ URL URL::fromString(const std::string& urlString) {
71 colonIndex = hostAndPort.find(':', addressEndIndex); 71 colonIndex = hostAndPort.find(':', addressEndIndex);
72 if (colonIndex != std::string::npos) { 72 if (colonIndex != std::string::npos) {
73 try { 73 try {
74 port = boost::lexical_cast<int>(hostAndPort.substr(colonIndex + 1)); 74 port = boost::numeric_cast<unsigned short>(boost::lexical_cast<int>(hostAndPort.substr(colonIndex + 1)));
75 } 75 }
76 catch (const boost::bad_lexical_cast&) { 76 catch (...) {
77 return URL(); 77 return URL();
78 } 78 }
79 } 79 }
@@ -87,7 +87,7 @@ URL URL::fromString(const std::string& urlString) {
87 if (colonIndex != std::string::npos) { 87 if (colonIndex != std::string::npos) {
88 host = unescape(hostAndPort.substr(0, colonIndex)); 88 host = unescape(hostAndPort.substr(0, colonIndex));
89 try { 89 try {
90 port = boost::lexical_cast<int>(hostAndPort.substr(colonIndex + 1)); 90 port = boost::numeric_cast<unsigned short>(boost::lexical_cast<int>(hostAndPort.substr(colonIndex + 1)));
91 } 91 }
92 catch (const boost::bad_lexical_cast&) { 92 catch (const boost::bad_lexical_cast&) {
93 return URL(); 93 return URL();
diff --git a/Swiften/Base/URL.h b/Swiften/Base/URL.h
index 1a03efe..8fdb018 100644
--- a/Swiften/Base/URL.h
+++ b/Swiften/Base/URL.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2011-2016 Isode Limited. 2 * Copyright (c) 2011-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 */
@@ -21,7 +21,7 @@ class SWIFTEN_API URL {
21 URL() : scheme(""), user(""), password(""), host(""), path(""), empty(true) { 21 URL() : scheme(""), user(""), password(""), host(""), path(""), empty(true) {
22 } 22 }
23 23
24 URL(const std::string& scheme, const std::string& host, int port, const std::string& path) : scheme(scheme), user(), password(), host(host), port(port), path(path), empty(false) { 24 URL(const std::string& scheme, const std::string& host, unsigned short port, const std::string& path) : scheme(scheme), user(), password(), host(host), port(port), path(path), empty(false) {
25 } 25 }
26 26
27 URL(const std::string& scheme, const std::string& host, const std::string& path) : scheme(scheme), user(), password(), host(host), path(path), empty(false) { 27 URL(const std::string& scheme, const std::string& host, const std::string& path) : scheme(scheme), user(), password(), host(host), path(path), empty(false) {
@@ -51,7 +51,7 @@ class SWIFTEN_API URL {
51 /** 51 /**
52 * Port number 52 * Port number
53 */ 53 */
54 boost::optional<int> getPort() const { 54 boost::optional<unsigned short> getPort() const {
55 return port; 55 return port;
56 } 56 }
57 57
@@ -64,7 +64,7 @@ class SWIFTEN_API URL {
64 64
65 std::string toString() const; 65 std::string toString() const;
66 66
67 static int getPortOrDefaultPort(const URL& url); 67 static unsigned short getPortOrDefaultPort(const URL& url);
68 static URL fromString(const std::string&); 68 static URL fromString(const std::string&);
69 static std::string unescape(const std::string&); 69 static std::string unescape(const std::string&);
70 70
@@ -74,7 +74,7 @@ class SWIFTEN_API URL {
74 std::string user; 74 std::string user;
75 std::string password; 75 std::string password;
76 std::string host; 76 std::string host;
77 boost::optional<int> port; 77 boost::optional<unsigned short> port;
78 std::string path; 78 std::string path;
79 bool empty; 79 bool empty;
80 }; 80 };
diff --git a/Swiften/Base/UnitTest/URLTest.cpp b/Swiften/Base/UnitTest/URLTest.cpp
index c38398a..da9f15c 100644
--- a/Swiften/Base/UnitTest/URLTest.cpp
+++ b/Swiften/Base/UnitTest/URLTest.cpp
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2012-2016 Isode Limited. 2 * Copyright (c) 2012-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 */
@@ -66,7 +66,7 @@ class URLTest : public CppUnit::TestFixture {
66 66
67 CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme()); 67 CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme());
68 CPPUNIT_ASSERT_EQUAL(std::string("foo.bar"), url.getHost()); 68 CPPUNIT_ASSERT_EQUAL(std::string("foo.bar"), url.getHost());
69 CPPUNIT_ASSERT_EQUAL(1234, *url.getPort()); 69 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(1234), *url.getPort());
70 CPPUNIT_ASSERT_EQUAL(std::string("/baz/bam"), url.getPath()); 70 CPPUNIT_ASSERT_EQUAL(std::string("/baz/bam"), url.getPath());
71 } 71 }
72 72
@@ -75,7 +75,7 @@ class URLTest : public CppUnit::TestFixture {
75 75
76 CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme()); 76 CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme());
77 CPPUNIT_ASSERT_EQUAL(std::string("foo.bar"), url.getHost()); 77 CPPUNIT_ASSERT_EQUAL(std::string("foo.bar"), url.getHost());
78 CPPUNIT_ASSERT_EQUAL(11440, *url.getPort()); 78 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(11440), *url.getPort());
79 CPPUNIT_ASSERT_EQUAL(std::string("/http-bind/"), url.getPath()); 79 CPPUNIT_ASSERT_EQUAL(std::string("/http-bind/"), url.getPath());
80 } 80 }
81 81
@@ -84,7 +84,7 @@ class URLTest : public CppUnit::TestFixture {
84 84
85 CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme()); 85 CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme());
86 CPPUNIT_ASSERT_EQUAL(std::string("foo.bar"), url.getHost()); 86 CPPUNIT_ASSERT_EQUAL(std::string("foo.bar"), url.getHost());
87 CPPUNIT_ASSERT_EQUAL(1234, *url.getPort()); 87 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(1234), *url.getPort());
88 CPPUNIT_ASSERT_EQUAL(std::string(""), url.getPath()); 88 CPPUNIT_ASSERT_EQUAL(std::string(""), url.getPath());
89 } 89 }
90 90
@@ -121,7 +121,7 @@ class URLTest : public CppUnit::TestFixture {
121 121
122 CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme()); 122 CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme());
123 CPPUNIT_ASSERT_EQUAL(std::string("127.0.0.1"), url.getHost()); 123 CPPUNIT_ASSERT_EQUAL(std::string("127.0.0.1"), url.getHost());
124 CPPUNIT_ASSERT_EQUAL(12345, url.getPort().get_value_or(0)); 124 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(12345), url.getPort().get_value_or(0));
125 CPPUNIT_ASSERT_EQUAL(std::string("/foobar"), url.getPath()); 125 CPPUNIT_ASSERT_EQUAL(std::string("/foobar"), url.getPath());
126 } 126 }
127 127
@@ -137,7 +137,7 @@ class URLTest : public CppUnit::TestFixture {
137 137
138 CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme()); 138 CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme());
139 CPPUNIT_ASSERT_EQUAL(std::string("fdf8:f53b:82e4::53"), url.getHost()); 139 CPPUNIT_ASSERT_EQUAL(std::string("fdf8:f53b:82e4::53"), url.getHost());
140 CPPUNIT_ASSERT_EQUAL(12435, url.getPort().get_value_or(0)); 140 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(12435), url.getPort().get_value_or(0));
141 } 141 }
142 142
143 void test_FromString_ToString_IPv6RFC2732() { 143 void test_FromString_ToString_IPv6RFC2732() {
@@ -147,7 +147,7 @@ class URLTest : public CppUnit::TestFixture {
147 147
148 CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme()); 148 CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme());
149 CPPUNIT_ASSERT_EQUAL(std::string("FEDC:BA98:7654:3210:FEDC:BA98:7654:3210"), url.getHost()); 149 CPPUNIT_ASSERT_EQUAL(std::string("FEDC:BA98:7654:3210:FEDC:BA98:7654:3210"), url.getHost());
150 CPPUNIT_ASSERT_EQUAL(80, url.getPort().get_value_or(2)); 150 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(80), url.getPort().get_value_or(2));
151 CPPUNIT_ASSERT_EQUAL(std::string("/index.html"), url.getPath()); 151 CPPUNIT_ASSERT_EQUAL(std::string("/index.html"), url.getPath());
152 152
153 CPPUNIT_ASSERT_EQUAL(std::string(testVector), url.toString()); 153 CPPUNIT_ASSERT_EQUAL(std::string(testVector), url.toString());
@@ -159,7 +159,7 @@ class URLTest : public CppUnit::TestFixture {
159 159
160 CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme()); 160 CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme());
161 CPPUNIT_ASSERT_EQUAL(std::string("1080:0:0:0:8:800:200C:417A"), url.getHost()); 161 CPPUNIT_ASSERT_EQUAL(std::string("1080:0:0:0:8:800:200C:417A"), url.getHost());
162 CPPUNIT_ASSERT_EQUAL(2, url.getPort().get_value_or(2)); 162 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(2), url.getPort().get_value_or(2));
163 CPPUNIT_ASSERT_EQUAL(std::string("/index.html"), url.getPath()); 163 CPPUNIT_ASSERT_EQUAL(std::string("/index.html"), url.getPath());
164 164
165 CPPUNIT_ASSERT_EQUAL(std::string(testVector), url.toString()); 165 CPPUNIT_ASSERT_EQUAL(std::string(testVector), url.toString());
@@ -171,7 +171,7 @@ class URLTest : public CppUnit::TestFixture {
171 171
172 CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme()); 172 CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme());
173 CPPUNIT_ASSERT_EQUAL(std::string("3ffe:2a00:100:7031::1"), url.getHost()); 173 CPPUNIT_ASSERT_EQUAL(std::string("3ffe:2a00:100:7031::1"), url.getHost());
174 CPPUNIT_ASSERT_EQUAL(2, url.getPort().get_value_or(2)); 174 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(2), url.getPort().get_value_or(2));
175 CPPUNIT_ASSERT_EQUAL(std::string(""), url.getPath()); 175 CPPUNIT_ASSERT_EQUAL(std::string(""), url.getPath());
176 176
177 CPPUNIT_ASSERT_EQUAL(std::string(testVector), url.toString()); 177 CPPUNIT_ASSERT_EQUAL(std::string(testVector), url.toString());
@@ -183,7 +183,7 @@ class URLTest : public CppUnit::TestFixture {
183 183
184 CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme()); 184 CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme());
185 CPPUNIT_ASSERT_EQUAL(std::string("1080::8:800:200C:417A"), url.getHost()); 185 CPPUNIT_ASSERT_EQUAL(std::string("1080::8:800:200C:417A"), url.getHost());
186 CPPUNIT_ASSERT_EQUAL(2, url.getPort().get_value_or(2)); 186 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(2), url.getPort().get_value_or(2));
187 CPPUNIT_ASSERT_EQUAL(std::string("/foo"), url.getPath()); 187 CPPUNIT_ASSERT_EQUAL(std::string("/foo"), url.getPath());
188 188
189 CPPUNIT_ASSERT_EQUAL(std::string(testVector), url.toString()); 189 CPPUNIT_ASSERT_EQUAL(std::string(testVector), url.toString());
@@ -195,7 +195,7 @@ class URLTest : public CppUnit::TestFixture {
195 195
196 CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme()); 196 CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme());
197 CPPUNIT_ASSERT_EQUAL(std::string("::192.9.5.5"), url.getHost()); 197 CPPUNIT_ASSERT_EQUAL(std::string("::192.9.5.5"), url.getHost());
198 CPPUNIT_ASSERT_EQUAL(2, url.getPort().get_value_or(2)); 198 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(2), url.getPort().get_value_or(2));
199 CPPUNIT_ASSERT_EQUAL(std::string("/ipng"), url.getPath()); 199 CPPUNIT_ASSERT_EQUAL(std::string("/ipng"), url.getPath());
200 200
201 CPPUNIT_ASSERT_EQUAL(std::string(testVector), url.toString()); 201 CPPUNIT_ASSERT_EQUAL(std::string(testVector), url.toString());
@@ -207,7 +207,7 @@ class URLTest : public CppUnit::TestFixture {
207 207
208 CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme()); 208 CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme());
209 CPPUNIT_ASSERT_EQUAL(std::string("::FFFF:129.144.52.38"), url.getHost()); 209 CPPUNIT_ASSERT_EQUAL(std::string("::FFFF:129.144.52.38"), url.getHost());
210 CPPUNIT_ASSERT_EQUAL(80, url.getPort().get_value_or(2)); 210 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(80), url.getPort().get_value_or(2));
211 CPPUNIT_ASSERT_EQUAL(std::string("/index.html"), url.getPath()); 211 CPPUNIT_ASSERT_EQUAL(std::string("/index.html"), url.getPath());
212 212
213 CPPUNIT_ASSERT_EQUAL(std::string(testVector), url.toString()); 213 CPPUNIT_ASSERT_EQUAL(std::string(testVector), url.toString());
@@ -219,7 +219,7 @@ class URLTest : public CppUnit::TestFixture {
219 219
220 CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme()); 220 CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme());
221 CPPUNIT_ASSERT_EQUAL(std::string("2010:836B:4179::836B:4179"), url.getHost()); 221 CPPUNIT_ASSERT_EQUAL(std::string("2010:836B:4179::836B:4179"), url.getHost());
222 CPPUNIT_ASSERT_EQUAL(2, url.getPort().get_value_or(2)); 222 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(2), url.getPort().get_value_or(2));
223 CPPUNIT_ASSERT_EQUAL(std::string(), url.getPath()); 223 CPPUNIT_ASSERT_EQUAL(std::string(), url.getPath());
224 224
225 CPPUNIT_ASSERT_EQUAL(std::string(testVector), url.toString()); 225 CPPUNIT_ASSERT_EQUAL(std::string(testVector), url.toString());
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.";
diff --git a/Swiften/Component/ComponentConnector.cpp b/Swiften/Component/ComponentConnector.cpp
index a7375a7..7789c4c 100644
--- a/Swiften/Component/ComponentConnector.cpp
+++ b/Swiften/Component/ComponentConnector.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 */
@@ -15,7 +15,7 @@
15 15
16namespace Swift { 16namespace Swift {
17 17
18ComponentConnector::ComponentConnector(const std::string& hostname, int port, DomainNameResolver* resolver, ConnectionFactory* connectionFactory, TimerFactory* timerFactory) : hostname(hostname), port(port), resolver(resolver), connectionFactory(connectionFactory), timerFactory(timerFactory), timeoutMilliseconds(0) { 18ComponentConnector::ComponentConnector(const std::string& hostname, unsigned short port, DomainNameResolver* resolver, ConnectionFactory* connectionFactory, TimerFactory* timerFactory) : hostname(hostname), port(port), resolver(resolver), connectionFactory(connectionFactory), timerFactory(timerFactory), timeoutMilliseconds(0) {
19} 19}
20 20
21void ComponentConnector::setTimeoutMilliseconds(int milliseconds) { 21void ComponentConnector::setTimeoutMilliseconds(int milliseconds) {
diff --git a/Swiften/Component/ComponentConnector.h b/Swiften/Component/ComponentConnector.h
index ab36901..cfd49fe 100644
--- a/Swiften/Component/ComponentConnector.h
+++ b/Swiften/Component/ComponentConnector.h
@@ -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 */
@@ -28,7 +28,7 @@ namespace Swift {
28 public: 28 public:
29 typedef std::shared_ptr<ComponentConnector> ref; 29 typedef std::shared_ptr<ComponentConnector> ref;
30 30
31 static ComponentConnector::ref create(const std::string& hostname, int port, DomainNameResolver* resolver, ConnectionFactory* connectionFactory, TimerFactory* timerFactory) { 31 static ComponentConnector::ref create(const std::string& hostname, unsigned short port, DomainNameResolver* resolver, ConnectionFactory* connectionFactory, TimerFactory* timerFactory) {
32 return ref(new ComponentConnector(hostname, port, resolver, connectionFactory, timerFactory)); 32 return ref(new ComponentConnector(hostname, port, resolver, connectionFactory, timerFactory));
33 } 33 }
34 34
@@ -40,7 +40,7 @@ namespace Swift {
40 boost::signals2::signal<void (std::shared_ptr<Connection>)> onConnectFinished; 40 boost::signals2::signal<void (std::shared_ptr<Connection>)> onConnectFinished;
41 41
42 private: 42 private:
43 ComponentConnector(const std::string& hostname, int port, DomainNameResolver*, ConnectionFactory*, TimerFactory*); 43 ComponentConnector(const std::string& hostname, unsigned short port, DomainNameResolver*, ConnectionFactory*, TimerFactory*);
44 44
45 void handleAddressQueryResult(const std::vector<HostAddress>& address, boost::optional<DomainNameResolveError> error); 45 void handleAddressQueryResult(const std::vector<HostAddress>& address, boost::optional<DomainNameResolveError> error);
46 void tryNextAddress(); 46 void tryNextAddress();
@@ -53,7 +53,7 @@ namespace Swift {
53 53
54 private: 54 private:
55 std::string hostname; 55 std::string hostname;
56 int port; 56 unsigned short port;
57 DomainNameResolver* resolver; 57 DomainNameResolver* resolver;
58 ConnectionFactory* connectionFactory; 58 ConnectionFactory* connectionFactory;
59 TimerFactory* timerFactory; 59 TimerFactory* timerFactory;
diff --git a/Swiften/Component/CoreComponent.cpp b/Swiften/Component/CoreComponent.cpp
index 5b2277b..2d91c9c 100644
--- a/Swiften/Component/CoreComponent.cpp
+++ b/Swiften/Component/CoreComponent.cpp
@@ -43,7 +43,7 @@ CoreComponent::~CoreComponent() {
43 delete stanzaChannel_; 43 delete stanzaChannel_;
44} 44}
45 45
46void CoreComponent::connect(const std::string& host, int port) { 46void CoreComponent::connect(const std::string& host, unsigned short port) {
47 assert(!connector_); 47 assert(!connector_);
48 connector_ = ComponentConnector::create(host, port, networkFactories->getDomainNameResolver(), networkFactories->getConnectionFactory(), networkFactories->getTimerFactory()); 48 connector_ = ComponentConnector::create(host, port, networkFactories->getDomainNameResolver(), networkFactories->getConnectionFactory(), networkFactories->getTimerFactory());
49 connector_->onConnectFinished.connect(boost::bind(&CoreComponent::handleConnectorFinished, this, _1)); 49 connector_->onConnectFinished.connect(boost::bind(&CoreComponent::handleConnectorFinished, this, _1));
diff --git a/Swiften/Component/CoreComponent.h b/Swiften/Component/CoreComponent.h
index 1a487d2..7565d00 100644
--- a/Swiften/Component/CoreComponent.h
+++ b/Swiften/Component/CoreComponent.h
@@ -46,7 +46,7 @@ namespace Swift {
46 CoreComponent(const JID& jid, const std::string& secret, NetworkFactories* networkFactories); 46 CoreComponent(const JID& jid, const std::string& secret, NetworkFactories* networkFactories);
47 virtual ~CoreComponent(); 47 virtual ~CoreComponent();
48 48
49 void connect(const std::string& host, int port); 49 void connect(const std::string& host, unsigned short port);
50 void disconnect(); 50 void disconnect();
51 51
52 void sendMessage(std::shared_ptr<Message>); 52 void sendMessage(std::shared_ptr<Message>);
diff --git a/Swiften/Component/UnitTest/ComponentConnectorTest.cpp b/Swiften/Component/UnitTest/ComponentConnectorTest.cpp
index 3b4fa83..bd26989 100644
--- a/Swiften/Component/UnitTest/ComponentConnectorTest.cpp
+++ b/Swiften/Component/UnitTest/ComponentConnectorTest.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 */
@@ -146,7 +146,7 @@ class ComponentConnectorTest : public CppUnit::TestFixture {
146 } 146 }
147 147
148 private: 148 private:
149 ComponentConnector::ref createConnector(const std::string& hostname, int port) { 149 ComponentConnector::ref createConnector(const std::string& hostname, unsigned short port) {
150 ComponentConnector::ref connector = ComponentConnector::create(hostname, port, resolver, connectionFactory, timerFactory); 150 ComponentConnector::ref connector = ComponentConnector::create(hostname, port, resolver, connectionFactory, timerFactory);
151 connector->onConnectFinished.connect(boost::bind(&ComponentConnectorTest::handleConnectorFinished, this, _1)); 151 connector->onConnectFinished.connect(boost::bind(&ComponentConnectorTest::handleConnectorFinished, this, _1));
152 return connector; 152 return connector;
diff --git a/Swiften/Elements/Bytestreams.h b/Swiften/Elements/Bytestreams.h
index ca30922..599ed46 100644
--- a/Swiften/Elements/Bytestreams.h
+++ b/Swiften/Elements/Bytestreams.h
@@ -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 */
@@ -22,11 +22,11 @@ namespace Swift {
22 typedef std::shared_ptr<Bytestreams> ref; 22 typedef std::shared_ptr<Bytestreams> ref;
23 23
24 struct StreamHost { 24 struct StreamHost {
25 StreamHost(const std::string& host = "", const JID& jid = JID(), int port = -1) : host(host), jid(jid), port(port) {} 25 StreamHost(const std::string& host = "", const JID& jid = JID(), unsigned short port = 0) : host(host), jid(jid), port(port) {}
26 26
27 std::string host; 27 std::string host;
28 JID jid; 28 JID jid;
29 int port; 29 unsigned short port;
30 }; 30 };
31 31
32 Bytestreams() {} 32 Bytestreams() {}
diff --git a/Swiften/Elements/S5BProxyRequest.h b/Swiften/Elements/S5BProxyRequest.h
index e3f5206..2fecae4 100644
--- a/Swiften/Elements/S5BProxyRequest.h
+++ b/Swiften/Elements/S5BProxyRequest.h
@@ -5,7 +5,7 @@
5 */ 5 */
6 6
7/* 7/*
8 * Copyright (c) 2015-2016 Isode Limited. 8 * Copyright (c) 2015-2018 Isode Limited.
9 * All rights reserved. 9 * All rights reserved.
10 * See the COPYING file for more information. 10 * See the COPYING file for more information.
11 */ 11 */
@@ -30,7 +30,7 @@ public:
30public: 30public:
31 struct StreamHost { 31 struct StreamHost {
32 std::string host; 32 std::string host;
33 int port; 33 unsigned short port;
34 JID jid; 34 JID jid;
35 }; 35 };
36 36
diff --git a/Swiften/FileTransfer/SOCKS5BytestreamServerManager.cpp b/Swiften/FileTransfer/SOCKS5BytestreamServerManager.cpp
index f749735..a6b75da 100644
--- a/Swiften/FileTransfer/SOCKS5BytestreamServerManager.cpp
+++ b/Swiften/FileTransfer/SOCKS5BytestreamServerManager.cpp
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2012-2016 Isode Limited. 2 * Copyright (c) 2012-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 */
@@ -114,7 +114,7 @@ void SOCKS5BytestreamServerManager::initialize() {
114 114
115 // Find a port to listen on 115 // Find a port to listen on
116 assert(!connectionServer); 116 assert(!connectionServer);
117 int port; 117 unsigned short port;
118 for (port = LISTEN_PORTS_BEGIN; port < LISTEN_PORTS_END; ++port) { 118 for (port = LISTEN_PORTS_BEGIN; port < LISTEN_PORTS_END; ++port) {
119 SWIFT_LOG(debug) << "Trying to start server on port " << port << std::endl; 119 SWIFT_LOG(debug) << "Trying to start server on port " << port << std::endl;
120 connectionServer = connectionServerFactory->createConnectionServer(HostAddress::fromString("::").get(), port); 120 connectionServer = connectionServerFactory->createConnectionServer(HostAddress::fromString("::").get(), port);
@@ -164,7 +164,7 @@ void SOCKS5BytestreamServerManager::setupPortForwarding() {
164 } 164 }
165 165
166 // Forward ports 166 // Forward ports
167 int port = server->getAddressPort().getPort(); 167 auto port = server->getAddressPort().getPort();
168 assert(!forwardPortRequest); 168 assert(!forwardPortRequest);
169 portMapping = boost::optional<NATPortMapping>(); 169 portMapping = boost::optional<NATPortMapping>();
170 if ((forwardPortRequest = natTraverser->createForwardPortRequest(port, port))) { 170 if ((forwardPortRequest = natTraverser->createForwardPortRequest(port, port))) {
diff --git a/Swiften/FileTransfer/SOCKS5BytestreamServerManager.h b/Swiften/FileTransfer/SOCKS5BytestreamServerManager.h
index 3c06513..74578cc 100644
--- a/Swiften/FileTransfer/SOCKS5BytestreamServerManager.h
+++ b/Swiften/FileTransfer/SOCKS5BytestreamServerManager.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2012-2016 Isode Limited. 2 * Copyright (c) 2012-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 */
@@ -78,7 +78,7 @@ namespace Swift {
78 enum { Start, Initializing, Initialized } state; 78 enum { Start, Initializing, Initialized } state;
79 SOCKS5BytestreamServer* server; 79 SOCKS5BytestreamServer* server;
80 std::shared_ptr<ConnectionServer> connectionServer; 80 std::shared_ptr<ConnectionServer> connectionServer;
81 int connectionServerPort = -1; 81 unsigned short connectionServerPort = 0;
82 82
83 std::shared_ptr<NATTraversalGetPublicIPRequest> getPublicIPRequest; 83 std::shared_ptr<NATTraversalGetPublicIPRequest> getPublicIPRequest;
84 std::shared_ptr<NATTraversalForwardPortRequest> forwardPortRequest; 84 std::shared_ptr<NATTraversalForwardPortRequest> forwardPortRequest;
diff --git a/Swiften/LinkLocal/DNSSD/Avahi/AvahiQuerier.cpp b/Swiften/LinkLocal/DNSSD/Avahi/AvahiQuerier.cpp
index 1b79946..66b4ae8 100644
--- a/Swiften/LinkLocal/DNSSD/Avahi/AvahiQuerier.cpp
+++ b/Swiften/LinkLocal/DNSSD/Avahi/AvahiQuerier.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 */
@@ -25,7 +25,7 @@ std::shared_ptr<DNSSDBrowseQuery> AvahiQuerier::createBrowseQuery() {
25 return std::make_shared<AvahiBrowseQuery>(shared_from_this(), eventLoop); 25 return std::make_shared<AvahiBrowseQuery>(shared_from_this(), eventLoop);
26} 26}
27 27
28std::shared_ptr<DNSSDRegisterQuery> AvahiQuerier::createRegisterQuery(const std::string& name, int port, const ByteArray& info) { 28std::shared_ptr<DNSSDRegisterQuery> AvahiQuerier::createRegisterQuery(const std::string& name, unsigned short port, const ByteArray& info) {
29 return std::make_shared<AvahiRegisterQuery>(name, port, info, shared_from_this(), eventLoop); 29 return std::make_shared<AvahiRegisterQuery>(name, port, info, shared_from_this(), eventLoop);
30} 30}
31 31
diff --git a/Swiften/LinkLocal/DNSSD/Avahi/AvahiQuerier.h b/Swiften/LinkLocal/DNSSD/Avahi/AvahiQuerier.h
index 5dce19d..73dd11d 100644
--- a/Swiften/LinkLocal/DNSSD/Avahi/AvahiQuerier.h
+++ b/Swiften/LinkLocal/DNSSD/Avahi/AvahiQuerier.h
@@ -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 */
@@ -30,7 +30,7 @@ namespace Swift {
30 30
31 std::shared_ptr<DNSSDBrowseQuery> createBrowseQuery(); 31 std::shared_ptr<DNSSDBrowseQuery> createBrowseQuery();
32 std::shared_ptr<DNSSDRegisterQuery> createRegisterQuery( 32 std::shared_ptr<DNSSDRegisterQuery> createRegisterQuery(
33 const std::string& name, int port, const ByteArray& info); 33 const std::string& name, unsigned short port, const ByteArray& info);
34 std::shared_ptr<DNSSDResolveServiceQuery> createResolveServiceQuery( 34 std::shared_ptr<DNSSDResolveServiceQuery> createResolveServiceQuery(
35 const DNSSDServiceID&); 35 const DNSSDServiceID&);
36 std::shared_ptr<DNSSDResolveHostnameQuery> createResolveHostnameQuery( 36 std::shared_ptr<DNSSDResolveHostnameQuery> createResolveHostnameQuery(
diff --git a/Swiften/LinkLocal/DNSSD/Avahi/AvahiRegisterQuery.h b/Swiften/LinkLocal/DNSSD/Avahi/AvahiRegisterQuery.h
index 68281d0..b780043 100644
--- a/Swiften/LinkLocal/DNSSD/Avahi/AvahiRegisterQuery.h
+++ b/Swiften/LinkLocal/DNSSD/Avahi/AvahiRegisterQuery.h
@@ -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 */
@@ -18,7 +18,7 @@ namespace Swift {
18 18
19 class AvahiRegisterQuery : public DNSSDRegisterQuery, public AvahiQuery { 19 class AvahiRegisterQuery : public DNSSDRegisterQuery, public AvahiQuery {
20 public: 20 public:
21 AvahiRegisterQuery(const std::string& name, int port, const ByteArray& txtRecord, std::shared_ptr<AvahiQuerier> querier, EventLoop* eventLoop) : AvahiQuery(querier, eventLoop), name(name), port(port), txtRecord(txtRecord), group(0) { 21 AvahiRegisterQuery(const std::string& name, unsigned short port, const ByteArray& txtRecord, std::shared_ptr<AvahiQuerier> querier, EventLoop* eventLoop) : AvahiQuery(querier, eventLoop), name(name), port(port), txtRecord(txtRecord), group(0) {
22 } 22 }
23 23
24 void registerService(); 24 void registerService();
@@ -50,7 +50,7 @@ namespace Swift {
50 50
51 private: 51 private:
52 std::string name; 52 std::string name;
53 int port; 53 unsigned short port;
54 ByteArray txtRecord; 54 ByteArray txtRecord;
55 AvahiEntryGroup* group; 55 AvahiEntryGroup* group;
56 }; 56 };
diff --git a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.cpp b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.cpp
index 0906ffc..551421e 100644
--- a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.cpp
+++ b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.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 */
@@ -11,6 +11,7 @@
11#include <unistd.h> 11#include <unistd.h>
12 12
13#include <Swiften/Base/Algorithm.h> 13#include <Swiften/Base/Algorithm.h>
14#include <Swiften/Base/Log.h>
14#include <Swiften/LinkLocal/DNSSD/Bonjour/BonjourBrowseQuery.h> 15#include <Swiften/LinkLocal/DNSSD/Bonjour/BonjourBrowseQuery.h>
15#include <Swiften/LinkLocal/DNSSD/Bonjour/BonjourRegisterQuery.h> 16#include <Swiften/LinkLocal/DNSSD/Bonjour/BonjourRegisterQuery.h>
16#include <Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveHostnameQuery.h> 17#include <Swiften/LinkLocal/DNSSD/Bonjour/BonjourResolveHostnameQuery.h>
@@ -36,7 +37,7 @@ std::shared_ptr<DNSSDBrowseQuery> BonjourQuerier::createBrowseQuery() {
36 return std::make_shared<BonjourBrowseQuery>(shared_from_this(), eventLoop); 37 return std::make_shared<BonjourBrowseQuery>(shared_from_this(), eventLoop);
37} 38}
38 39
39std::shared_ptr<DNSSDRegisterQuery> BonjourQuerier::createRegisterQuery(const std::string& name, int port, const ByteArray& info) { 40std::shared_ptr<DNSSDRegisterQuery> BonjourQuerier::createRegisterQuery(const std::string& name, unsigned short port, const ByteArray& info) {
40 return std::make_shared<BonjourRegisterQuery>(name, port, info, shared_from_this(), eventLoop); 41 return std::make_shared<BonjourRegisterQuery>(name, port, info, shared_from_this(), eventLoop);
41} 42}
42 43
diff --git a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.h b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.h
index 77326bc..6af1c1f 100644
--- a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.h
+++ b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.h
@@ -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 */
@@ -25,7 +25,7 @@ namespace Swift {
25 25
26 std::shared_ptr<DNSSDBrowseQuery> createBrowseQuery(); 26 std::shared_ptr<DNSSDBrowseQuery> createBrowseQuery();
27 std::shared_ptr<DNSSDRegisterQuery> createRegisterQuery( 27 std::shared_ptr<DNSSDRegisterQuery> createRegisterQuery(
28 const std::string& name, int port, const ByteArray& info); 28 const std::string& name, unsigned short port, const ByteArray& info);
29 std::shared_ptr<DNSSDResolveServiceQuery> createResolveServiceQuery( 29 std::shared_ptr<DNSSDResolveServiceQuery> createResolveServiceQuery(
30 const DNSSDServiceID&); 30 const DNSSDServiceID&);
31 std::shared_ptr<DNSSDResolveHostnameQuery> createResolveHostnameQuery( 31 std::shared_ptr<DNSSDResolveHostnameQuery> createResolveHostnameQuery(
diff --git a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourRegisterQuery.h b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourRegisterQuery.h
index 8b2e955..9eb8cd9 100644
--- a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourRegisterQuery.h
+++ b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourRegisterQuery.h
@@ -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 */
@@ -20,12 +20,21 @@ namespace Swift {
20 20
21 class BonjourRegisterQuery : public DNSSDRegisterQuery, public BonjourQuery { 21 class BonjourRegisterQuery : public DNSSDRegisterQuery, public BonjourQuery {
22 public: 22 public:
23 BonjourRegisterQuery(const std::string& name, int port, const ByteArray& txtRecord, std::shared_ptr<BonjourQuerier> querier, EventLoop* eventLoop) : BonjourQuery(querier, eventLoop) { 23 BonjourRegisterQuery(const std::string& name, unsigned short port, const ByteArray& txtRecord, std::shared_ptr<BonjourQuerier> querier, EventLoop* eventLoop) : BonjourQuery(querier, eventLoop) {
24 unsigned short recordSize = 0;
25 try {
26 recordSize = boost::numeric_cast<unsigned short>(txtRecord.size());
27 }
28 catch (const boost::numeric::bad_numeric_cast&) {
29 SWIFT_LOG(warning) << "Bonjour TXT record is too long (" << txtRecord.size() << " bytes), not registring service" << std::endl;
30 return;
31 }
24 DNSServiceErrorType result = DNSServiceRegister( 32 DNSServiceErrorType result = DNSServiceRegister(
25 &sdRef, 0, 0, name.c_str(), "_presence._tcp", nullptr, nullptr, boost::numeric_cast<unsigned short>(port), 33 &sdRef, 0, 0, name.c_str(), "_presence._tcp", nullptr, nullptr, port,
26 boost::numeric_cast<unsigned short>(txtRecord.size()), vecptr(txtRecord), 34 recordSize, vecptr(txtRecord),
27 &BonjourRegisterQuery::handleServiceRegisteredStatic, this); 35 &BonjourRegisterQuery::handleServiceRegisteredStatic, this);
28 if (result != kDNSServiceErr_NoError) { 36 if (result != kDNSServiceErr_NoError) {
37 SWIFT_LOG(warning) << "Failed to register Bonjour service" << std::endl;
29 sdRef = nullptr; 38 sdRef = nullptr;
30 } 39 }
31 } 40 }
@@ -45,7 +54,12 @@ namespace Swift {
45 54
46 void updateServiceInfo(const ByteArray& txtRecord) { 55 void updateServiceInfo(const ByteArray& txtRecord) {
47 std::lock_guard<std::mutex> lock(sdRefMutex); 56 std::lock_guard<std::mutex> lock(sdRefMutex);
48 DNSServiceUpdateRecord(sdRef, nullptr, 0, boost::numeric_cast<unsigned short>(txtRecord.size()), vecptr(txtRecord), 0); 57 try {
58 DNSServiceUpdateRecord(sdRef, nullptr, 0, boost::numeric_cast<unsigned short>(txtRecord.size()), vecptr(txtRecord), 0);
59 }
60 catch (const boost::numeric::bad_numeric_cast&) {
61 SWIFT_LOG(warning) << "Bonjour TXT record is too long (" << txtRecord.size() << " bytes), not updating service record" << std::endl;
62 }
49 } 63 }
50 64
51 private: 65 private:
diff --git a/Swiften/LinkLocal/DNSSD/DNSSDQuerier.h b/Swiften/LinkLocal/DNSSD/DNSSDQuerier.h
index 8f3c3ec..3924c05 100644
--- a/Swiften/LinkLocal/DNSSD/DNSSDQuerier.h
+++ b/Swiften/LinkLocal/DNSSD/DNSSDQuerier.h
@@ -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 */
@@ -26,7 +26,7 @@ namespace Swift {
26 26
27 virtual std::shared_ptr<DNSSDBrowseQuery> createBrowseQuery() = 0; 27 virtual std::shared_ptr<DNSSDBrowseQuery> createBrowseQuery() = 0;
28 virtual std::shared_ptr<DNSSDRegisterQuery> createRegisterQuery( 28 virtual std::shared_ptr<DNSSDRegisterQuery> createRegisterQuery(
29 const std::string& name, int port, const ByteArray& info) = 0; 29 const std::string& name, unsigned short port, const ByteArray& info) = 0;
30 virtual std::shared_ptr<DNSSDResolveServiceQuery> createResolveServiceQuery( 30 virtual std::shared_ptr<DNSSDResolveServiceQuery> createResolveServiceQuery(
31 const DNSSDServiceID&) = 0; 31 const DNSSDServiceID&) = 0;
32 virtual std::shared_ptr<DNSSDResolveHostnameQuery> createResolveHostnameQuery( 32 virtual std::shared_ptr<DNSSDResolveHostnameQuery> createResolveHostnameQuery(
diff --git a/Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.h b/Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.h
index b55447a..6416d69 100644
--- a/Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.h
+++ b/Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.h
@@ -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 */
@@ -16,11 +16,11 @@ namespace Swift {
16 class DNSSDResolveServiceQuery { 16 class DNSSDResolveServiceQuery {
17 public: 17 public:
18 struct Result { 18 struct Result {
19 Result(const std::string& fullName, const std::string& host, int port, const ByteArray& info) : 19 Result(const std::string& fullName, const std::string& host, unsigned short port, const ByteArray& info) :
20 fullName(fullName), host(host), port(port), info(info) {} 20 fullName(fullName), host(host), port(port), info(info) {}
21 std::string fullName; 21 std::string fullName;
22 std::string host; 22 std::string host;
23 int port; 23 unsigned short port;
24 ByteArray info; 24 ByteArray info;
25 }; 25 };
26 26
diff --git a/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.cpp b/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.cpp
index c17f8b2..3381a26 100644
--- a/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.cpp
+++ b/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.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 */
@@ -32,7 +32,7 @@ std::shared_ptr<DNSSDBrowseQuery> FakeDNSSDQuerier::createBrowseQuery() {
32 return std::make_shared<FakeDNSSDBrowseQuery>(shared_from_this()); 32 return std::make_shared<FakeDNSSDBrowseQuery>(shared_from_this());
33} 33}
34 34
35std::shared_ptr<DNSSDRegisterQuery> FakeDNSSDQuerier::createRegisterQuery(const std::string& name, int port, const ByteArray& info) { 35std::shared_ptr<DNSSDRegisterQuery> FakeDNSSDQuerier::createRegisterQuery(const std::string& name, unsigned short port, const ByteArray& info) {
36 return std::make_shared<FakeDNSSDRegisterQuery>(name, port, info, shared_from_this()); 36 return std::make_shared<FakeDNSSDRegisterQuery>(name, port, info, shared_from_this());
37} 37}
38 38
@@ -105,7 +105,7 @@ void FakeDNSSDQuerier::setServiceInfo(const DNSSDServiceID& id, const DNSSDResol
105 } 105 }
106} 106}
107 107
108bool FakeDNSSDQuerier::isServiceRegistered(const std::string& name, int port, const ByteArray& info) { 108bool FakeDNSSDQuerier::isServiceRegistered(const std::string& name, unsigned short port, const ByteArray& info) {
109 for (const auto& query : getQueries<FakeDNSSDRegisterQuery>()) { 109 for (const auto& query : getQueries<FakeDNSSDRegisterQuery>()) {
110 if (query->name == name && query->port == port && query->info == info) { 110 if (query->name == name && query->port == port && query->info == info) {
111 return true; 111 return true;
diff --git a/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.h b/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.h
index 5d4fefd..07cb75c 100644
--- a/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.h
+++ b/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2010-2017 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 */
@@ -39,7 +39,7 @@ namespace Swift {
39 39
40 std::shared_ptr<DNSSDBrowseQuery> createBrowseQuery(); 40 std::shared_ptr<DNSSDBrowseQuery> createBrowseQuery();
41 std::shared_ptr<DNSSDRegisterQuery> createRegisterQuery( 41 std::shared_ptr<DNSSDRegisterQuery> createRegisterQuery(
42 const std::string& name, int port, const ByteArray& info); 42 const std::string& name, unsigned short port, const ByteArray& info);
43 std::shared_ptr<DNSSDResolveServiceQuery> createResolveServiceQuery( 43 std::shared_ptr<DNSSDResolveServiceQuery> createResolveServiceQuery(
44 const DNSSDServiceID&); 44 const DNSSDServiceID&);
45 std::shared_ptr<DNSSDResolveHostnameQuery> createResolveHostnameQuery( 45 std::shared_ptr<DNSSDResolveHostnameQuery> createResolveHostnameQuery(
@@ -51,7 +51,7 @@ namespace Swift {
51 void addService(const DNSSDServiceID& id); 51 void addService(const DNSSDServiceID& id);
52 void removeService(const DNSSDServiceID& id); 52 void removeService(const DNSSDServiceID& id);
53 void setServiceInfo(const DNSSDServiceID& id, const DNSSDResolveServiceQuery::Result& info); 53 void setServiceInfo(const DNSSDServiceID& id, const DNSSDResolveServiceQuery::Result& info);
54 bool isServiceRegistered(const std::string& name, int port, const ByteArray& info); 54 bool isServiceRegistered(const std::string& name, unsigned short port, const ByteArray& info);
55 void setAddress(const std::string& hostname, boost::optional<HostAddress> address); 55 void setAddress(const std::string& hostname, boost::optional<HostAddress> address);
56 56
57 void setBrowseError(); 57 void setBrowseError();
diff --git a/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDRegisterQuery.h b/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDRegisterQuery.h
index 7478841..ee6bb92 100644
--- a/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDRegisterQuery.h
+++ b/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDRegisterQuery.h
@@ -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 */
@@ -17,7 +17,7 @@ namespace Swift {
17 17
18 class FakeDNSSDRegisterQuery : public DNSSDRegisterQuery, public FakeDNSSDQuery { 18 class FakeDNSSDRegisterQuery : public DNSSDRegisterQuery, public FakeDNSSDQuery {
19 public: 19 public:
20 FakeDNSSDRegisterQuery(const std::string& name, int port, const ByteArray& info, std::shared_ptr<FakeDNSSDQuerier> querier) : FakeDNSSDQuery(querier), name(name), port(port), info(info) { 20 FakeDNSSDRegisterQuery(const std::string& name, unsigned short port, const ByteArray& info, std::shared_ptr<FakeDNSSDQuerier> querier) : FakeDNSSDQuery(querier), name(name), port(port), info(info) {
21 } 21 }
22 22
23 void registerService() { 23 void registerService() {
@@ -33,7 +33,7 @@ namespace Swift {
33 } 33 }
34 34
35 std::string name; 35 std::string name;
36 int port; 36 unsigned short port;
37 ByteArray info; 37 ByteArray info;
38 }; 38 };
39} 39}
diff --git a/Swiften/LinkLocal/LinkLocalService.h b/Swiften/LinkLocal/LinkLocalService.h
index 9b0e2ab..c51f890 100644
--- a/Swiften/LinkLocal/LinkLocalService.h
+++ b/Swiften/LinkLocal/LinkLocalService.h
@@ -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 */
@@ -31,7 +31,7 @@ namespace Swift {
31 return id.getName(); 31 return id.getName();
32 } 32 }
33 33
34 int getPort() const { 34 unsigned short getPort() const {
35 return info.port; 35 return info.port;
36 } 36 }
37 37
diff --git a/Swiften/LinkLocal/LinkLocalServiceBrowser.cpp b/Swiften/LinkLocal/LinkLocalServiceBrowser.cpp
index b79f184..b3328cd 100644
--- a/Swiften/LinkLocal/LinkLocalServiceBrowser.cpp
+++ b/Swiften/LinkLocal/LinkLocalServiceBrowser.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 */
@@ -65,7 +65,7 @@ bool LinkLocalServiceBrowser::isRegistered() const {
65 return !!registerQuery; 65 return !!registerQuery;
66} 66}
67 67
68void LinkLocalServiceBrowser::registerService(const std::string& name, int port, const LinkLocalServiceInfo& info) { 68void LinkLocalServiceBrowser::registerService(const std::string& name, unsigned short port, const LinkLocalServiceInfo& info) {
69 assert(!registerQuery); 69 assert(!registerQuery);
70 registerQuery = querier->createRegisterQuery(name, port, info.toTXTRecord()); 70 registerQuery = querier->createRegisterQuery(name, port, info.toTXTRecord());
71 registerQuery->onRegisterFinished.connect( 71 registerQuery->onRegisterFinished.connect(
diff --git a/Swiften/LinkLocal/LinkLocalServiceBrowser.h b/Swiften/LinkLocal/LinkLocalServiceBrowser.h
index c59a4d0..bfcfc07 100644
--- a/Swiften/LinkLocal/LinkLocalServiceBrowser.h
+++ b/Swiften/LinkLocal/LinkLocalServiceBrowser.h
@@ -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 */
@@ -35,7 +35,7 @@ namespace Swift {
35 35
36 void registerService( 36 void registerService(
37 const std::string& name, 37 const std::string& name,
38 int port, 38 unsigned short port,
39 const LinkLocalServiceInfo& info = LinkLocalServiceInfo()); 39 const LinkLocalServiceInfo& info = LinkLocalServiceInfo());
40 void updateService( 40 void updateService(
41 const LinkLocalServiceInfo& info = LinkLocalServiceInfo()); 41 const LinkLocalServiceInfo& info = LinkLocalServiceInfo());
diff --git a/Swiften/LinkLocal/LinkLocalServiceInfo.cpp b/Swiften/LinkLocal/LinkLocalServiceInfo.cpp
index 771251a..102b7f3 100644
--- a/Swiften/LinkLocal/LinkLocalServiceInfo.cpp
+++ b/Swiften/LinkLocal/LinkLocalServiceInfo.cpp
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2010-2013 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 */
@@ -82,7 +82,13 @@ LinkLocalServiceInfo LinkLocalServiceInfo::createFromTXTRecord(const ByteArray&
82 info.setNick(entry.second); 82 info.setNick(entry.second);
83 } 83 }
84 else if (entry.first == "port.p2pj") { 84 else if (entry.first == "port.p2pj") {
85 info.setPort(boost::lexical_cast<int>(entry.second)); 85 try {
86 info.setPort(boost::numeric_cast<unsigned short>(boost::lexical_cast<int>(entry.second)));
87 }
88 catch (const boost::bad_lexical_cast&) {
89 }
90 catch (const boost::numeric::bad_numeric_cast&) {
91 }
86 } 92 }
87 else if (entry.first == "status") { 93 else if (entry.first == "status") {
88 if (entry.second == "away") { 94 if (entry.second == "away") {
diff --git a/Swiften/LinkLocal/LinkLocalServiceInfo.h b/Swiften/LinkLocal/LinkLocalServiceInfo.h
index 9f15c6e..eb65706 100644
--- a/Swiften/LinkLocal/LinkLocalServiceInfo.h
+++ b/Swiften/LinkLocal/LinkLocalServiceInfo.h
@@ -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 */
@@ -43,8 +43,8 @@ namespace Swift {
43 Status getStatus() const { return status; } 43 Status getStatus() const { return status; }
44 void setStatus(Status s) { status = s; } 44 void setStatus(Status s) { status = s; }
45 45
46 boost::optional<int> getPort() const { return port; } 46 boost::optional<unsigned short> getPort() const { return port; }
47 void setPort(int p) { port = p; } 47 void setPort(unsigned short p) { port = p; }
48 48
49 ByteArray toTXTRecord() const; 49 ByteArray toTXTRecord() const;
50 50
@@ -62,6 +62,6 @@ namespace Swift {
62 std::string message; 62 std::string message;
63 std::string nick; 63 std::string nick;
64 Status status; 64 Status status;
65 boost::optional<int> port; 65 boost::optional<unsigned short> port;
66 }; 66 };
67} 67}
diff --git a/Swiften/LinkLocal/UnitTest/LinkLocalConnectorTest.cpp b/Swiften/LinkLocal/UnitTest/LinkLocalConnectorTest.cpp
index 85ae537..ab1ee0c 100644
--- a/Swiften/LinkLocal/UnitTest/LinkLocalConnectorTest.cpp
+++ b/Swiften/LinkLocal/UnitTest/LinkLocalConnectorTest.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 */
@@ -53,7 +53,7 @@ class LinkLocalConnectorTest : public CppUnit::TestFixture {
53 CPPUNIT_ASSERT(!connectError); 53 CPPUNIT_ASSERT(!connectError);
54 CPPUNIT_ASSERT(connection->connectedTo); 54 CPPUNIT_ASSERT(connection->connectedTo);
55 CPPUNIT_ASSERT_EQUAL(std::string(connection->connectedTo->getAddress().toString()), std::string("192.168.1.1")); 55 CPPUNIT_ASSERT_EQUAL(std::string(connection->connectedTo->getAddress().toString()), std::string("192.168.1.1"));
56 CPPUNIT_ASSERT_EQUAL(connection->connectedTo->getPort(), 1234); 56 CPPUNIT_ASSERT_EQUAL(connection->connectedTo->getPort(), static_cast<unsigned short>(1234));
57 } 57 }
58 58
59 void testConnect_UnableToResolve() { 59 void testConnect_UnableToResolve() {
@@ -114,7 +114,7 @@ class LinkLocalConnectorTest : public CppUnit::TestFixture {
114 } 114 }
115 115
116 private: 116 private:
117 std::shared_ptr<LinkLocalConnector> createConnector(const std::string& hostname, int port) { 117 std::shared_ptr<LinkLocalConnector> createConnector(const std::string& hostname, unsigned short port) {
118 LinkLocalService service( 118 LinkLocalService service(
119 DNSSDServiceID("myname", "local."), 119 DNSSDServiceID("myname", "local."),
120 DNSSDResolveServiceQuery::Result( 120 DNSSDResolveServiceQuery::Result(
diff --git a/Swiften/Network/BoostConnectionServer.cpp b/Swiften/Network/BoostConnectionServer.cpp
index f25f915..8db9656 100644
--- a/Swiften/Network/BoostConnectionServer.cpp
+++ b/Swiften/Network/BoostConnectionServer.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 */
@@ -19,10 +19,10 @@
19 19
20namespace Swift { 20namespace Swift {
21 21
22BoostConnectionServer::BoostConnectionServer(int port, std::shared_ptr<boost::asio::io_service> ioService, EventLoop* eventLoop) : port_(port), ioService_(ioService), eventLoop(eventLoop), acceptor_(nullptr) { 22BoostConnectionServer::BoostConnectionServer(unsigned short port, std::shared_ptr<boost::asio::io_service> ioService, EventLoop* eventLoop) : port_(port), ioService_(ioService), eventLoop(eventLoop), acceptor_(nullptr) {
23} 23}
24 24
25BoostConnectionServer::BoostConnectionServer(const HostAddress &address, int port, std::shared_ptr<boost::asio::io_service> ioService, EventLoop* eventLoop) : address_(address), port_(port), ioService_(ioService), eventLoop(eventLoop), acceptor_(nullptr) { 25BoostConnectionServer::BoostConnectionServer(const HostAddress &address, unsigned short port, std::shared_ptr<boost::asio::io_service> ioService, EventLoop* eventLoop) : address_(address), port_(port), ioService_(ioService), eventLoop(eventLoop), acceptor_(nullptr) {
26} 26}
27 27
28void BoostConnectionServer::start() { 28void BoostConnectionServer::start() {
@@ -37,10 +37,10 @@ boost::optional<BoostConnectionServer::Error> BoostConnectionServer::tryStart()
37 assert(!acceptor_); 37 assert(!acceptor_);
38 boost::asio::ip::tcp::endpoint endpoint; 38 boost::asio::ip::tcp::endpoint endpoint;
39 if (address_.isValid()) { 39 if (address_.isValid()) {
40 endpoint = boost::asio::ip::tcp::endpoint(address_.getRawAddress(), boost::numeric_cast<unsigned short>(port_)); 40 endpoint = boost::asio::ip::tcp::endpoint(address_.getRawAddress(), port_);
41 } 41 }
42 else { 42 else {
43 endpoint = boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v6(), boost::numeric_cast<unsigned short>(port_)); 43 endpoint = boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v6(), port_);
44 } 44 }
45 acceptor_ = new boost::asio::ip::tcp::acceptor(*ioService_, endpoint); 45 acceptor_ = new boost::asio::ip::tcp::acceptor(*ioService_, endpoint);
46 if (endpoint.protocol() == boost::asio::ip::tcp::v6()) { 46 if (endpoint.protocol() == boost::asio::ip::tcp::v6()) {
diff --git a/Swiften/Network/BoostConnectionServer.h b/Swiften/Network/BoostConnectionServer.h
index 3dd9830..917d638 100644
--- a/Swiften/Network/BoostConnectionServer.h
+++ b/Swiften/Network/BoostConnectionServer.h
@@ -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 */
@@ -23,11 +23,11 @@ namespace Swift {
23 public: 23 public:
24 typedef std::shared_ptr<BoostConnectionServer> ref; 24 typedef std::shared_ptr<BoostConnectionServer> ref;
25 25
26 static ref create(int port, std::shared_ptr<boost::asio::io_service> ioService, EventLoop* eventLoop) { 26 static ref create(unsigned short port, std::shared_ptr<boost::asio::io_service> ioService, EventLoop* eventLoop) {
27 return ref(new BoostConnectionServer(port, ioService, eventLoop)); 27 return ref(new BoostConnectionServer(port, ioService, eventLoop));
28 } 28 }
29 29
30 static ref create(const HostAddress &address, int port, std::shared_ptr<boost::asio::io_service> ioService, EventLoop* eventLoop) { 30 static ref create(const HostAddress &address, unsigned short port, std::shared_ptr<boost::asio::io_service> ioService, EventLoop* eventLoop) {
31 return ref(new BoostConnectionServer(address, port, ioService, eventLoop)); 31 return ref(new BoostConnectionServer(address, port, ioService, eventLoop));
32 } 32 }
33 33
@@ -40,8 +40,8 @@ namespace Swift {
40 boost::signals2::signal<void (boost::optional<Error>)> onStopped; 40 boost::signals2::signal<void (boost::optional<Error>)> onStopped;
41 41
42 private: 42 private:
43 BoostConnectionServer(int port, std::shared_ptr<boost::asio::io_service> ioService, EventLoop* eventLoop); 43 BoostConnectionServer(unsigned short port, std::shared_ptr<boost::asio::io_service> ioService, EventLoop* eventLoop);
44 BoostConnectionServer(const HostAddress &address, int port, std::shared_ptr<boost::asio::io_service> ioService, EventLoop* eventLoop); 44 BoostConnectionServer(const HostAddress &address, unsigned short port, std::shared_ptr<boost::asio::io_service> ioService, EventLoop* eventLoop);
45 45
46 void stop(boost::optional<Error> e); 46 void stop(boost::optional<Error> e);
47 void acceptNextConnection(); 47 void acceptNextConnection();
@@ -49,7 +49,7 @@ namespace Swift {
49 49
50 private: 50 private:
51 HostAddress address_; 51 HostAddress address_;
52 int port_; 52 unsigned short port_;
53 std::shared_ptr<boost::asio::io_service> ioService_; 53 std::shared_ptr<boost::asio::io_service> ioService_;
54 EventLoop* eventLoop; 54 EventLoop* eventLoop;
55 boost::asio::ip::tcp::acceptor* acceptor_; 55 boost::asio::ip::tcp::acceptor* acceptor_;
diff --git a/Swiften/Network/BoostConnectionServerFactory.cpp b/Swiften/Network/BoostConnectionServerFactory.cpp
index 8b3fd2f..6936453 100644
--- a/Swiften/Network/BoostConnectionServerFactory.cpp
+++ b/Swiften/Network/BoostConnectionServerFactory.cpp
@@ -19,11 +19,11 @@ namespace Swift {
19BoostConnectionServerFactory::BoostConnectionServerFactory(std::shared_ptr<boost::asio::io_service> ioService, EventLoop* eventLoop) : ioService(ioService), eventLoop(eventLoop) { 19BoostConnectionServerFactory::BoostConnectionServerFactory(std::shared_ptr<boost::asio::io_service> ioService, EventLoop* eventLoop) : ioService(ioService), eventLoop(eventLoop) {
20} 20}
21 21
22std::shared_ptr<ConnectionServer> BoostConnectionServerFactory::createConnectionServer(int port) { 22std::shared_ptr<ConnectionServer> BoostConnectionServerFactory::createConnectionServer(unsigned short port) {
23 return BoostConnectionServer::create(port, ioService, eventLoop); 23 return BoostConnectionServer::create(port, ioService, eventLoop);
24} 24}
25 25
26std::shared_ptr<ConnectionServer> BoostConnectionServerFactory::createConnectionServer(const Swift::HostAddress &hostAddress, int port) { 26std::shared_ptr<ConnectionServer> BoostConnectionServerFactory::createConnectionServer(const Swift::HostAddress &hostAddress, unsigned short port) {
27 return BoostConnectionServer::create(hostAddress, port, ioService, eventLoop); 27 return BoostConnectionServer::create(hostAddress, port, ioService, eventLoop);
28} 28}
29 29
diff --git a/Swiften/Network/BoostConnectionServerFactory.h b/Swiften/Network/BoostConnectionServerFactory.h
index 033e63d..956132b 100644
--- a/Swiften/Network/BoostConnectionServerFactory.h
+++ b/Swiften/Network/BoostConnectionServerFactory.h
@@ -5,7 +5,7 @@
5 */ 5 */
6 6
7/* 7/*
8 * Copyright (c) 2015-2016 Isode Limited. 8 * Copyright (c) 2015-2018 Isode Limited.
9 * All rights reserved. 9 * All rights reserved.
10 * See the COPYING file for more information. 10 * See the COPYING file for more information.
11 */ 11 */
@@ -25,9 +25,9 @@ namespace Swift {
25 public: 25 public:
26 BoostConnectionServerFactory(std::shared_ptr<boost::asio::io_service>, EventLoop* eventLoop); 26 BoostConnectionServerFactory(std::shared_ptr<boost::asio::io_service>, EventLoop* eventLoop);
27 27
28 virtual std::shared_ptr<ConnectionServer> createConnectionServer(int port); 28 virtual std::shared_ptr<ConnectionServer> createConnectionServer(unsigned short port);
29 29
30 virtual std::shared_ptr<ConnectionServer> createConnectionServer(const Swift::HostAddress &hostAddress, int port); 30 virtual std::shared_ptr<ConnectionServer> createConnectionServer(const Swift::HostAddress &hostAddress, unsigned short port);
31 31
32 private: 32 private:
33 std::shared_ptr<boost::asio::io_service> ioService; 33 std::shared_ptr<boost::asio::io_service> ioService;
diff --git a/Swiften/Network/ChainedConnector.cpp b/Swiften/Network/ChainedConnector.cpp
index ea55db3..94899ad 100644
--- a/Swiften/Network/ChainedConnector.cpp
+++ b/Swiften/Network/ChainedConnector.cpp
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2011-2016 Isode Limited. 2 * Copyright (c) 2011-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 */
@@ -18,7 +18,7 @@ using namespace Swift;
18 18
19ChainedConnector::ChainedConnector( 19ChainedConnector::ChainedConnector(
20 const std::string& hostname, 20 const std::string& hostname,
21 int port, 21 unsigned short port,
22 const boost::optional<std::string>& serviceLookupPrefix, 22 const boost::optional<std::string>& serviceLookupPrefix,
23 DomainNameResolver* resolver, 23 DomainNameResolver* resolver,
24 const std::vector<ConnectionFactory*>& connectionFactories, 24 const std::vector<ConnectionFactory*>& connectionFactories,
diff --git a/Swiften/Network/ChainedConnector.h b/Swiften/Network/ChainedConnector.h
index a00d7e5..9620293 100644
--- a/Swiften/Network/ChainedConnector.h
+++ b/Swiften/Network/ChainedConnector.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2011-2016 Isode Limited. 2 * Copyright (c) 2011-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 */
@@ -26,7 +26,7 @@ namespace Swift {
26 26
27 class SWIFTEN_API ChainedConnector { 27 class SWIFTEN_API ChainedConnector {
28 public: 28 public:
29 ChainedConnector(const std::string& hostname, int port, const boost::optional<std::string>& serviceLookupPrefix, DomainNameResolver*, const std::vector<ConnectionFactory*>&, TimerFactory*); 29 ChainedConnector(const std::string& hostname, unsigned short port, const boost::optional<std::string>& serviceLookupPrefix, DomainNameResolver*, const std::vector<ConnectionFactory*>&, TimerFactory*);
30 ~ChainedConnector(); 30 ~ChainedConnector();
31 31
32 void setTimeoutMilliseconds(int milliseconds); 32 void setTimeoutMilliseconds(int milliseconds);
@@ -42,7 +42,7 @@ namespace Swift {
42 42
43 private: 43 private:
44 std::string hostname; 44 std::string hostname;
45 int port; 45 unsigned short port;
46 boost::optional<std::string> serviceLookupPrefix; 46 boost::optional<std::string> serviceLookupPrefix;
47 DomainNameResolver* resolver; 47 DomainNameResolver* resolver;
48 std::vector<ConnectionFactory*> connectionFactories; 48 std::vector<ConnectionFactory*> connectionFactories;
diff --git a/Swiften/Network/ConnectionServerFactory.h b/Swiften/Network/ConnectionServerFactory.h
index 413131e..2ebccc1 100644
--- a/Swiften/Network/ConnectionServerFactory.h
+++ b/Swiften/Network/ConnectionServerFactory.h
@@ -5,7 +5,7 @@
5 */ 5 */
6 6
7/* 7/*
8 * Copyright (c) 2015-2016 Isode Limited. 8 * Copyright (c) 2015-2018 Isode Limited.
9 * All rights reserved. 9 * All rights reserved.
10 * See the COPYING file for more information. 10 * See the COPYING file for more information.
11 */ 11 */
@@ -24,8 +24,8 @@ namespace Swift {
24 public: 24 public:
25 virtual ~ConnectionServerFactory(); 25 virtual ~ConnectionServerFactory();
26 26
27 virtual std::shared_ptr<ConnectionServer> createConnectionServer(int port) = 0; 27 virtual std::shared_ptr<ConnectionServer> createConnectionServer(unsigned short port) = 0;
28 28
29 virtual std::shared_ptr<ConnectionServer> createConnectionServer(const Swift::HostAddress& hostAddress, int port) = 0; 29 virtual std::shared_ptr<ConnectionServer> createConnectionServer(const Swift::HostAddress& hostAddress, unsigned short port) = 0;
30 }; 30 };
31} 31}
diff --git a/Swiften/Network/Connector.cpp b/Swiften/Network/Connector.cpp
index ca924bb..a0e6b23 100644
--- a/Swiften/Network/Connector.cpp
+++ b/Swiften/Network/Connector.cpp
@@ -17,7 +17,7 @@
17 17
18namespace Swift { 18namespace Swift {
19 19
20Connector::Connector(const std::string& hostname, int port, const boost::optional<std::string>& serviceLookupPrefix, DomainNameResolver* resolver, ConnectionFactory* connectionFactory, TimerFactory* timerFactory) : hostname(hostname), port(port), serviceLookupPrefix(serviceLookupPrefix), resolver(resolver), connectionFactory(connectionFactory), timerFactory(timerFactory), timeoutMilliseconds(0), queriedAllServices(true), foundSomeDNS(false) { 20Connector::Connector(const std::string& hostname, unsigned short port, const boost::optional<std::string>& serviceLookupPrefix, DomainNameResolver* resolver, ConnectionFactory* connectionFactory, TimerFactory* timerFactory) : hostname(hostname), port(port), serviceLookupPrefix(serviceLookupPrefix), resolver(resolver), connectionFactory(connectionFactory), timerFactory(timerFactory), timeoutMilliseconds(0), queriedAllServices(true), foundSomeDNS(false) {
21} 21}
22 22
23void Connector::setTimeoutMilliseconds(int milliseconds) { 23void Connector::setTimeoutMilliseconds(int milliseconds) {
@@ -122,7 +122,7 @@ void Connector::tryNextAddress() {
122 HostAddress address = addressQueryResults.front(); 122 HostAddress address = addressQueryResults.front();
123 addressQueryResults.pop_front(); 123 addressQueryResults.pop_front();
124 124
125 int connectPort = (port == -1 ? 5222 : port); 125 unsigned short connectPort = (port == 0 ? 5222 : port);
126 if (!serviceQueryResults.empty()) { 126 if (!serviceQueryResults.empty()) {
127 connectPort = serviceQueryResults.front().port; 127 connectPort = serviceQueryResults.front().port;
128 } 128 }
diff --git a/Swiften/Network/Connector.h b/Swiften/Network/Connector.h
index d8a1b88..c76a4af 100644
--- a/Swiften/Network/Connector.h
+++ b/Swiften/Network/Connector.h
@@ -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 */
@@ -30,7 +30,7 @@ namespace Swift {
30 public: 30 public:
31 typedef std::shared_ptr<Connector> ref; 31 typedef std::shared_ptr<Connector> ref;
32 32
33 static Connector::ref create(const std::string& hostname, int port, const boost::optional<std::string>& serviceLookupPrefix, DomainNameResolver* resolver, ConnectionFactory* connectionFactory, TimerFactory* timerFactory) { 33 static Connector::ref create(const std::string& hostname, unsigned short port, const boost::optional<std::string>& serviceLookupPrefix, DomainNameResolver* resolver, ConnectionFactory* connectionFactory, TimerFactory* timerFactory) {
34 return ref(new Connector(hostname, port, serviceLookupPrefix, resolver, connectionFactory, timerFactory)); 34 return ref(new Connector(hostname, port, serviceLookupPrefix, resolver, connectionFactory, timerFactory));
35 } 35 }
36 36
@@ -46,7 +46,7 @@ namespace Swift {
46 boost::signals2::signal<void (std::shared_ptr<Connection>, std::shared_ptr<Error>)> onConnectFinished; 46 boost::signals2::signal<void (std::shared_ptr<Connection>, std::shared_ptr<Error>)> onConnectFinished;
47 47
48 private: 48 private:
49 Connector(const std::string& hostname, int port, const boost::optional<std::string>& serviceLookupPrefix, DomainNameResolver*, ConnectionFactory*, TimerFactory*); 49 Connector(const std::string& hostname, unsigned short port, const boost::optional<std::string>& serviceLookupPrefix, DomainNameResolver*, ConnectionFactory*, TimerFactory*);
50 50
51 void handleServiceQueryResult(const std::vector<DomainNameServiceQuery::Result>& result); 51 void handleServiceQueryResult(const std::vector<DomainNameServiceQuery::Result>& result);
52 void handleAddressQueryResult(const std::vector<HostAddress>& address, boost::optional<DomainNameResolveError> error); 52 void handleAddressQueryResult(const std::vector<HostAddress>& address, boost::optional<DomainNameResolveError> error);
@@ -63,7 +63,7 @@ namespace Swift {
63 63
64 private: 64 private:
65 std::string hostname; 65 std::string hostname;
66 int port; 66 unsigned short port;
67 boost::optional<std::string> serviceLookupPrefix; 67 boost::optional<std::string> serviceLookupPrefix;
68 DomainNameResolver* resolver; 68 DomainNameResolver* resolver;
69 ConnectionFactory* connectionFactory; 69 ConnectionFactory* connectionFactory;
diff --git a/Swiften/Network/DomainNameServiceQuery.cpp b/Swiften/Network/DomainNameServiceQuery.cpp
index 548c837..5784dd7 100644
--- a/Swiften/Network/DomainNameServiceQuery.cpp
+++ b/Swiften/Network/DomainNameServiceQuery.cpp
@@ -43,16 +43,21 @@ void DomainNameServiceQuery::sortResults(std::vector<DomainNameServiceQuery::Res
43 /* easy hack to account for '0' weights getting at least some weight */ 43 /* easy hack to account for '0' weights getting at least some weight */
44 return result.weight + 1; 44 return result.weight + 1;
45 }); 45 });
46 for (int j = 0; j < boost::numeric_cast<int>(weights.size() - 1); ++j) { 46 try {
47 std::vector<int> cumulativeWeights; 47 for (int j = 0; j < boost::numeric_cast<int>(weights.size()) - 1; ++j) {
48 std::partial_sum( 48 std::vector<int> cumulativeWeights;
49 weights.begin() + j, 49 std::partial_sum(
50 weights.end(), 50 weights.begin() + j,
51 std::back_inserter(cumulativeWeights)); 51 weights.end(),
52 int randomNumber = generator.generateRandomInteger(cumulativeWeights.back()); 52 std::back_inserter(cumulativeWeights));
53 auto selectedIndex = std::lower_bound(cumulativeWeights.begin(), cumulativeWeights.end(), randomNumber) - cumulativeWeights.begin(); 53 int randomNumber = generator.generateRandomInteger(cumulativeWeights.back());
54 std::swap(i[j], i[j + selectedIndex]); 54 auto selectedIndex = std::lower_bound(cumulativeWeights.begin(), cumulativeWeights.end(), randomNumber) - cumulativeWeights.begin();
55 std::swap(weights.begin()[j], weights.begin()[j + selectedIndex]); 55 std::swap(i[j], i[j + selectedIndex]);
56 std::swap(weights.begin()[j], weights.begin()[j + selectedIndex]);
57 }
58 }
59 catch (const boost::numeric::bad_numeric_cast&) {
60 // In the unlikely event of weights.size() being too large, use the list as-is.
56 } 61 }
57 } 62 }
58 i = next; 63 i = next;
diff --git a/Swiften/Network/DomainNameServiceQuery.h b/Swiften/Network/DomainNameServiceQuery.h
index b27f32e..1631b99 100644
--- a/Swiften/Network/DomainNameServiceQuery.h
+++ b/Swiften/Network/DomainNameServiceQuery.h
@@ -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 */
@@ -24,9 +24,9 @@ namespace Swift {
24 typedef std::shared_ptr<DomainNameServiceQuery> ref; 24 typedef std::shared_ptr<DomainNameServiceQuery> ref;
25 25
26 struct Result { 26 struct Result {
27 Result(const std::string& hostname = "", int port = -1, int priority = -1, int weight = -1) : hostname(hostname), port(port), priority(priority), weight(weight) {} 27 Result(const std::string& hostname = "", unsigned short port = 0, int priority = -1, int weight = -1) : hostname(hostname), port(port), priority(priority), weight(weight) {}
28 std::string hostname; 28 std::string hostname;
29 int port; 29 unsigned short port;
30 int priority; 30 int priority;
31 int weight; 31 int weight;
32 }; 32 };
diff --git a/Swiften/Network/DummyConnectionServer.h b/Swiften/Network/DummyConnectionServer.h
index 970cbb7..a4fd07f 100644
--- a/Swiften/Network/DummyConnectionServer.h
+++ b/Swiften/Network/DummyConnectionServer.h
@@ -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 */
@@ -17,8 +17,8 @@
17namespace Swift { 17namespace Swift {
18 class SWIFTEN_API DummyConnectionServer : public ConnectionServer, public EventOwner, public std::enable_shared_from_this<DummyConnectionServer> { 18 class SWIFTEN_API DummyConnectionServer : public ConnectionServer, public EventOwner, public std::enable_shared_from_this<DummyConnectionServer> {
19 public: 19 public:
20 DummyConnectionServer(EventLoop* /*eventLoop*/, int port) : localAddressPort(HostAddress(), port) {} 20 DummyConnectionServer(EventLoop* /*eventLoop*/, unsigned short port) : localAddressPort(HostAddress(), port) {}
21 DummyConnectionServer(EventLoop* /*eventLoop*/, const Swift::HostAddress& hostAddress, int port) : localAddressPort(hostAddress, port) {} 21 DummyConnectionServer(EventLoop* /*eventLoop*/, const Swift::HostAddress& hostAddress, unsigned short port) : localAddressPort(hostAddress, port) {}
22 virtual ~DummyConnectionServer() {} 22 virtual ~DummyConnectionServer() {}
23 23
24 virtual HostAddressPort getAddressPort() const { 24 virtual HostAddressPort getAddressPort() const {
diff --git a/Swiften/Network/DummyConnectionServerFactory.h b/Swiften/Network/DummyConnectionServerFactory.h
index 822f95f..4b25118 100644
--- a/Swiften/Network/DummyConnectionServerFactory.h
+++ b/Swiften/Network/DummyConnectionServerFactory.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2014-2016 Isode Limited. 2 * Copyright (c) 2014-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 */
@@ -20,11 +20,11 @@ public:
20 DummyConnectionServerFactory(EventLoop* eventLoop) : eventLoop(eventLoop) {} 20 DummyConnectionServerFactory(EventLoop* eventLoop) : eventLoop(eventLoop) {}
21 virtual ~DummyConnectionServerFactory() {} 21 virtual ~DummyConnectionServerFactory() {}
22 22
23 virtual std::shared_ptr<ConnectionServer> createConnectionServer(int port) { 23 virtual std::shared_ptr<ConnectionServer> createConnectionServer(unsigned short port) {
24 return std::make_shared<DummyConnectionServer>(eventLoop, port); 24 return std::make_shared<DummyConnectionServer>(eventLoop, port);
25 } 25 }
26 26
27 virtual std::shared_ptr<ConnectionServer> createConnectionServer(const Swift::HostAddress& hostAddress, int port) { 27 virtual std::shared_ptr<ConnectionServer> createConnectionServer(const Swift::HostAddress& hostAddress, unsigned short port) {
28 return std::make_shared<DummyConnectionServer>(eventLoop, hostAddress, port); 28 return std::make_shared<DummyConnectionServer>(eventLoop, hostAddress, port);
29 } 29 }
30 30
diff --git a/Swiften/Network/EnvironmentProxyProvider.cpp b/Swiften/Network/EnvironmentProxyProvider.cpp
index 8edb136..65cf4ff 100644
--- a/Swiften/Network/EnvironmentProxyProvider.cpp
+++ b/Swiften/Network/EnvironmentProxyProvider.cpp
@@ -17,6 +17,8 @@
17 17
18#include <iostream> 18#include <iostream>
19 19
20#include <boost/numeric/conversion/cast.hpp>
21
20#include <Swiften/Base/Log.h> 22#include <Swiften/Base/Log.h>
21 23
22namespace Swift { 24namespace Swift {
@@ -38,7 +40,7 @@ HostAddressPort EnvironmentProxyProvider::getSOCKS5Proxy() const {
38HostAddressPort EnvironmentProxyProvider::getFromEnv(const char* envVarName, std::string proxyProtocol) { 40HostAddressPort EnvironmentProxyProvider::getFromEnv(const char* envVarName, std::string proxyProtocol) {
39 char* envVar = nullptr; 41 char* envVar = nullptr;
40 std::string address; 42 std::string address;
41 int port = 0; 43 unsigned short port = 0;
42 44
43 envVar = getenv(envVarName); 45 envVar = getenv(envVarName);
44 46
@@ -46,7 +48,11 @@ HostAddressPort EnvironmentProxyProvider::getFromEnv(const char* envVarName, std
46 address = envVar != nullptr ? envVar : "0.0.0.0"; 48 address = envVar != nullptr ? envVar : "0.0.0.0";
47 if(envVar != nullptr && address.compare(0, proxyProtocol.length(), proxyProtocol) == 0) { 49 if(envVar != nullptr && address.compare(0, proxyProtocol.length(), proxyProtocol) == 0) {
48 address = address.substr(proxyProtocol.length(), address.length()); 50 address = address.substr(proxyProtocol.length(), address.length());
49 port = atoi(address.substr(address.find(':') + 1, address.length()).c_str()); 51 try {
52 port = boost::numeric_cast<unsigned short>(atoi(address.substr(address.find(':') + 1, address.length()).c_str()));
53 }
54 catch (boost::numeric::bad_numeric_cast&) {
55 }
50 address = address.substr(0, address.find(':')); 56 address = address.substr(0, address.find(':'));
51 } 57 }
52 58
diff --git a/Swiften/Network/GConfProxyProvider.cpp b/Swiften/Network/GConfProxyProvider.cpp
index eade450..7c31868 100644
--- a/Swiften/Network/GConfProxyProvider.cpp
+++ b/Swiften/Network/GConfProxyProvider.cpp
@@ -5,7 +5,7 @@
5 */ 5 */
6 6
7/* 7/*
8 * Copyright (c) 2016-2017 Isode Limited. 8 * Copyright (c) 2016-2018 Isode Limited.
9 * All rights reserved. 9 * All rights reserved.
10 * See the COPYING file for more information. 10 * See the COPYING file for more information.
11 */ 11 */
@@ -21,6 +21,8 @@ extern "C" {
21#include <gconf/gconf-client.h> 21#include <gconf/gconf-client.h>
22} 22}
23 23
24#include <boost/numeric/conversion/cast.hpp>
25
24#include <Swiften/Base/Log.h> 26#include <Swiften/Base/Log.h>
25 27
26namespace Swift { 28namespace Swift {
@@ -50,13 +52,17 @@ HostAddressPort GConfProxyProvider::getSOCKS5Proxy() const {
50 52
51HostAddressPort GConfProxyProvider::getFromGConf(const char* gcHost, const char* gcPort) { 53HostAddressPort GConfProxyProvider::getFromGConf(const char* gcHost, const char* gcPort) {
52 std::string address; 54 std::string address;
53 int port = 0; 55 unsigned short port = 0;
54 gchar* str; 56 gchar* str;
55 57
56 GConfClient* client = gconf_client_get_default(); 58 GConfClient* client = gconf_client_get_default();
57 59
58 str = gconf_client_get_string(client, gcHost, NULL); 60 str = gconf_client_get_string(client, gcHost, NULL);
59 port = static_cast<int> (gconf_client_get_int(client, gcPort, NULL)); 61 try {
62 port = boost::numeric_cast<unsigned short>(gconf_client_get_int(client, gcPort, NULL));
63 }
64 catch (const boost::numeric::bad_numeric_cast&) {
65 }
60 66
61 if(str) { 67 if(str) {
62 address = static_cast<char*> (str); 68 address = static_cast<char*> (str);
diff --git a/Swiften/Network/HTTPConnectProxiedConnection.cpp b/Swiften/Network/HTTPConnectProxiedConnection.cpp
index b5e521b..8eba49e 100644
--- a/Swiften/Network/HTTPConnectProxiedConnection.cpp
+++ b/Swiften/Network/HTTPConnectProxiedConnection.cpp
@@ -5,7 +5,7 @@
5 */ 5 */
6 6
7/* 7/*
8 * Copyright (c) 2011-2016 Isode Limited. 8 * Copyright (c) 2011-2018 Isode Limited.
9 * All rights reserved. 9 * All rights reserved.
10 * See the COPYING file for more information. 10 * See the COPYING file for more information.
11 */ 11 */
@@ -36,7 +36,7 @@ HTTPConnectProxiedConnection::HTTPConnectProxiedConnection(
36 ConnectionFactory* connectionFactory, 36 ConnectionFactory* connectionFactory,
37 TimerFactory* timerFactory, 37 TimerFactory* timerFactory,
38 const std::string& proxyHost, 38 const std::string& proxyHost,
39 int proxyPort, 39 unsigned short proxyPort,
40 const SafeString& authID, 40 const SafeString& authID,
41 const SafeString& authPassword) : 41 const SafeString& authPassword) :
42 ProxiedConnection(resolver, connectionFactory, timerFactory, proxyHost, proxyPort), 42 ProxiedConnection(resolver, connectionFactory, timerFactory, proxyHost, proxyPort),
diff --git a/Swiften/Network/HTTPConnectProxiedConnection.h b/Swiften/Network/HTTPConnectProxiedConnection.h
index 6592839..a83d47c 100644
--- a/Swiften/Network/HTTPConnectProxiedConnection.h
+++ b/Swiften/Network/HTTPConnectProxiedConnection.h
@@ -5,7 +5,7 @@
5 */ 5 */
6 6
7/* 7/*
8 * Copyright (c) 2011-2017 Isode Limited. 8 * Copyright (c) 2011-2018 Isode Limited.
9 * All rights reserved. 9 * All rights reserved.
10 * See the COPYING file for more information. 10 * See the COPYING file for more information.
11 */ 11 */
@@ -30,14 +30,14 @@ namespace Swift {
30 30
31 virtual ~HTTPConnectProxiedConnection(); 31 virtual ~HTTPConnectProxiedConnection();
32 32
33 static ref create(DomainNameResolver* resolver, ConnectionFactory* connectionFactory, TimerFactory* timerFactory, const std::string& proxyHost, int proxyPort, const SafeString& authID, const SafeString& authPassword) { 33 static ref create(DomainNameResolver* resolver, ConnectionFactory* connectionFactory, TimerFactory* timerFactory, const std::string& proxyHost, unsigned short proxyPort, const SafeString& authID, const SafeString& authPassword) {
34 return ref(new HTTPConnectProxiedConnection(resolver, connectionFactory, timerFactory, proxyHost, proxyPort, authID, authPassword)); 34 return ref(new HTTPConnectProxiedConnection(resolver, connectionFactory, timerFactory, proxyHost, proxyPort, authID, authPassword));
35 } 35 }
36 36
37 void setHTTPTrafficFilter(std::shared_ptr<HTTPTrafficFilter> trafficFilter); 37 void setHTTPTrafficFilter(std::shared_ptr<HTTPTrafficFilter> trafficFilter);
38 38
39 private: 39 private:
40 HTTPConnectProxiedConnection(DomainNameResolver* resolver, ConnectionFactory* connectionFactory, TimerFactory* timerFactory, const std::string& proxyHost, int proxyPort, const SafeString& authID, const SafeString& authPassword); 40 HTTPConnectProxiedConnection(DomainNameResolver* resolver, ConnectionFactory* connectionFactory, TimerFactory* timerFactory, const std::string& proxyHost, unsigned short proxyPort, const SafeString& authID, const SafeString& authPassword);
41 41
42 virtual void initializeProxy(); 42 virtual void initializeProxy();
43 virtual void handleProxyInitializeData(std::shared_ptr<SafeByteArray> data); 43 virtual void handleProxyInitializeData(std::shared_ptr<SafeByteArray> data);
diff --git a/Swiften/Network/HTTPConnectProxiedConnectionFactory.cpp b/Swiften/Network/HTTPConnectProxiedConnectionFactory.cpp
index 91ace3d..54b998a 100644
--- a/Swiften/Network/HTTPConnectProxiedConnectionFactory.cpp
+++ b/Swiften/Network/HTTPConnectProxiedConnectionFactory.cpp
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2012-2016 Isode Limited. 2 * Copyright (c) 2012-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 */
@@ -16,11 +16,11 @@
16 16
17namespace Swift { 17namespace Swift {
18 18
19HTTPConnectProxiedConnectionFactory::HTTPConnectProxiedConnectionFactory(DomainNameResolver* resolver, ConnectionFactory* connectionFactory, TimerFactory* timerFactory, const std::string& proxyHost, int proxyPort, std::shared_ptr<HTTPTrafficFilter> httpTrafficFilter) : resolver_(resolver), connectionFactory_(connectionFactory), timerFactory_(timerFactory), proxyHost_(proxyHost), proxyPort_(proxyPort), authID_(""), authPassword_(""), httpTrafficFilter_(httpTrafficFilter) { 19HTTPConnectProxiedConnectionFactory::HTTPConnectProxiedConnectionFactory(DomainNameResolver* resolver, ConnectionFactory* connectionFactory, TimerFactory* timerFactory, const std::string& proxyHost, unsigned short proxyPort, std::shared_ptr<HTTPTrafficFilter> httpTrafficFilter) : resolver_(resolver), connectionFactory_(connectionFactory), timerFactory_(timerFactory), proxyHost_(proxyHost), proxyPort_(proxyPort), authID_(""), authPassword_(""), httpTrafficFilter_(httpTrafficFilter) {
20} 20}
21 21
22 22
23HTTPConnectProxiedConnectionFactory::HTTPConnectProxiedConnectionFactory(DomainNameResolver* resolver, ConnectionFactory* connectionFactory, TimerFactory* timerFactory, const std::string& proxyHost, int proxyPort, const SafeString& authID, const SafeString& authPassword, std::shared_ptr<HTTPTrafficFilter> httpTrafficFilter) : resolver_(resolver), connectionFactory_(connectionFactory), timerFactory_(timerFactory), proxyHost_(proxyHost), proxyPort_(proxyPort), authID_(authID), authPassword_(authPassword), httpTrafficFilter_(httpTrafficFilter) { 23HTTPConnectProxiedConnectionFactory::HTTPConnectProxiedConnectionFactory(DomainNameResolver* resolver, ConnectionFactory* connectionFactory, TimerFactory* timerFactory, const std::string& proxyHost, unsigned short proxyPort, const SafeString& authID, const SafeString& authPassword, std::shared_ptr<HTTPTrafficFilter> httpTrafficFilter) : resolver_(resolver), connectionFactory_(connectionFactory), timerFactory_(timerFactory), proxyHost_(proxyHost), proxyPort_(proxyPort), authID_(authID), authPassword_(authPassword), httpTrafficFilter_(httpTrafficFilter) {
24} 24}
25 25
26std::shared_ptr<Connection> HTTPConnectProxiedConnectionFactory::createConnection() { 26std::shared_ptr<Connection> HTTPConnectProxiedConnectionFactory::createConnection() {
diff --git a/Swiften/Network/HTTPConnectProxiedConnectionFactory.h b/Swiften/Network/HTTPConnectProxiedConnectionFactory.h
index 395f64f..7a5f527 100644
--- a/Swiften/Network/HTTPConnectProxiedConnectionFactory.h
+++ b/Swiften/Network/HTTPConnectProxiedConnectionFactory.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2012-2017 Isode Limited. 2 * Copyright (c) 2012-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 */
@@ -24,8 +24,8 @@ namespace Swift {
24 24
25 class SWIFTEN_API HTTPConnectProxiedConnectionFactory : public ConnectionFactory { 25 class SWIFTEN_API HTTPConnectProxiedConnectionFactory : public ConnectionFactory {
26 public: 26 public:
27 HTTPConnectProxiedConnectionFactory(DomainNameResolver* resolver, ConnectionFactory* connectionFactory, TimerFactory* timerFactory, const std::string& proxyHost, int proxyPort, std::shared_ptr<HTTPTrafficFilter> httpTrafficFilter = std::shared_ptr<HTTPTrafficFilter>()); 27 HTTPConnectProxiedConnectionFactory(DomainNameResolver* resolver, ConnectionFactory* connectionFactory, TimerFactory* timerFactory, const std::string& proxyHost, unsigned short proxyPort, std::shared_ptr<HTTPTrafficFilter> httpTrafficFilter = std::shared_ptr<HTTPTrafficFilter>());
28 HTTPConnectProxiedConnectionFactory(DomainNameResolver* resolver, ConnectionFactory* connectionFactory, TimerFactory* timerFactory, const std::string& proxyHost, int proxyPort, const SafeString& authID, const SafeString& authPassword, std::shared_ptr<HTTPTrafficFilter> httpTrafficFilter = std::shared_ptr<HTTPTrafficFilter>()); 28 HTTPConnectProxiedConnectionFactory(DomainNameResolver* resolver, ConnectionFactory* connectionFactory, TimerFactory* timerFactory, const std::string& proxyHost, unsigned short proxyPort, const SafeString& authID, const SafeString& authPassword, std::shared_ptr<HTTPTrafficFilter> httpTrafficFilter = std::shared_ptr<HTTPTrafficFilter>());
29 29
30 virtual std::shared_ptr<Connection> createConnection(); 30 virtual std::shared_ptr<Connection> createConnection();
31 31
@@ -34,7 +34,7 @@ namespace Swift {
34 ConnectionFactory* connectionFactory_; 34 ConnectionFactory* connectionFactory_;
35 TimerFactory* timerFactory_; 35 TimerFactory* timerFactory_;
36 std::string proxyHost_; 36 std::string proxyHost_;
37 int proxyPort_; 37 unsigned short proxyPort_;
38 SafeString authID_; 38 SafeString authID_;
39 SafeString authPassword_; 39 SafeString authPassword_;
40 std::shared_ptr<HTTPTrafficFilter> httpTrafficFilter_; 40 std::shared_ptr<HTTPTrafficFilter> httpTrafficFilter_;
diff --git a/Swiften/Network/HostAddressPort.cpp b/Swiften/Network/HostAddressPort.cpp
index 401ddec..248be2d 100644
--- a/Swiften/Network/HostAddressPort.cpp
+++ b/Swiften/Network/HostAddressPort.cpp
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2010 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 */
@@ -10,7 +10,7 @@
10 10
11using namespace Swift; 11using namespace Swift;
12 12
13HostAddressPort::HostAddressPort(const HostAddress& address, int port) : address_(address), port_(port) { 13HostAddressPort::HostAddressPort(const HostAddress& address, unsigned short port) : address_(address), port_(port) {
14} 14}
15 15
16HostAddressPort::HostAddressPort(const boost::asio::ip::tcp::endpoint& endpoint) { 16HostAddressPort::HostAddressPort(const boost::asio::ip::tcp::endpoint& endpoint) {
diff --git a/Swiften/Network/HostAddressPort.h b/Swiften/Network/HostAddressPort.h
index e42e1d1..14c7c66 100644
--- a/Swiften/Network/HostAddressPort.h
+++ b/Swiften/Network/HostAddressPort.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2010 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 */
@@ -14,14 +14,14 @@
14namespace Swift { 14namespace Swift {
15 class SWIFTEN_API HostAddressPort { 15 class SWIFTEN_API HostAddressPort {
16 public: 16 public:
17 HostAddressPort(const HostAddress& address = HostAddress(), int port = -1); 17 HostAddressPort(const HostAddress& address = HostAddress(), unsigned short port = 0);
18 HostAddressPort(const boost::asio::ip::tcp::endpoint& endpoint); 18 HostAddressPort(const boost::asio::ip::tcp::endpoint& endpoint);
19 19
20 const HostAddress& getAddress() const { 20 const HostAddress& getAddress() const {
21 return address_; 21 return address_;
22 } 22 }
23 23
24 int getPort() const { 24 unsigned short getPort() const {
25 return port_; 25 return port_;
26 } 26 }
27 27
@@ -37,6 +37,6 @@ namespace Swift {
37 37
38 private: 38 private:
39 HostAddress address_; 39 HostAddress address_;
40 int port_; 40 unsigned short port_;
41 }; 41 };
42} 42}
diff --git a/Swiften/Network/MacOSXProxyProvider.cpp b/Swiften/Network/MacOSXProxyProvider.cpp
index 232fc60..d3b10dd 100644
--- a/Swiften/Network/MacOSXProxyProvider.cpp
+++ b/Swiften/Network/MacOSXProxyProvider.cpp
@@ -5,7 +5,7 @@
5 */ 5 */
6 6
7/* 7/*
8 * Copyright (c) 2013-2016 Isode Limited. 8 * Copyright (c) 2013-2018 Isode Limited.
9 * All rights reserved. 9 * All rights reserved.
10 * See the COPYING file for more information. 10 * See the COPYING file for more information.
11 */ 11 */
@@ -40,13 +40,15 @@ static HostAddressPort getFromDictionary(CFDictionaryRef dict, CFStringRef enabl
40 CFRelease(zero); 40 CFRelease(zero);
41 41
42 if(result != kCFCompareEqualTo) { 42 if(result != kCFCompareEqualTo) {
43 int port = 0; 43 unsigned short port = 0;
44 std::string host = ""; 44 std::string host = "";
45 45
46 try { 46 try {
47 CFNumberRef numberValue = reinterpret_cast<CFNumberRef> (CFDictionaryGetValue(dict, portKey)); 47 CFNumberRef numberValue = reinterpret_cast<CFNumberRef> (CFDictionaryGetValue(dict, portKey));
48 if(numberValue != nullptr) { 48 if(numberValue != nullptr) {
49 CFNumberGetValue(numberValue, kCFNumberIntType, &port); 49 int intPort = 0;
50 CFNumberGetValue(numberValue, kCFNumberIntType, &intPort);
51 port = boost::numeric_cast<unsigned short>(intPort);
50 } 52 }
51 53
52 CFStringRef stringValue = reinterpret_cast<CFStringRef> (CFDictionaryGetValue(dict, hostKey)); 54 CFStringRef stringValue = reinterpret_cast<CFStringRef> (CFDictionaryGetValue(dict, hostKey));
diff --git a/Swiften/Network/MiniUPnPInterface.cpp b/Swiften/Network/MiniUPnPInterface.cpp
index 2c61ad3..af3b67c 100644
--- a/Swiften/Network/MiniUPnPInterface.cpp
+++ b/Swiften/Network/MiniUPnPInterface.cpp
@@ -5,7 +5,7 @@
5 */ 5 */
6 6
7/* 7/*
8 * Copyright (c) 2015-2016 Isode Limited. 8 * Copyright (c) 2015-2018 Isode Limited.
9 * All rights reserved. 9 * All rights reserved.
10 * See the COPYING file for more information. 10 * See the COPYING file for more information.
11 */ 11 */
@@ -73,7 +73,7 @@ boost::optional<HostAddress> MiniUPnPInterface::getPublicIP() {
73 } 73 }
74} 74}
75 75
76boost::optional<NATPortMapping> MiniUPnPInterface::addPortForward(int actualLocalPort, int actualPublicPort) { 76boost::optional<NATPortMapping> MiniUPnPInterface::addPortForward(unsigned short actualLocalPort, unsigned short actualPublicPort) {
77 if (!p->isValid) { 77 if (!p->isValid) {
78 return boost::optional<NATPortMapping>(); 78 return boost::optional<NATPortMapping>();
79 } 79 }
diff --git a/Swiften/Network/MiniUPnPInterface.h b/Swiften/Network/MiniUPnPInterface.h
index 89457b8..8c68268 100644
--- a/Swiften/Network/MiniUPnPInterface.h
+++ b/Swiften/Network/MiniUPnPInterface.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2011-2016 Isode Limited. 2 * Copyright (c) 2011-2018 Isode Limited.
3 * Licensed under the simplified BSD license. 3 * Licensed under the simplified BSD license.
4 * See Documentation/Licenses/BSD-simplified.txt for more information. 4 * See Documentation/Licenses/BSD-simplified.txt for more information.
5 */ 5 */
@@ -23,7 +23,7 @@ namespace Swift {
23 virtual bool isAvailable(); 23 virtual bool isAvailable();
24 24
25 boost::optional<HostAddress> getPublicIP(); 25 boost::optional<HostAddress> getPublicIP();
26 boost::optional<NATPortMapping> addPortForward(int localPort, int publicPort); 26 boost::optional<NATPortMapping> addPortForward(unsigned short localPort, unsigned short publicPort);
27 bool removePortForward(const NATPortMapping&); 27 bool removePortForward(const NATPortMapping&);
28 28
29 private: 29 private:
diff --git a/Swiften/Network/NATPMPInterface.cpp b/Swiften/Network/NATPMPInterface.cpp
index 5e0b3b3..8ab26d4 100644
--- a/Swiften/Network/NATPMPInterface.cpp
+++ b/Swiften/Network/NATPMPInterface.cpp
@@ -5,7 +5,7 @@
5 */ 5 */
6 6
7/* 7/*
8 * Copyright (c) 2014-2016 Isode Limited. 8 * Copyright (c) 2014-2018 Isode Limited.
9 * All rights reserved. 9 * All rights reserved.
10 * See the COPYING file for more information. 10 * See the COPYING file for more information.
11 */ 11 */
@@ -74,13 +74,13 @@ boost::optional<HostAddress> NATPMPInterface::getPublicIP() {
74 } 74 }
75} 75}
76 76
77boost::optional<NATPortMapping> NATPMPInterface::addPortForward(int localPort, int publicPort) { 77boost::optional<NATPortMapping> NATPMPInterface::addPortForward(unsigned short localPort, unsigned short publicPort) {
78 NATPortMapping mapping(localPort, publicPort, NATPortMapping::TCP); 78 NATPortMapping mapping(localPort, publicPort, NATPortMapping::TCP);
79 if (sendnewportmappingrequest( 79 if (sendnewportmappingrequest(
80 &p->natpmp, 80 &p->natpmp,
81 mapping.getProtocol() == NATPortMapping::TCP ? NATPMP_PROTOCOL_TCP : NATPMP_PROTOCOL_UDP, 81 mapping.getProtocol() == NATPortMapping::TCP ? NATPMP_PROTOCOL_TCP : NATPMP_PROTOCOL_UDP,
82 boost::numeric_cast<uint16_t>(mapping.getLocalPort()), 82 mapping.getLocalPort(),
83 boost::numeric_cast<uint16_t>(mapping.getPublicPort()), 83 mapping.getPublicPort(),
84 boost::numeric_cast<uint32_t>(mapping.getLeaseInSeconds())) < 0) { 84 boost::numeric_cast<uint32_t>(mapping.getLeaseInSeconds())) < 0) {
85 SWIFT_LOG(debug) << "Failed to send NAT-PMP port forwarding request!" << std::endl; 85 SWIFT_LOG(debug) << "Failed to send NAT-PMP port forwarding request!" << std::endl;
86 return boost::optional<NATPortMapping>(); 86 return boost::optional<NATPortMapping>();
diff --git a/Swiften/Network/NATPMPInterface.h b/Swiften/Network/NATPMPInterface.h
index e1666c8..58d62b6 100644
--- a/Swiften/Network/NATPMPInterface.h
+++ b/Swiften/Network/NATPMPInterface.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2011-2016 Isode Limited. 2 * Copyright (c) 2011-2018 Isode Limited.
3 * Licensed under the simplified BSD license. 3 * Licensed under the simplified BSD license.
4 * See Documentation/Licenses/BSD-simplified.txt for more information. 4 * See Documentation/Licenses/BSD-simplified.txt for more information.
5 */ 5 */
@@ -23,7 +23,7 @@ namespace Swift {
23 virtual bool isAvailable(); 23 virtual bool isAvailable();
24 24
25 virtual boost::optional<HostAddress> getPublicIP(); 25 virtual boost::optional<HostAddress> getPublicIP();
26 virtual boost::optional<NATPortMapping> addPortForward(int localPort, int publicPort); 26 virtual boost::optional<NATPortMapping> addPortForward(unsigned short localPort, unsigned short publicPort);
27 virtual bool removePortForward(const NATPortMapping&); 27 virtual bool removePortForward(const NATPortMapping&);
28 28
29 private: 29 private:
diff --git a/Swiften/Network/NATPortMapping.h b/Swiften/Network/NATPortMapping.h
index ff8fde3..b68052d 100644
--- a/Swiften/Network/NATPortMapping.h
+++ b/Swiften/Network/NATPortMapping.h
@@ -23,16 +23,16 @@ namespace Swift {
23 UDP 23 UDP
24 }; 24 };
25 25
26 NATPortMapping(int localPort, int publicPort, Protocol protocol = TCP, int leaseInSeconds = 60 * 60 * 24) : 26 NATPortMapping(unsigned short localPort, unsigned short publicPort, Protocol protocol = TCP, int leaseInSeconds = 60 * 60 * 24) :
27 publicPort(publicPort), localPort(localPort), protocol(protocol), leaseInSeconds(leaseInSeconds) { 27 publicPort(publicPort), localPort(localPort), protocol(protocol), leaseInSeconds(leaseInSeconds) {
28 28
29 } 29 }
30 30
31 int getPublicPort() const { 31 unsigned short getPublicPort() const {
32 return publicPort; 32 return publicPort;
33 } 33 }
34 34
35 int getLocalPort() const { 35 unsigned short getLocalPort() const {
36 return localPort; 36 return localPort;
37 } 37 }
38 38
@@ -45,8 +45,8 @@ namespace Swift {
45 } 45 }
46 46
47 private: 47 private:
48 int publicPort; 48 unsigned short publicPort;
49 int localPort; 49 unsigned short localPort;
50 Protocol protocol; 50 Protocol protocol;
51 int leaseInSeconds; 51 int leaseInSeconds;
52 }; 52 };
diff --git a/Swiften/Network/NATTraversalInterface.h b/Swiften/Network/NATTraversalInterface.h
index ea9ed6a..1655eb6 100644
--- a/Swiften/Network/NATTraversalInterface.h
+++ b/Swiften/Network/NATTraversalInterface.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2011-2015 Isode Limited. 2 * Copyright (c) 2011-2018 Isode Limited.
3 * Licensed under the simplified BSD license. 3 * Licensed under the simplified BSD license.
4 * See Documentation/Licenses/BSD-simplified.txt for more information. 4 * See Documentation/Licenses/BSD-simplified.txt for more information.
5 */ 5 */
@@ -19,7 +19,7 @@ namespace Swift {
19 virtual bool isAvailable() = 0; 19 virtual bool isAvailable() = 0;
20 20
21 virtual boost::optional<HostAddress> getPublicIP() = 0; 21 virtual boost::optional<HostAddress> getPublicIP() = 0;
22 virtual boost::optional<NATPortMapping> addPortForward(int localPort, int publicPort) = 0; 22 virtual boost::optional<NATPortMapping> addPortForward(unsigned short localPort, unsigned short publicPort) = 0;
23 virtual bool removePortForward(const NATPortMapping&) = 0; 23 virtual bool removePortForward(const NATPortMapping&) = 0;
24 }; 24 };
25} 25}
diff --git a/Swiften/Network/NATTraversalRemovePortForwardingRequest.h b/Swiften/Network/NATTraversalRemovePortForwardingRequest.h
index 3db9ee1..83235f9 100644
--- a/Swiften/Network/NATTraversalRemovePortForwardingRequest.h
+++ b/Swiften/Network/NATTraversalRemovePortForwardingRequest.h
@@ -5,7 +5,7 @@
5 */ 5 */
6 6
7/* 7/*
8 * Copyright (c) 2015-2016 Isode Limited. 8 * Copyright (c) 2015-2018 Isode Limited.
9 * All rights reserved. 9 * All rights reserved.
10 * See the COPYING file for more information. 10 * See the COPYING file for more information.
11 */ 11 */
@@ -26,8 +26,8 @@ namespace Swift {
26 UDP 26 UDP
27 }; 27 };
28 28
29 unsigned int publicPort; 29 unsigned short publicPort;
30 unsigned int localPort; 30 unsigned short localPort;
31 Protocol protocol; 31 Protocol protocol;
32 unsigned long leaseInSeconds; 32 unsigned long leaseInSeconds;
33 }; 33 };
diff --git a/Swiften/Network/NATTraverser.h b/Swiften/Network/NATTraverser.h
index 716bfcb..7f03c03 100644
--- a/Swiften/Network/NATTraverser.h
+++ b/Swiften/Network/NATTraverser.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2011-2016 Isode Limited. 2 * Copyright (c) 2011-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 */
@@ -20,7 +20,7 @@ namespace Swift {
20 virtual ~NATTraverser(); 20 virtual ~NATTraverser();
21 21
22 virtual std::shared_ptr<NATTraversalGetPublicIPRequest> createGetPublicIPRequest() = 0; 22 virtual std::shared_ptr<NATTraversalGetPublicIPRequest> createGetPublicIPRequest() = 0;
23 virtual std::shared_ptr<NATTraversalForwardPortRequest> createForwardPortRequest(int localPort, int publicPort) = 0; 23 virtual std::shared_ptr<NATTraversalForwardPortRequest> createForwardPortRequest(unsigned short localPort, unsigned short publicPort) = 0;
24 virtual std::shared_ptr<NATTraversalRemovePortForwardingRequest> createRemovePortForwardingRequest(int localPort, int publicPort) = 0; 24 virtual std::shared_ptr<NATTraversalRemovePortForwardingRequest> createRemovePortForwardingRequest(unsigned short localPort, unsigned short publicPort) = 0;
25 }; 25 };
26} 26}
diff --git a/Swiften/Network/NullNATTraversalInterface.h b/Swiften/Network/NullNATTraversalInterface.h
index ecbf110..eabc197 100644
--- a/Swiften/Network/NullNATTraversalInterface.h
+++ b/Swiften/Network/NullNATTraversalInterface.h
@@ -21,7 +21,7 @@ namespace Swift {
21 return boost::optional<HostAddress>(); 21 return boost::optional<HostAddress>();
22 } 22 }
23 23
24 virtual boost::optional<NATPortMapping> addPortForward(int, int) { 24 virtual boost::optional<NATPortMapping> addPortForward(unsigned short, unsigned short) {
25 return boost::optional<NATPortMapping>(); 25 return boost::optional<NATPortMapping>();
26 } 26 }
27 27
diff --git a/Swiften/Network/NullNATTraverser.cpp b/Swiften/Network/NullNATTraverser.cpp
index cc8bae0..0b9464e 100644
--- a/Swiften/Network/NullNATTraverser.cpp
+++ b/Swiften/Network/NullNATTraverser.cpp
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2011-2016 Isode Limited. 2 * Copyright (c) 2011-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 */
@@ -72,11 +72,11 @@ std::shared_ptr<NATTraversalGetPublicIPRequest> NullNATTraverser::createGetPubli
72 return std::make_shared<NullNATTraversalGetPublicIPRequest>(eventLoop); 72 return std::make_shared<NullNATTraversalGetPublicIPRequest>(eventLoop);
73} 73}
74 74
75std::shared_ptr<NATTraversalForwardPortRequest> NullNATTraverser::createForwardPortRequest(int, int) { 75std::shared_ptr<NATTraversalForwardPortRequest> NullNATTraverser::createForwardPortRequest(unsigned short, unsigned short) {
76 return std::make_shared<NullNATTraversalForwardPortRequest>(eventLoop); 76 return std::make_shared<NullNATTraversalForwardPortRequest>(eventLoop);
77} 77}
78 78
79std::shared_ptr<NATTraversalRemovePortForwardingRequest> NullNATTraverser::createRemovePortForwardingRequest(int, int) { 79std::shared_ptr<NATTraversalRemovePortForwardingRequest> NullNATTraverser::createRemovePortForwardingRequest(unsigned short, unsigned short) {
80 return std::make_shared<NullNATTraversalRemovePortForwardingRequest>(eventLoop); 80 return std::make_shared<NullNATTraversalRemovePortForwardingRequest>(eventLoop);
81} 81}
82 82
diff --git a/Swiften/Network/NullNATTraverser.h b/Swiften/Network/NullNATTraverser.h
index d3a6640..2f975bf 100644
--- a/Swiften/Network/NullNATTraverser.h
+++ b/Swiften/Network/NullNATTraverser.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2011-2016 Isode Limited. 2 * Copyright (c) 2011-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 */
@@ -16,8 +16,8 @@ namespace Swift {
16 NullNATTraverser(EventLoop* eventLoop); 16 NullNATTraverser(EventLoop* eventLoop);
17 17
18 std::shared_ptr<NATTraversalGetPublicIPRequest> createGetPublicIPRequest(); 18 std::shared_ptr<NATTraversalGetPublicIPRequest> createGetPublicIPRequest();
19 std::shared_ptr<NATTraversalForwardPortRequest> createForwardPortRequest(int localPort, int publicPort); 19 std::shared_ptr<NATTraversalForwardPortRequest> createForwardPortRequest(unsigned short localPort, unsigned short publicPort);
20 std::shared_ptr<NATTraversalRemovePortForwardingRequest> createRemovePortForwardingRequest(int localPort, int publicPort); 20 std::shared_ptr<NATTraversalRemovePortForwardingRequest> createRemovePortForwardingRequest(unsigned short localPort, unsigned short publicPort);
21 21
22 private: 22 private:
23 EventLoop* eventLoop; 23 EventLoop* eventLoop;
diff --git a/Swiften/Network/PlatformDomainNameServiceQuery.cpp b/Swiften/Network/PlatformDomainNameServiceQuery.cpp
index a5d180b..f884500 100644
--- a/Swiften/Network/PlatformDomainNameServiceQuery.cpp
+++ b/Swiften/Network/PlatformDomainNameServiceQuery.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 */
@@ -129,35 +129,42 @@ void PlatformDomainNameServiceQuery::runBlocking() {
129 currentEntry += entryLength; 129 currentEntry += entryLength;
130 currentEntry += NS_RRFIXEDSZ; 130 currentEntry += NS_RRFIXEDSZ;
131 131
132 // Priority 132 try {
133 if (currentEntry + 2 >= messageEnd) { 133 // Priority
134 emitError(); 134 if (currentEntry + 2 >= messageEnd) {
135 return; 135 emitError();
136 } 136 return;
137 record.priority = boost::numeric_cast<int>(ns_get16(currentEntry)); 137 }
138 currentEntry += 2; 138 record.priority = boost::numeric_cast<int>(ns_get16(currentEntry));
139 139 currentEntry += 2;
140 // Weight 140
141 if (currentEntry + 2 >= messageEnd) { 141 // Weight
142 emitError(); 142 if (currentEntry + 2 >= messageEnd) {
143 return; 143 emitError();
144 return;
145 }
146 record.weight = boost::numeric_cast<int>(ns_get16(currentEntry));
147 currentEntry += 2;
148
149 // Port
150 if (currentEntry + 2 >= messageEnd) {
151 emitError();
152 return;
153 }
154 record.port = boost::numeric_cast<unsigned short>(ns_get16(currentEntry));
155 currentEntry += 2;
156
157 // Hostname
158 if (currentEntry >= messageEnd) {
159 emitError();
160 return;
161 }
144 } 162 }
145 record.weight = boost::numeric_cast<int>(ns_get16(currentEntry)); 163 catch (const boost::numeric::bad_numeric_cast&) {
146 currentEntry += 2;
147
148 // Port
149 if (currentEntry + 2 >= messageEnd) {
150 emitError(); 164 emitError();
151 return; 165 return;
152 } 166 }
153 record.port = boost::numeric_cast<int>(ns_get16(currentEntry));
154 currentEntry += 2;
155 167
156 // Hostname
157 if (currentEntry >= messageEnd) {
158 emitError();
159 return;
160 }
161 ByteArray entry; 168 ByteArray entry;
162 entry.resize(NS_MAXDNAME); 169 entry.resize(NS_MAXDNAME);
163 entryLength = dn_expand(messageStart, messageEnd, currentEntry, reinterpret_cast<char*>(vecptr(entry)), entry.size()); 170 entryLength = dn_expand(messageStart, messageEnd, currentEntry, reinterpret_cast<char*>(vecptr(entry)), entry.size());
diff --git a/Swiften/Network/PlatformNATTraversalWorker.cpp b/Swiften/Network/PlatformNATTraversalWorker.cpp
index f56de0b..af12049 100644
--- a/Swiften/Network/PlatformNATTraversalWorker.cpp
+++ b/Swiften/Network/PlatformNATTraversalWorker.cpp
@@ -84,7 +84,7 @@ class PlatformNATTraversalGetPublicIPRequest : public NATTraversalGetPublicIPReq
84 84
85class PlatformNATTraversalForwardPortRequest : public NATTraversalForwardPortRequest, public PlatformNATTraversalRequest { 85class PlatformNATTraversalForwardPortRequest : public NATTraversalForwardPortRequest, public PlatformNATTraversalRequest {
86 public: 86 public:
87 PlatformNATTraversalForwardPortRequest(PlatformNATTraversalWorker* worker, unsigned int localIP, unsigned int publicIP) : PlatformNATTraversalRequest(worker), localIP(localIP), publicIP(publicIP) { 87 PlatformNATTraversalForwardPortRequest(PlatformNATTraversalWorker* worker, unsigned short localPort, unsigned short publicPort) : PlatformNATTraversalRequest(worker), localPort(localPort), publicPort(publicPort) {
88 } 88 }
89 89
90 virtual ~PlatformNATTraversalForwardPortRequest() { 90 virtual ~PlatformNATTraversalForwardPortRequest() {
@@ -99,12 +99,12 @@ class PlatformNATTraversalForwardPortRequest : public NATTraversalForwardPortReq
99 } 99 }
100 100
101 virtual void runBlocking() { 101 virtual void runBlocking() {
102 getEventLoop()->postEvent(boost::bind(boost::ref(onResult), getNATTraversalInterface()->addPortForward(boost::numeric_cast<int>(localIP), boost::numeric_cast<int>(publicIP))), shared_from_this()); 102 getEventLoop()->postEvent(boost::bind(boost::ref(onResult), getNATTraversalInterface()->addPortForward(localPort, publicPort)), shared_from_this());
103 } 103 }
104 104
105 private: 105 private:
106 unsigned int localIP; 106 unsigned short localPort;
107 unsigned int publicIP; 107 unsigned short publicPort;
108}; 108};
109 109
110class PlatformNATTraversalRemovePortForwardingRequest : public NATTraversalRemovePortForwardingRequest, public PlatformNATTraversalRequest { 110class PlatformNATTraversalRemovePortForwardingRequest : public NATTraversalRemovePortForwardingRequest, public PlatformNATTraversalRequest {
@@ -181,11 +181,11 @@ std::shared_ptr<NATTraversalGetPublicIPRequest> PlatformNATTraversalWorker::crea
181 return std::make_shared<PlatformNATTraversalGetPublicIPRequest>(this); 181 return std::make_shared<PlatformNATTraversalGetPublicIPRequest>(this);
182} 182}
183 183
184std::shared_ptr<NATTraversalForwardPortRequest> PlatformNATTraversalWorker::createForwardPortRequest(int localPort, int publicPort) { 184std::shared_ptr<NATTraversalForwardPortRequest> PlatformNATTraversalWorker::createForwardPortRequest(unsigned short localPort, unsigned short publicPort) {
185 return std::make_shared<PlatformNATTraversalForwardPortRequest>(this, localPort, publicPort); 185 return std::make_shared<PlatformNATTraversalForwardPortRequest>(this, localPort, publicPort);
186} 186}
187 187
188std::shared_ptr<NATTraversalRemovePortForwardingRequest> PlatformNATTraversalWorker::createRemovePortForwardingRequest(int localPort, int publicPort) { 188std::shared_ptr<NATTraversalRemovePortForwardingRequest> PlatformNATTraversalWorker::createRemovePortForwardingRequest(unsigned short localPort, unsigned short publicPort) {
189 NATPortMapping mapping(localPort, publicPort, NATPortMapping::TCP); // FIXME 189 NATPortMapping mapping(localPort, publicPort, NATPortMapping::TCP); // FIXME
190 return std::make_shared<PlatformNATTraversalRemovePortForwardingRequest>(this, mapping); 190 return std::make_shared<PlatformNATTraversalRemovePortForwardingRequest>(this, mapping);
191} 191}
diff --git a/Swiften/Network/PlatformNATTraversalWorker.h b/Swiften/Network/PlatformNATTraversalWorker.h
index aee1052..368798e 100644
--- a/Swiften/Network/PlatformNATTraversalWorker.h
+++ b/Swiften/Network/PlatformNATTraversalWorker.h
@@ -5,7 +5,7 @@
5 */ 5 */
6 6
7/* 7/*
8 * Copyright (c) 2016-2017 Isode Limited. 8 * Copyright (c) 2016-2018 Isode Limited.
9 * All rights reserved. 9 * All rights reserved.
10 * See the COPYING file for more information. 10 * See the COPYING file for more information.
11 */ 11 */
@@ -44,8 +44,8 @@ namespace Swift {
44 virtual ~PlatformNATTraversalWorker(); 44 virtual ~PlatformNATTraversalWorker();
45 45
46 std::shared_ptr<NATTraversalGetPublicIPRequest> createGetPublicIPRequest(); 46 std::shared_ptr<NATTraversalGetPublicIPRequest> createGetPublicIPRequest();
47 std::shared_ptr<NATTraversalForwardPortRequest> createForwardPortRequest(int localPort, int publicPort); 47 std::shared_ptr<NATTraversalForwardPortRequest> createForwardPortRequest(unsigned short localPort, unsigned short publicPort);
48 std::shared_ptr<NATTraversalRemovePortForwardingRequest> createRemovePortForwardingRequest(int localPort, int publicPort); 48 std::shared_ptr<NATTraversalRemovePortForwardingRequest> createRemovePortForwardingRequest(unsigned short localPort, unsigned short publicPort);
49 49
50 private: 50 private:
51 NATTraversalInterface* getNATTraversalInterface() const; 51 NATTraversalInterface* getNATTraversalInterface() const;
diff --git a/Swiften/Network/ProxiedConnection.cpp b/Swiften/Network/ProxiedConnection.cpp
index aa6c4d2..4c97e31 100644
--- a/Swiften/Network/ProxiedConnection.cpp
+++ b/Swiften/Network/ProxiedConnection.cpp
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2012-2016 Isode Limited. 2 * Copyright (c) 2012-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 */
@@ -20,7 +20,7 @@ ProxiedConnection::ProxiedConnection(
20 ConnectionFactory* connectionFactory, 20 ConnectionFactory* connectionFactory,
21 TimerFactory* timerFactory, 21 TimerFactory* timerFactory,
22 const std::string& proxyHost, 22 const std::string& proxyHost,
23 int proxyPort) : 23 unsigned short proxyPort) :
24 resolver_(resolver), 24 resolver_(resolver),
25 connectionFactory_(connectionFactory), 25 connectionFactory_(connectionFactory),
26 timerFactory_(timerFactory), 26 timerFactory_(timerFactory),
diff --git a/Swiften/Network/ProxiedConnection.h b/Swiften/Network/ProxiedConnection.h
index 440fb86..f79845a 100644
--- a/Swiften/Network/ProxiedConnection.h
+++ b/Swiften/Network/ProxiedConnection.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2012-2017 Isode Limited. 2 * Copyright (c) 2012-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 */
@@ -20,7 +20,7 @@ namespace Swift {
20 20
21 class SWIFTEN_API ProxiedConnection : public Connection, public std::enable_shared_from_this<ProxiedConnection> { 21 class SWIFTEN_API ProxiedConnection : public Connection, public std::enable_shared_from_this<ProxiedConnection> {
22 public: 22 public:
23 ProxiedConnection(DomainNameResolver* resolver, ConnectionFactory* connectionFactory, TimerFactory* timerFactory, const std::string& proxyHost, int proxyPort); 23 ProxiedConnection(DomainNameResolver* resolver, ConnectionFactory* connectionFactory, TimerFactory* timerFactory, const std::string& proxyHost, unsigned short proxyPort);
24 virtual ~ProxiedConnection(); 24 virtual ~ProxiedConnection();
25 25
26 virtual void listen(); 26 virtual void listen();
@@ -55,7 +55,7 @@ namespace Swift {
55 ConnectionFactory* connectionFactory_; 55 ConnectionFactory* connectionFactory_;
56 TimerFactory* timerFactory_; 56 TimerFactory* timerFactory_;
57 std::string proxyHost_; 57 std::string proxyHost_;
58 int proxyPort_; 58 unsigned short proxyPort_;
59 HostAddressPort server_; 59 HostAddressPort server_;
60 Connector::ref connector_; 60 Connector::ref connector_;
61 std::shared_ptr<Connection> connection_; 61 std::shared_ptr<Connection> connection_;
diff --git a/Swiften/Network/SOCKS5ProxiedConnection.cpp b/Swiften/Network/SOCKS5ProxiedConnection.cpp
index 2492827..d7036f2 100644
--- a/Swiften/Network/SOCKS5ProxiedConnection.cpp
+++ b/Swiften/Network/SOCKS5ProxiedConnection.cpp
@@ -5,7 +5,7 @@
5 */ 5 */
6 6
7/* 7/*
8 * Copyright (c) 2014-2016 Isode Limited. 8 * Copyright (c) 2014-2018 Isode Limited.
9 * All rights reserved. 9 * All rights reserved.
10 * See the COPYING file for more information. 10 * See the COPYING file for more information.
11 */ 11 */
@@ -27,7 +27,7 @@ SOCKS5ProxiedConnection::SOCKS5ProxiedConnection(
27 ConnectionFactory* connectionFactory, 27 ConnectionFactory* connectionFactory,
28 TimerFactory* timerFactory, 28 TimerFactory* timerFactory,
29 const std::string& proxyHost, 29 const std::string& proxyHost,
30 int proxyPort) : 30 unsigned short proxyPort) :
31 ProxiedConnection(resolver, connectionFactory, timerFactory, proxyHost, proxyPort), 31 ProxiedConnection(resolver, connectionFactory, timerFactory, proxyHost, proxyPort),
32 proxyState_(Initial) { 32 proxyState_(Initial) {
33 } 33 }
diff --git a/Swiften/Network/SOCKS5ProxiedConnection.h b/Swiften/Network/SOCKS5ProxiedConnection.h
index c8faae9..515c5b7 100644
--- a/Swiften/Network/SOCKS5ProxiedConnection.h
+++ b/Swiften/Network/SOCKS5ProxiedConnection.h
@@ -5,7 +5,7 @@
5 */ 5 */
6 6
7/* 7/*
8 * Copyright (c) 2015-2016 Isode Limited. 8 * Copyright (c) 2015-2018 Isode Limited.
9 * All rights reserved. 9 * All rights reserved.
10 * See the COPYING file for more information. 10 * See the COPYING file for more information.
11 */ 11 */
@@ -24,12 +24,12 @@ namespace Swift {
24 public: 24 public:
25 typedef std::shared_ptr<SOCKS5ProxiedConnection> ref; 25 typedef std::shared_ptr<SOCKS5ProxiedConnection> ref;
26 26
27 static ref create(DomainNameResolver* resolver, ConnectionFactory* connectionFactory, TimerFactory* timerFactory, const std::string& proxyHost, int proxyPort) { 27 static ref create(DomainNameResolver* resolver, ConnectionFactory* connectionFactory, TimerFactory* timerFactory, const std::string& proxyHost, unsigned short proxyPort) {
28 return ref(new SOCKS5ProxiedConnection(resolver, connectionFactory, timerFactory, proxyHost, proxyPort)); 28 return ref(new SOCKS5ProxiedConnection(resolver, connectionFactory, timerFactory, proxyHost, proxyPort));
29 } 29 }
30 30
31 private: 31 private:
32 SOCKS5ProxiedConnection(DomainNameResolver* resolver, ConnectionFactory* connectionFactory, TimerFactory* timerFactory, const std::string& proxyHost, int proxyPort); 32 SOCKS5ProxiedConnection(DomainNameResolver* resolver, ConnectionFactory* connectionFactory, TimerFactory* timerFactory, const std::string& proxyHost, unsigned short proxyPort);
33 33
34 virtual void initializeProxy(); 34 virtual void initializeProxy();
35 virtual void handleProxyInitializeData(std::shared_ptr<SafeByteArray> data); 35 virtual void handleProxyInitializeData(std::shared_ptr<SafeByteArray> data);
diff --git a/Swiften/Network/SOCKS5ProxiedConnectionFactory.cpp b/Swiften/Network/SOCKS5ProxiedConnectionFactory.cpp
index 01ce8ac..abd7718 100644
--- a/Swiften/Network/SOCKS5ProxiedConnectionFactory.cpp
+++ b/Swiften/Network/SOCKS5ProxiedConnectionFactory.cpp
@@ -16,7 +16,7 @@
16 16
17namespace Swift { 17namespace Swift {
18 18
19SOCKS5ProxiedConnectionFactory::SOCKS5ProxiedConnectionFactory(DomainNameResolver* resolver, ConnectionFactory* connectionFactory, TimerFactory* timerFactory, const std::string& proxyHost, int proxyPort) : resolver_(resolver), connectionFactory_(connectionFactory), timerFactory_(timerFactory), proxyHost_(proxyHost), proxyPort_(proxyPort) { 19SOCKS5ProxiedConnectionFactory::SOCKS5ProxiedConnectionFactory(DomainNameResolver* resolver, ConnectionFactory* connectionFactory, TimerFactory* timerFactory, const std::string& proxyHost, unsigned short proxyPort) : resolver_(resolver), connectionFactory_(connectionFactory), timerFactory_(timerFactory), proxyHost_(proxyHost), proxyPort_(proxyPort) {
20} 20}
21 21
22std::shared_ptr<Connection> SOCKS5ProxiedConnectionFactory::createConnection() { 22std::shared_ptr<Connection> SOCKS5ProxiedConnectionFactory::createConnection() {
diff --git a/Swiften/Network/SOCKS5ProxiedConnectionFactory.h b/Swiften/Network/SOCKS5ProxiedConnectionFactory.h
index 8631239..47ae9a3 100644
--- a/Swiften/Network/SOCKS5ProxiedConnectionFactory.h
+++ b/Swiften/Network/SOCKS5ProxiedConnectionFactory.h
@@ -5,7 +5,7 @@
5 */ 5 */
6 6
7/* 7/*
8 * Copyright (c) 2015-2016 Isode Limited. 8 * Copyright (c) 2015-2018 Isode Limited.
9 * All rights reserved. 9 * All rights reserved.
10 * See the COPYING file for more information. 10 * See the COPYING file for more information.
11 */ 11 */
@@ -23,7 +23,7 @@ namespace Swift {
23 23
24 class SWIFTEN_API SOCKS5ProxiedConnectionFactory : public ConnectionFactory { 24 class SWIFTEN_API SOCKS5ProxiedConnectionFactory : public ConnectionFactory {
25 public: 25 public:
26 SOCKS5ProxiedConnectionFactory(DomainNameResolver* resolver, ConnectionFactory* connectionFactory, TimerFactory* timerFactory, const std::string& proxyHost, int proxyPort); 26 SOCKS5ProxiedConnectionFactory(DomainNameResolver* resolver, ConnectionFactory* connectionFactory, TimerFactory* timerFactory, const std::string& proxyHost, unsigned short proxyPort);
27 27
28 virtual std::shared_ptr<Connection> createConnection(); 28 virtual std::shared_ptr<Connection> createConnection();
29 29
@@ -32,6 +32,6 @@ namespace Swift {
32 ConnectionFactory* connectionFactory_; 32 ConnectionFactory* connectionFactory_;
33 TimerFactory* timerFactory_; 33 TimerFactory* timerFactory_;
34 std::string proxyHost_; 34 std::string proxyHost_;
35 int proxyPort_; 35 unsigned short proxyPort_;
36 }; 36 };
37} 37}
diff --git a/Swiften/Network/StaticDomainNameResolver.cpp b/Swiften/Network/StaticDomainNameResolver.cpp
index 5a38fc4..eca6687 100644
--- a/Swiften/Network/StaticDomainNameResolver.cpp
+++ b/Swiften/Network/StaticDomainNameResolver.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 */
@@ -109,7 +109,7 @@ void StaticDomainNameResolver::addXMPPClientService(const std::string& domain, c
109 addAddress(hostname, address.getAddress()); 109 addAddress(hostname, address.getAddress());
110} 110}
111 111
112void StaticDomainNameResolver::addXMPPClientService(const std::string& domain, const std::string& hostname, int port) { 112void StaticDomainNameResolver::addXMPPClientService(const std::string& domain, const std::string& hostname, unsigned short port) {
113 addService("_xmpp-client._tcp." + domain, ServiceQuery::Result(hostname, port, 0, 0)); 113 addService("_xmpp-client._tcp." + domain, ServiceQuery::Result(hostname, port, 0, 0));
114} 114}
115 115
diff --git a/Swiften/Network/StaticDomainNameResolver.h b/Swiften/Network/StaticDomainNameResolver.h
index 76394d0..2064046 100644
--- a/Swiften/Network/StaticDomainNameResolver.h
+++ b/Swiften/Network/StaticDomainNameResolver.h
@@ -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 */
@@ -31,7 +31,7 @@ namespace Swift {
31 void addAddress(const std::string& domain, const HostAddress& address); 31 void addAddress(const std::string& domain, const HostAddress& address);
32 void addService(const std::string& service, const DomainNameServiceQuery::Result& result); 32 void addService(const std::string& service, const DomainNameServiceQuery::Result& result);
33 void addXMPPClientService(const std::string& domain, const HostAddressPort&); 33 void addXMPPClientService(const std::string& domain, const HostAddressPort&);
34 void addXMPPClientService(const std::string& domain, const std::string& host, int port); 34 void addXMPPClientService(const std::string& domain, const std::string& host, unsigned short port);
35 35
36 const AddressesMap& getAddresses() const { 36 const AddressesMap& getAddresses() const {
37 return addresses; 37 return addresses;
diff --git a/Swiften/Network/UnitTest/ConnectorTest.cpp b/Swiften/Network/UnitTest/ConnectorTest.cpp
index 658aaf7..065911d 100644
--- a/Swiften/Network/UnitTest/ConnectorTest.cpp
+++ b/Swiften/Network/UnitTest/ConnectorTest.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 */
@@ -92,7 +92,7 @@ class ConnectorTest : public CppUnit::TestFixture {
92 } 92 }
93 93
94 void testConnect_NoServiceLookups_DefaultPort() { 94 void testConnect_NoServiceLookups_DefaultPort() {
95 Connector::ref testling(createConnector(-1, boost::optional<std::string>())); 95 Connector::ref testling(createConnector(0, boost::optional<std::string>()));
96 resolver->addXMPPClientService("foo.com", host1); 96 resolver->addXMPPClientService("foo.com", host1);
97 resolver->addXMPPClientService("foo.com", host2); 97 resolver->addXMPPClientService("foo.com", host2);
98 resolver->addAddress("foo.com", host3.getAddress()); 98 resolver->addAddress("foo.com", host3.getAddress());
@@ -103,7 +103,7 @@ class ConnectorTest : public CppUnit::TestFixture {
103 CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(connections.size())); 103 CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(connections.size()));
104 CPPUNIT_ASSERT(connections[0]); 104 CPPUNIT_ASSERT(connections[0]);
105 CPPUNIT_ASSERT(host3.getAddress() == (*(connections[0]->hostAddressPort)).getAddress()); 105 CPPUNIT_ASSERT(host3.getAddress() == (*(connections[0]->hostAddressPort)).getAddress());
106 CPPUNIT_ASSERT_EQUAL(5222, (*(connections[0]->hostAddressPort)).getPort()); 106 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(5222), (*(connections[0]->hostAddressPort)).getPort());
107 CPPUNIT_ASSERT(!std::dynamic_pointer_cast<DomainNameResolveError>(error)); 107 CPPUNIT_ASSERT(!std::dynamic_pointer_cast<DomainNameResolveError>(error));
108 } 108 }
109 109
@@ -328,7 +328,7 @@ class ConnectorTest : public CppUnit::TestFixture {
328 328
329 329
330 private: 330 private:
331 Connector::ref createConnector(int port = -1, boost::optional<std::string> serviceLookupPrefix = boost::optional<std::string>("_xmpp-client._tcp.")) { 331 Connector::ref createConnector(unsigned short port = 0, boost::optional<std::string> serviceLookupPrefix = boost::optional<std::string>("_xmpp-client._tcp.")) {
332 Connector::ref connector = Connector::create("foo.com", port, serviceLookupPrefix, resolver, connectionFactory, timerFactory); 332 Connector::ref connector = Connector::create("foo.com", port, serviceLookupPrefix, resolver, connectionFactory, timerFactory);
333 connector->onConnectFinished.connect(boost::bind(&ConnectorTest::handleConnectorFinished, this, _1, _2)); 333 connector->onConnectFinished.connect(boost::bind(&ConnectorTest::handleConnectorFinished, this, _1, _2));
334 return connector; 334 return connector;
diff --git a/Swiften/Network/UnitTest/HTTPConnectProxiedConnectionTest.cpp b/Swiften/Network/UnitTest/HTTPConnectProxiedConnectionTest.cpp
index 1a160b7..065d015 100644
--- a/Swiften/Network/UnitTest/HTTPConnectProxiedConnectionTest.cpp
+++ b/Swiften/Network/UnitTest/HTTPConnectProxiedConnectionTest.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 */
@@ -421,7 +421,7 @@ class HTTPConnectProxiedConnectionTest : public CppUnit::TestFixture {
421 private: 421 private:
422 std::string proxyHost; 422 std::string proxyHost;
423 HostAddressPort proxyHostAddress; 423 HostAddressPort proxyHostAddress;
424 int proxyPort; 424 unsigned short proxyPort;
425 HostAddressPort host; 425 HostAddressPort host;
426 DummyEventLoop* eventLoop; 426 DummyEventLoop* eventLoop;
427 StaticDomainNameResolver* resolver; 427 StaticDomainNameResolver* resolver;
diff --git a/Swiften/Network/WindowsProxyProvider.cpp b/Swiften/Network/WindowsProxyProvider.cpp
index 78bd72f..9a60bb4 100644
--- a/Swiften/Network/WindowsProxyProvider.cpp
+++ b/Swiften/Network/WindowsProxyProvider.cpp
@@ -17,6 +17,7 @@
17#include <stdlib.h> 17#include <stdlib.h>
18 18
19#include <boost/lexical_cast.hpp> 19#include <boost/lexical_cast.hpp>
20#include <boost/numeric/conversion/cast.hpp>
20 21
21#include <windows.h> 22#include <windows.h>
22 23
@@ -77,11 +78,11 @@ HostAddressPort WindowsProxyProvider::getAsHostAddressPort(std::string proxy) {
77 78
78 try { 79 try {
79 std::pair<std::string, std::string> tmp; 80 std::pair<std::string, std::string> tmp;
80 int port = 0; 81 unsigned short port = 0;
81 tmp = String::getSplittedAtFirst(proxy, ':'); 82 tmp = String::getSplittedAtFirst(proxy, ':');
82 // .c_str() is needed as tmp.second can include a \0 char which will end in an exception of the lexical cast. 83 // .c_str() is needed as tmp.second can include a \0 char which will end in an exception of the lexical cast.
83 // with .c_str() the \0 will not be part of the string which is to be casted 84 // with .c_str() the \0 will not be part of the string which is to be casted
84 port = boost::lexical_cast<int> (tmp.second.c_str()); 85 port = boost::numeric_cast<unsigned short>(boost::lexical_cast<int> (tmp.second.c_str()));
85 ret = HostAddressPort(HostAddress::fromString(tmp.first).get(), port); 86 ret = HostAddressPort(HostAddress::fromString(tmp.first).get(), port);
86 } 87 }
87 catch(...) { 88 catch(...) {
diff --git a/Swiften/Parser/PayloadParsers/BytestreamsParser.cpp b/Swiften/Parser/PayloadParsers/BytestreamsParser.cpp
index 405c593..71bce54 100644
--- a/Swiften/Parser/PayloadParsers/BytestreamsParser.cpp
+++ b/Swiften/Parser/PayloadParsers/BytestreamsParser.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 */
@@ -7,6 +7,7 @@
7#include <Swiften/Parser/PayloadParsers/BytestreamsParser.h> 7#include <Swiften/Parser/PayloadParsers/BytestreamsParser.h>
8 8
9#include <boost/lexical_cast.hpp> 9#include <boost/lexical_cast.hpp>
10#include <boost/numeric/conversion/cast.hpp>
10 11
11namespace Swift { 12namespace Swift {
12 13
@@ -23,7 +24,9 @@ void BytestreamsParser::handleStartElement(const std::string& element, const std
23 else if (level == PayloadLevel) { 24 else if (level == PayloadLevel) {
24 if (element == "streamhost") { 25 if (element == "streamhost") {
25 try { 26 try {
26 getPayloadInternal()->addStreamHost(Bytestreams::StreamHost(attributes.getAttribute("host"), JID(attributes.getAttribute("jid")), boost::lexical_cast<int>(attributes.getAttribute("port")))); 27 getPayloadInternal()->addStreamHost(Bytestreams::StreamHost(attributes.getAttribute("host"), JID(attributes.getAttribute("jid")), boost::numeric_cast<unsigned short>(boost::lexical_cast<int>(attributes.getAttribute("port")))));
28 }
29 catch (boost::numeric::bad_numeric_cast&) {
27 } 30 }
28 catch (boost::bad_lexical_cast&) { 31 catch (boost::bad_lexical_cast&) {
29 } 32 }
diff --git a/Swiften/Parser/PayloadParsers/JingleS5BTransportMethodPayloadParser.cpp b/Swiften/Parser/PayloadParsers/JingleS5BTransportMethodPayloadParser.cpp
index e639e20..a405e0e 100644
--- a/Swiften/Parser/PayloadParsers/JingleS5BTransportMethodPayloadParser.cpp
+++ b/Swiften/Parser/PayloadParsers/JingleS5BTransportMethodPayloadParser.cpp
@@ -5,7 +5,7 @@
5 */ 5 */
6 6
7/* 7/*
8 * Copyright (c) 2014-2016 Isode Limited. 8 * Copyright (c) 2014-2018 Isode Limited.
9 * All rights reserved. 9 * All rights reserved.
10 * See the COPYING file for more information. 10 * See the COPYING file for more information.
11 */ 11 */
@@ -13,6 +13,7 @@
13#include <Swiften/Parser/PayloadParsers/JingleS5BTransportMethodPayloadParser.h> 13#include <Swiften/Parser/PayloadParsers/JingleS5BTransportMethodPayloadParser.h>
14 14
15#include <boost/lexical_cast.hpp> 15#include <boost/lexical_cast.hpp>
16#include <boost/numeric/conversion/cast.hpp>
16#include <boost/optional.hpp> 17#include <boost/optional.hpp>
17 18
18#include <Swiften/Base/Log.h> 19#include <Swiften/Base/Log.h>
@@ -40,10 +41,10 @@ namespace Swift {
40 JingleS5BTransportPayload::Candidate candidate; 41 JingleS5BTransportPayload::Candidate candidate;
41 candidate.cid = attributes.getAttributeValue("cid").get_value_or(""); 42 candidate.cid = attributes.getAttributeValue("cid").get_value_or("");
42 43
43 int port = -1; 44 unsigned short port = 0;
44 try { 45 try {
45 port = boost::lexical_cast<int>(attributes.getAttributeValue("port").get_value_or("-1")); 46 port = boost::numeric_cast<unsigned short>(boost::lexical_cast<int>(attributes.getAttributeValue("port").get_value_or("0")));
46 } catch(boost::bad_lexical_cast &) { } 47 } catch(...) { }
47 candidate.hostPort = HostAddressPort(HostAddress::fromString(attributes.getAttributeValue("host").get_value_or("")).get_value_or(HostAddress()), port); 48 candidate.hostPort = HostAddressPort(HostAddress::fromString(attributes.getAttributeValue("host").get_value_or("")).get_value_or(HostAddress()), port);
48 candidate.jid = JID(attributes.getAttributeValue("jid").get_value_or("")); 49 candidate.jid = JID(attributes.getAttributeValue("jid").get_value_or(""));
49 int priority = -1; 50 int priority = -1;
diff --git a/Swiften/Parser/PayloadParsers/S5BProxyRequestParser.cpp b/Swiften/Parser/PayloadParsers/S5BProxyRequestParser.cpp
index 502f400..7a5a1fd 100644
--- a/Swiften/Parser/PayloadParsers/S5BProxyRequestParser.cpp
+++ b/Swiften/Parser/PayloadParsers/S5BProxyRequestParser.cpp
@@ -5,7 +5,7 @@
5 */ 5 */
6 6
7/* 7/*
8 * Copyright (c) 2015-2016 Isode Limited. 8 * Copyright (c) 2015-2018 Isode Limited.
9 * All rights reserved. 9 * All rights reserved.
10 * See the COPYING file for more information. 10 * See the COPYING file for more information.
11 */ 11 */
@@ -13,6 +13,7 @@
13#include <Swiften/Parser/PayloadParsers/S5BProxyRequestParser.h> 13#include <Swiften/Parser/PayloadParsers/S5BProxyRequestParser.h>
14 14
15#include <boost/lexical_cast.hpp> 15#include <boost/lexical_cast.hpp>
16#include <boost/numeric/conversion/cast.hpp>
16#include <boost/optional.hpp> 17#include <boost/optional.hpp>
17 18
18namespace Swift { 19namespace Swift {
@@ -27,15 +28,14 @@ void S5BProxyRequestParser::handleStartElement(const std::string& element, const
27 if (element == "streamhost") { 28 if (element == "streamhost") {
28 if (attributes.getAttributeValue("host") && attributes.getAttributeValue("jid") && attributes.getAttributeValue("port")) { 29 if (attributes.getAttributeValue("host") && attributes.getAttributeValue("jid") && attributes.getAttributeValue("port")) {
29 std::string host = attributes.getAttributeValue("host").get_value_or(""); 30 std::string host = attributes.getAttributeValue("host").get_value_or("");
30 int port = -1; 31 unsigned short port = 0;
31 JID jid = attributes.getAttributeValue("jid").get_value_or(""); 32 JID jid = attributes.getAttributeValue("jid").get_value_or("");
32 33
33 try { 34 try {
34 port = boost::lexical_cast<int>(attributes.getAttributeValue("port").get()); 35 port = boost::numeric_cast<unsigned short>(boost::lexical_cast<int>(attributes.getAttributeValue("port").get()));
35 } catch (boost::bad_lexical_cast &) { 36 } catch (...) {
36 port = -1;
37 } 37 }
38 if (!host.empty() && port != -1 && jid.isValid()) { 38 if (!host.empty() && port != 0 && jid.isValid()) {
39 S5BProxyRequest::StreamHost streamHost; 39 S5BProxyRequest::StreamHost streamHost;
40 streamHost.host = host; 40 streamHost.host = host;
41 streamHost.port = port; 41 streamHost.port = port;
diff --git a/Swiften/QA/ClientTest/ClientTest.cpp b/Swiften/QA/ClientTest/ClientTest.cpp
index 5cb1765..c5117fa 100644
--- a/Swiften/QA/ClientTest/ClientTest.cpp
+++ b/Swiften/QA/ClientTest/ClientTest.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 */
@@ -8,6 +8,7 @@
8#include <thread> 8#include <thread>
9 9
10#include <boost/bind.hpp> 10#include <boost/bind.hpp>
11#include <boost/numeric/conversion/cast.hpp>
11 12
12#include <Swiften/Client/Client.h> 13#include <Swiften/Client/Client.h>
13#include <Swiften/Client/ClientXMLTracer.h> 14#include <Swiften/Client/ClientXMLTracer.h>
@@ -74,7 +75,17 @@ int main(int, char**) {
74 75
75 if (boshHost && boshPort && boshPath) { 76 if (boshHost && boshPort && boshPath) {
76 std::cout << "Using BOSH with URL: http://" << boshHost << ":" << boshPort << boshPath << std::endl; 77 std::cout << "Using BOSH with URL: http://" << boshHost << ":" << boshPort << boshPath << std::endl;
77 options.boshURL = URL("http", boshHost, atoi(boshPort), boshPath); 78 try {
79 options.boshURL = URL("http", boshHost, boost::numeric_cast<unsigned short>(boost::lexical_cast<int>(boshPort)), boshPath);
80 }
81 catch (const boost::numeric::bad_numeric_cast& e) {
82 std::cerr << "SWIFT_CLIENTTEST_BOSH_PORT doesn't hold a valid port number: " << e.what() << std::endl;
83 return -1;
84 }
85 catch (const boost::bad_lexical_cast& e) {
86 std::cerr << "SWIFT_CLIENTTEST_BOSH_PORT doesn't hold a valid port number: " << e.what() << std::endl;
87 return -1;
88 }
78 } 89 }
79 90
80 client = new Swift::Client(JID(jid), std::string(pass), &networkFactories); 91 client = new Swift::Client(JID(jid), std::string(pass), &networkFactories);
diff --git a/Swiften/QA/NetworkTest/DomainNameResolverTest.cpp b/Swiften/QA/NetworkTest/DomainNameResolverTest.cpp
index 95ebb6d..69e6fe8 100644
--- a/Swiften/QA/NetworkTest/DomainNameResolverTest.cpp
+++ b/Swiften/QA/NetworkTest/DomainNameResolverTest.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 */
@@ -179,19 +179,19 @@ class DomainNameResolverTest : public CppUnit::TestFixture {
179 179
180 CPPUNIT_ASSERT_EQUAL(4, static_cast<int>(serviceQueryResult.size())); 180 CPPUNIT_ASSERT_EQUAL(4, static_cast<int>(serviceQueryResult.size()));
181 CPPUNIT_ASSERT_EQUAL(std::string("xmpp1.test.swift.im"), serviceQueryResult[0].hostname); 181 CPPUNIT_ASSERT_EQUAL(std::string("xmpp1.test.swift.im"), serviceQueryResult[0].hostname);
182 CPPUNIT_ASSERT_EQUAL(5000, serviceQueryResult[0].port); 182 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(5000), serviceQueryResult[0].port);
183 CPPUNIT_ASSERT_EQUAL(0, serviceQueryResult[0].priority); 183 CPPUNIT_ASSERT_EQUAL(0, serviceQueryResult[0].priority);
184 CPPUNIT_ASSERT_EQUAL(1, serviceQueryResult[0].weight); 184 CPPUNIT_ASSERT_EQUAL(1, serviceQueryResult[0].weight);
185 CPPUNIT_ASSERT_EQUAL(std::string("xmpp-invalid.test.swift.im"), serviceQueryResult[1].hostname); 185 CPPUNIT_ASSERT_EQUAL(std::string("xmpp-invalid.test.swift.im"), serviceQueryResult[1].hostname);
186 CPPUNIT_ASSERT_EQUAL(5000, serviceQueryResult[1].port); 186 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(5000), serviceQueryResult[1].port);
187 CPPUNIT_ASSERT_EQUAL(1, serviceQueryResult[1].priority); 187 CPPUNIT_ASSERT_EQUAL(1, serviceQueryResult[1].priority);
188 CPPUNIT_ASSERT_EQUAL(100, serviceQueryResult[1].weight); 188 CPPUNIT_ASSERT_EQUAL(100, serviceQueryResult[1].weight);
189 CPPUNIT_ASSERT_EQUAL(std::string("xmpp3.test.swift.im"), serviceQueryResult[2].hostname); 189 CPPUNIT_ASSERT_EQUAL(std::string("xmpp3.test.swift.im"), serviceQueryResult[2].hostname);
190 CPPUNIT_ASSERT_EQUAL(5000, serviceQueryResult[2].port); 190 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(5000), serviceQueryResult[2].port);
191 CPPUNIT_ASSERT_EQUAL(3, serviceQueryResult[2].priority); 191 CPPUNIT_ASSERT_EQUAL(3, serviceQueryResult[2].priority);
192 CPPUNIT_ASSERT_EQUAL(100, serviceQueryResult[2].weight); 192 CPPUNIT_ASSERT_EQUAL(100, serviceQueryResult[2].weight);
193 CPPUNIT_ASSERT_EQUAL(std::string("xmpp2.test.swift.im"), serviceQueryResult[3].hostname); 193 CPPUNIT_ASSERT_EQUAL(std::string("xmpp2.test.swift.im"), serviceQueryResult[3].hostname);
194 CPPUNIT_ASSERT_EQUAL(5000, serviceQueryResult[3].port); 194 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(5000), serviceQueryResult[3].port);
195 CPPUNIT_ASSERT_EQUAL(5, serviceQueryResult[3].priority); 195 CPPUNIT_ASSERT_EQUAL(5, serviceQueryResult[3].priority);
196 CPPUNIT_ASSERT_EQUAL(100, serviceQueryResult[3].weight); 196 CPPUNIT_ASSERT_EQUAL(100, serviceQueryResult[3].weight);
197 } 197 }