diff options
Diffstat (limited to 'Swiften/Network')
47 files changed, 192 insertions, 165 deletions
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 | ||
| 20 | namespace Swift { | 20 | namespace Swift { |
| 21 | 21 | ||
| 22 | BoostConnectionServer::BoostConnectionServer(int port, std::shared_ptr<boost::asio::io_service> ioService, EventLoop* eventLoop) : port_(port), ioService_(ioService), eventLoop(eventLoop), acceptor_(nullptr) { | 22 | BoostConnectionServer::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 | ||
| 25 | BoostConnectionServer::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) { | 25 | BoostConnectionServer::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 | ||
| 28 | void BoostConnectionServer::start() { | 28 | void 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 { | |||
| 19 | BoostConnectionServerFactory::BoostConnectionServerFactory(std::shared_ptr<boost::asio::io_service> ioService, EventLoop* eventLoop) : ioService(ioService), eventLoop(eventLoop) { | 19 | BoostConnectionServerFactory::BoostConnectionServerFactory(std::shared_ptr<boost::asio::io_service> ioService, EventLoop* eventLoop) : ioService(ioService), eventLoop(eventLoop) { |
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | std::shared_ptr<ConnectionServer> BoostConnectionServerFactory::createConnectionServer(int port) { | 22 | std::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 | ||
| 26 | std::shared_ptr<ConnectionServer> BoostConnectionServerFactory::createConnectionServer(const Swift::HostAddress &hostAddress, int port) { | 26 | std::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 | ||
| 19 | ChainedConnector::ChainedConnector( | 19 | ChainedConnector::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 | ||
| 18 | namespace Swift { | 18 | namespace Swift { |
| 19 | 19 | ||
| 20 | Connector::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) { | 20 | Connector::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 | ||
| 23 | void Connector::setTimeoutMilliseconds(int milliseconds) { | 23 | void 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 @@ | |||
| 17 | namespace Swift { | 17 | namespace 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 | ||
| 22 | namespace Swift { | 24 | namespace Swift { |
| @@ -38,7 +40,7 @@ HostAddressPort EnvironmentProxyProvider::getSOCKS5Proxy() const { | |||
| 38 | HostAddressPort EnvironmentProxyProvider::getFromEnv(const char* envVarName, std::string proxyProtocol) { | 40 | HostAddressPort 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 | ||
| 26 | namespace Swift { | 28 | namespace Swift { |
| @@ -50,13 +52,17 @@ HostAddressPort GConfProxyProvider::getSOCKS5Proxy() const { | |||
| 50 | 52 | ||
| 51 | HostAddressPort GConfProxyProvider::getFromGConf(const char* gcHost, const char* gcPort) { | 53 | HostAddressPort 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 | ||
| 17 | namespace Swift { | 17 | namespace Swift { |
| 18 | 18 | ||
| 19 | HTTPConnectProxiedConnectionFactory::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) { | 19 | HTTPConnectProxiedConnectionFactory::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 | ||
| 23 | HTTPConnectProxiedConnectionFactory::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) { | 23 | HTTPConnectProxiedConnectionFactory::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 | ||
| 26 | std::shared_ptr<Connection> HTTPConnectProxiedConnectionFactory::createConnection() { | 26 | std::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 | ||
| 11 | using namespace Swift; | 11 | using namespace Swift; |
| 12 | 12 | ||
| 13 | HostAddressPort::HostAddressPort(const HostAddress& address, int port) : address_(address), port_(port) { | 13 | HostAddressPort::HostAddressPort(const HostAddress& address, unsigned short port) : address_(address), port_(port) { |
| 14 | } | 14 | } |
| 15 | 15 | ||
| 16 | HostAddressPort::HostAddressPort(const boost::asio::ip::tcp::endpoint& endpoint) { | 16 | HostAddressPort::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 @@ | |||
| 14 | namespace Swift { | 14 | namespace 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 | ||
| 76 | boost::optional<NATPortMapping> MiniUPnPInterface::addPortForward(int actualLocalPort, int actualPublicPort) { | 76 | boost::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 | ||
| 77 | boost::optional<NATPortMapping> NATPMPInterface::addPortForward(int localPort, int publicPort) { | 77 | boost::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 | ||
| 75 | std::shared_ptr<NATTraversalForwardPortRequest> NullNATTraverser::createForwardPortRequest(int, int) { | 75 | std::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 | ||
| 79 | std::shared_ptr<NATTraversalRemovePortForwardingRequest> NullNATTraverser::createRemovePortForwardingRequest(int, int) { | 79 | std::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 | ||
| 85 | class PlatformNATTraversalForwardPortRequest : public NATTraversalForwardPortRequest, public PlatformNATTraversalRequest { | 85 | class 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 | ||
| 110 | class PlatformNATTraversalRemovePortForwardingRequest : public NATTraversalRemovePortForwardingRequest, public PlatformNATTraversalRequest { | 110 | class 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 | ||
| 184 | std::shared_ptr<NATTraversalForwardPortRequest> PlatformNATTraversalWorker::createForwardPortRequest(int localPort, int publicPort) { | 184 | std::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 | ||
| 188 | std::shared_ptr<NATTraversalRemovePortForwardingRequest> PlatformNATTraversalWorker::createRemovePortForwardingRequest(int localPort, int publicPort) { | 188 | std::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 | ||
| 17 | namespace Swift { | 17 | namespace Swift { |
| 18 | 18 | ||
| 19 | SOCKS5ProxiedConnectionFactory::SOCKS5ProxiedConnectionFactory(DomainNameResolver* resolver, ConnectionFactory* connectionFactory, TimerFactory* timerFactory, const std::string& proxyHost, int proxyPort) : resolver_(resolver), connectionFactory_(connectionFactory), timerFactory_(timerFactory), proxyHost_(proxyHost), proxyPort_(proxyPort) { | 19 | SOCKS5ProxiedConnectionFactory::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 | ||
| 22 | std::shared_ptr<Connection> SOCKS5ProxiedConnectionFactory::createConnection() { | 22 | std::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 | ||
| 112 | void StaticDomainNameResolver::addXMPPClientService(const std::string& domain, const std::string& hostname, int port) { | 112 | void 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(...) { |
Swift