diff options
Diffstat (limited to 'Swiften/Client')
| -rw-r--r-- | Swiften/Client/ClientXMLTracer.cpp | 4 | ||||
| -rw-r--r-- | Swiften/Client/CoreClient.cpp | 40 | ||||
| -rw-r--r-- | Swiften/Client/DummyStanzaChannel.h | 7 | ||||
| -rw-r--r-- | Swiften/Client/UnitTest/XMLBeautifierTest.cpp | 13 |
4 files changed, 52 insertions, 12 deletions
diff --git a/Swiften/Client/ClientXMLTracer.cpp b/Swiften/Client/ClientXMLTracer.cpp index e205f41..e1b9e0c 100644 --- a/Swiften/Client/ClientXMLTracer.cpp +++ b/Swiften/Client/ClientXMLTracer.cpp @@ -14,13 +14,13 @@ namespace Swift { ClientXMLTracer::ClientXMLTracer(CoreClient* client, bool bosh) : bosh_(bosh) { #ifdef SWIFTEN_PLATFORM_WIN32 - beautifier_ = std::unique_ptr<XMLBeautifier>(new XMLBeautifier(true, false)); + beautifier_ = std::make_unique<XMLBeautifier>(true, false); #else - beautifier_ = std::unique_ptr<XMLBeautifier>(new XMLBeautifier(true, true)); + beautifier_ = std::make_unique<XMLBeautifier>(true, true); #endif onDataReadConnection_ = client->onDataRead.connect(boost::bind(&ClientXMLTracer::printData, this, '<', _1)); onDataWrittenConnection_ = client->onDataWritten.connect(boost::bind(&ClientXMLTracer::printData, this, '>', _1)); } diff --git a/Swiften/Client/CoreClient.cpp b/Swiften/Client/CoreClient.cpp index 1de1d61..ccde0c2 100644 --- a/Swiften/Client/CoreClient.cpp +++ b/Swiften/Client/CoreClient.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010-2016 Isode Limited. + * Copyright (c) 2010-2018 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swiften/Client/CoreClient.h> @@ -83,20 +83,40 @@ void CoreClient::connect(const ClientOptions& o) { } break; case ClientOptions::SOCKS5Proxy: { SWIFT_LOG(debug) << " with manual configured SOCKS5 proxy" << std::endl; std::string proxyHostname = o.manualProxyHostname.empty() ? systemSOCKS5Proxy.getAddress().toString() : o.manualProxyHostname; - int proxyPort = o.manualProxyPort == -1 ? systemSOCKS5Proxy.getPort() : o.manualProxyPort; + auto proxyPort = systemSOCKS5Proxy.getPort(); + if (o.manualProxyPort != -1) { + try { + proxyPort = boost::numeric_cast<unsigned short>(o.manualProxyPort); + } + catch (const boost::numeric::bad_numeric_cast& e) { + SWIFT_LOG(warning) << "Manual proxy port " << o.manualProxyPort << " is invalid: " << e.what() << std::endl; + onDisconnected(boost::optional<ClientError>(ClientError::ConnectionError)); + return; + } + } SWIFT_LOG(debug) << "Proxy: " << proxyHostname << ":" << proxyPort << std::endl; proxyConnectionFactories.push_back(new SOCKS5ProxiedConnectionFactory(networkFactories->getDomainNameResolver(), networkFactories->getConnectionFactory(), networkFactories->getTimerFactory(), proxyHostname, proxyPort)); useDirectConnection = false; break; } case ClientOptions::HTTPConnectProxy: { SWIFT_LOG(debug) << " with manual configured HTTPConnect proxy" << std::endl; std::string proxyHostname = o.manualProxyHostname.empty() ? systemHTTPConnectProxy.getAddress().toString() : o.manualProxyHostname; - int proxyPort = o.manualProxyPort == -1 ? systemHTTPConnectProxy.getPort() : o.manualProxyPort; + unsigned short proxyPort = systemHTTPConnectProxy.getPort(); + if (o.manualProxyPort != -1) { + try { + proxyPort = boost::numeric_cast<unsigned short>(o.manualProxyPort); + } + catch (const boost::numeric::bad_numeric_cast& e) { + SWIFT_LOG(warning) << "Manual proxy port " << o.manualProxyPort << " is invalid: " << e.what() << std::endl; + onDisconnected(boost::optional<ClientError>(ClientError::ConnectionError)); + return; + } + } SWIFT_LOG(debug) << "Proxy: " << proxyHostname << ":" << proxyPort << std::endl; proxyConnectionFactories.push_back(new HTTPConnectProxiedConnectionFactory(networkFactories->getDomainNameResolver(), networkFactories->getConnectionFactory(), networkFactories->getTimerFactory(), proxyHostname, proxyPort, o.httpTrafficFilter)); useDirectConnection = false; break; } @@ -106,11 +126,21 @@ void CoreClient::connect(const ClientOptions& o) { connectionFactories.push_back(networkFactories->getConnectionFactory()); } // Create connector std::string host = o.manualHostname.empty() ? jid_.getDomain() : o.manualHostname; - int port = o.manualPort; + unsigned short port = 0; + if (o.manualPort != -1) { + try { + port = boost::numeric_cast<unsigned short>(o.manualPort); + } + catch (const boost::numeric::bad_numeric_cast& e) { + SWIFT_LOG(warning) << "Invalid manual port " << o.manualPort << ": " << e.what() << std::endl; + onDisconnected(boost::optional<ClientError>(ClientError::ConnectionError)); + return; + } + } boost::optional<std::string> serviceLookupPrefix; if (o.manualHostname.empty()) { serviceLookupPrefix = "_xmpp-client._tcp."; } assert(!connector_); @@ -284,10 +314,12 @@ void CoreClient::handleSessionFinished(std::shared_ptr<Error> error) { switch(actualError->getType()) { case TLSError::CertificateCardRemoved: clientError = ClientError(ClientError::CertificateCardRemoved); break; case TLSError::UnknownError: + case TLSError::AcceptFailed: + case TLSError::ConnectFailed: clientError = ClientError(ClientError::TLSError); break; } } else if (std::shared_ptr<SessionStream::SessionStreamError> actualError = std::dynamic_pointer_cast<SessionStream::SessionStreamError>(error)) { diff --git a/Swiften/Client/DummyStanzaChannel.h b/Swiften/Client/DummyStanzaChannel.h index 4cc0f7e..1ba70ad 100644 --- a/Swiften/Client/DummyStanzaChannel.h +++ b/Swiften/Client/DummyStanzaChannel.h @@ -46,12 +46,16 @@ namespace Swift { virtual bool isAvailable() const { return available_; } + virtual void setStreamManagementEnabled(bool enable) { + streamManagement_ = enable; + } + virtual bool getStreamManagementEnabled() const { - return false; + return streamManagement_; } template<typename T> bool isRequestAtIndex(size_t index, const JID& jid, IQ::Type type) { if (index >= sentStanzas.size()) { return false; @@ -99,7 +103,8 @@ namespace Swift { std::vector<std::shared_ptr<Stanza> > sentStanzas; bool available_ = true; bool uniqueIDs_ = false; unsigned int idCounter_ = 0; + bool streamManagement_ = false; }; } diff --git a/Swiften/Client/UnitTest/XMLBeautifierTest.cpp b/Swiften/Client/UnitTest/XMLBeautifierTest.cpp index 0188634..2a639ea 100644 --- a/Swiften/Client/UnitTest/XMLBeautifierTest.cpp +++ b/Swiften/Client/UnitTest/XMLBeautifierTest.cpp @@ -1,34 +1,37 @@ /* - * Copyright (c) 2010-2017 Isode Limited. + * Copyright (c) 2010-2018 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include "gtest/gtest.h" #include <Swiften/Client/XMLBeautifier.h> #include <iostream> +// Clang wrongly things that tests for 0 are using 0 as null. +#pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant" + using namespace Swift; namespace { const static std::string FULL_FORMATTED_OUTPUT("<list>\n <el>aqq</el>\n <el>bzz</el>\n</list>"); } TEST(XMLBeautifierTest, testBeautify) { - auto beautifier = std::unique_ptr<XMLBeautifier>(new XMLBeautifier(true, false)); + auto beautifier = std::make_unique<XMLBeautifier>(true, false); ASSERT_EQ(FULL_FORMATTED_OUTPUT, beautifier->beautify("<list><el>aqq</el><el>bzz</el></list>")); ASSERT_TRUE(beautifier->wasReset()); ASSERT_EQ(0, beautifier->getLevel()); ASSERT_EQ(FULL_FORMATTED_OUTPUT, beautifier->beautify("<list><el>aqq</el><el>bzz</el></list>")); ASSERT_TRUE(beautifier->wasReset()); ASSERT_EQ(0, beautifier->getLevel()); } TEST(XMLBeautifierTest, testBeautifyMultipleChunks) { - auto beautifier = std::unique_ptr<XMLBeautifier>(new XMLBeautifier(true, false)); + auto beautifier = std::make_unique<XMLBeautifier>(true, false); auto result = beautifier->beautify("<list><el>aqq</el>"); ASSERT_TRUE(beautifier->wasReset()); ASSERT_EQ(1, beautifier->getLevel()); @@ -38,11 +41,11 @@ TEST(XMLBeautifierTest, testBeautifyMultipleChunks) { ASSERT_EQ(FULL_FORMATTED_OUTPUT, result); } TEST(XMLBeautifierTest, testBeautifyMultipleChunksMiddleElement) { - auto beautifier = std::unique_ptr<XMLBeautifier>(new XMLBeautifier(true, false)); + auto beautifier = std::make_unique<XMLBeautifier>(true, false); auto result = beautifier->beautify("<l"); ASSERT_TRUE(beautifier->wasReset()); ASSERT_EQ(0, beautifier->getLevel()); @@ -52,11 +55,11 @@ TEST(XMLBeautifierTest, testBeautifyMultipleChunksMiddleElement) { ASSERT_EQ(FULL_FORMATTED_OUTPUT, result); } TEST(XMLBeautifierTest, testBeautifyInvalidMultipleChunks) { - auto beautifier = std::unique_ptr<XMLBeautifier>(new XMLBeautifier(true, false)); + auto beautifier = std::make_unique<XMLBeautifier>(true, false); ASSERT_EQ(std::string("<list>\n <el>aqq"), beautifier->beautify("<list><el>aqq<")); ASSERT_TRUE(beautifier->wasReset()); ASSERT_EQ(2, beautifier->getLevel()); |
Swift