summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Client')
-rw-r--r--Swiften/Client/Client.h2
-rw-r--r--Swiften/Client/ClientSession.cpp26
-rw-r--r--Swiften/Client/ClientSessionStanzaChannel.cpp4
-rw-r--r--Swiften/Client/ClientXMLTracer.cpp4
-rw-r--r--Swiften/Client/CoreClient.cpp64
-rw-r--r--Swiften/Client/CoreClient.h24
-rw-r--r--Swiften/Client/DummyNickManager.h4
-rw-r--r--Swiften/Client/DummyStanzaChannel.h7
-rw-r--r--Swiften/Client/UnitTest/XMLBeautifierTest.cpp13
9 files changed, 92 insertions, 56 deletions
diff --git a/Swiften/Client/Client.h b/Swiften/Client/Client.h
index 5b11688..be4881a 100644
--- a/Swiften/Client/Client.h
+++ b/Swiften/Client/Client.h
@@ -51,7 +51,7 @@ namespace Swift {
/**
* Constructs a client for the given JID with the given password.
*
- * \param jid The JID to be used for the login. If only a bare
+ * \param jid The JID to be used for the login. If only a bare
* JID is give the server will be asked to generate a resource.
* \param password The password used for login given as a \ref SafeString.
* \param networkFactories The network factories that are used
diff --git a/Swiften/Client/ClientSession.cpp b/Swiften/Client/ClientSession.cpp
index 661a832..1114336 100644
--- a/Swiften/Client/ClientSession.cpp
+++ b/Swiften/Client/ClientSession.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010-2016 Isode Limited.
+ * Copyright (c) 2010-2019 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -88,7 +88,7 @@ ClientSession::ClientSession(
authenticationPort(-1) {
#ifdef SWIFTEN_PLATFORM_WIN32
if (WindowsRegistry::isFIPSEnabled()) {
- SWIFT_LOG(info) << "Windows is running in FIPS-140 mode. Some authentication methods will be unavailable." << std::endl;
+ SWIFT_LOG(info) << "Windows is running in FIPS-140 mode. Some authentication methods will be unavailable.";
}
#endif
}
@@ -122,7 +122,7 @@ void ClientSession::sendStanza(std::shared_ptr<Stanza> stanza) {
}
void ClientSession::handleStreamStart(const ProtocolHeader&) {
- CHECK_STATE_OR_RETURN(State::WaitingForStreamStart);
+ CHECK_STATE_OR_RETURN(State::WaitingForStreamStart)
state = State::Negotiating;
}
@@ -214,7 +214,7 @@ void ClientSession::handleElement(std::shared_ptr<ToplevelElement> element) {
}
}
else if (StreamFeatures* streamFeatures = dynamic_cast<StreamFeatures*>(element.get())) {
- CHECK_STATE_OR_RETURN(State::Negotiating);
+ CHECK_STATE_OR_RETURN(State::Negotiating)
if (streamFeatures->hasStartTLS() && stream->supportsTLSEncryption() && useTLS != NeverUseTLS) {
state = State::WaitingForEncrypt;
@@ -231,13 +231,13 @@ void ClientSession::handleElement(std::shared_ptr<ToplevelElement> element) {
#ifdef SWIFTEN_PLATFORM_WIN32
if (singleSignOn) {
const boost::optional<std::string> authenticationHostname = streamFeatures->getAuthenticationHostname();
- bool gssapiSupported = streamFeatures->hasAuthenticationMechanism("GSSAPI") && authenticationHostname && !authenticationHostname->empty();
+ bool gssapiSupported = streamFeatures->hasAuthenticationMechanism("GSSAPI");
if (!gssapiSupported) {
finishSession(Error::NoSupportedAuthMechanismsError);
}
else {
- WindowsGSSAPIClientAuthenticator* gssapiAuthenticator = new WindowsGSSAPIClientAuthenticator(*authenticationHostname, localJID.getDomain(), authenticationPort);
+ WindowsGSSAPIClientAuthenticator* gssapiAuthenticator = new WindowsGSSAPIClientAuthenticator(authenticationHostname.value_or(""), localJID.getDomain(), authenticationPort);
std::shared_ptr<Error> error = std::make_shared<Error>(Error::AuthenticationFailedError);
authenticator = gssapiAuthenticator;
@@ -320,7 +320,7 @@ void ClientSession::handleElement(std::shared_ptr<ToplevelElement> element) {
}
}
else if (std::dynamic_pointer_cast<Compressed>(element)) {
- CHECK_STATE_OR_RETURN(State::Compressing);
+ CHECK_STATE_OR_RETURN(State::Compressing)
state = State::WaitingForStreamStart;
stream->addZLibCompression();
stream->resetXMPPParser();
@@ -343,7 +343,7 @@ void ClientSession::handleElement(std::shared_ptr<ToplevelElement> element) {
continueSessionInitialization();
}
else if (AuthChallenge* challenge = dynamic_cast<AuthChallenge*>(element.get())) {
- CHECK_STATE_OR_RETURN(State::Authenticating);
+ CHECK_STATE_OR_RETURN(State::Authenticating)
assert(authenticator);
if (authenticator->setChallenge(challenge->getValue())) {
stream->writeElement(std::make_shared<AuthResponse>(authenticator->getResponse()));
@@ -361,7 +361,7 @@ void ClientSession::handleElement(std::shared_ptr<ToplevelElement> element) {
}
}
else if (AuthSuccess* authSuccess = dynamic_cast<AuthSuccess*>(element.get())) {
- CHECK_STATE_OR_RETURN(State::Authenticating);
+ CHECK_STATE_OR_RETURN(State::Authenticating)
assert(authenticator);
if (!authenticator->setChallenge(authSuccess->getValue())) {
finishSession(Error::ServerVerificationFailedError);
@@ -378,7 +378,7 @@ void ClientSession::handleElement(std::shared_ptr<ToplevelElement> element) {
finishSession(Error::AuthenticationFailedError);
}
else if (dynamic_cast<TLSProceed*>(element.get())) {
- CHECK_STATE_OR_RETURN(State::WaitingForEncrypt);
+ CHECK_STATE_OR_RETURN(State::WaitingForEncrypt)
state = State::Encrypting;
stream->addTLSEncryption();
}
@@ -433,7 +433,7 @@ void ClientSession::sendCredentials(const SafeByteArray& password) {
void ClientSession::handleTLSEncrypted() {
if (!std::dynamic_pointer_cast<BOSHSessionStream>(stream)) {
- CHECK_STATE_OR_RETURN(State::Encrypting);
+ CHECK_STATE_OR_RETURN(State::Encrypting)
}
std::vector<Certificate::ref> certificateChain = stream->getPeerCertificateChain();
@@ -531,7 +531,7 @@ void ClientSession::finish() {
finishSession(std::shared_ptr<Error>());
}
else {
- SWIFT_LOG(warning) << "Session already finished or finishing." << std::endl;
+ SWIFT_LOG(warning) << "Session already finished or finishing.";
}
}
@@ -544,7 +544,7 @@ void ClientSession::finishSession(std::shared_ptr<Swift::Error> error) {
error_ = error;
}
else {
- SWIFT_LOG(warning) << "Session finished twice" << std::endl;
+ SWIFT_LOG(warning) << "Session finished twice";
}
assert(stream->isOpen());
if (stanzaAckResponder_) {
diff --git a/Swiften/Client/ClientSessionStanzaChannel.cpp b/Swiften/Client/ClientSessionStanzaChannel.cpp
index f48b306..6a5d07d 100644
--- a/Swiften/Client/ClientSessionStanzaChannel.cpp
+++ b/Swiften/Client/ClientSessionStanzaChannel.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010-2016 Isode Limited.
+ * Copyright (c) 2010-2019 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -49,7 +49,7 @@ std::string ClientSessionStanzaChannel::getNewIQID() {
void ClientSessionStanzaChannel::send(std::shared_ptr<Stanza> stanza) {
if (!isAvailable()) {
- SWIFT_LOG(warning) << "Client: Trying to send a stanza while disconnected." << std::endl;
+ SWIFT_LOG(warning) << "Client: Trying to send a stanza while disconnected.";
return;
}
session->sendStanza(stanza);
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
@@ -16,9 +16,9 @@ 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..7579bca 100644
--- a/Swiften/Client/CoreClient.cpp
+++ b/Swiften/Client/CoreClient.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010-2016 Isode Limited.
+ * Copyright (c) 2010-2019 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -69,33 +69,53 @@ void CoreClient::connect(const ClientOptions& o) {
HostAddressPort systemHTTPConnectProxy = networkFactories->getProxyProvider()->getHTTPConnectProxy();
switch (o.proxyType) {
case ClientOptions::NoProxy:
- SWIFT_LOG(debug) << " without a proxy" << std::endl;
+ SWIFT_LOG(debug) << " without a proxy";
break;
case ClientOptions::SystemConfiguredProxy:
- SWIFT_LOG(debug) << " with a system configured proxy" << std::endl;
+ SWIFT_LOG(debug) << " with a system configured proxy";
if (systemSOCKS5Proxy.isValid()) {
- SWIFT_LOG(debug) << "Found SOCK5 Proxy: " << systemSOCKS5Proxy.getAddress().toString() << ":" << systemSOCKS5Proxy.getPort() << std::endl;
+ SWIFT_LOG(debug) << "Found SOCK5 Proxy: " << systemSOCKS5Proxy.getAddress().toString() << ":" << systemSOCKS5Proxy.getPort();
proxyConnectionFactories.push_back(new SOCKS5ProxiedConnectionFactory(networkFactories->getDomainNameResolver(), networkFactories->getConnectionFactory(), networkFactories->getTimerFactory(), systemSOCKS5Proxy.getAddress().toString(), systemSOCKS5Proxy.getPort()));
}
if (systemHTTPConnectProxy.isValid()) {
- SWIFT_LOG(debug) << "Found HTTPConnect Proxy: " << systemHTTPConnectProxy.getAddress().toString() << ":" << systemHTTPConnectProxy.getPort() << std::endl;
+ SWIFT_LOG(debug) << "Found HTTPConnect Proxy: " << systemHTTPConnectProxy.getAddress().toString() << ":" << systemHTTPConnectProxy.getPort();
proxyConnectionFactories.push_back(new HTTPConnectProxiedConnectionFactory(networkFactories->getDomainNameResolver(), networkFactories->getConnectionFactory(), networkFactories->getTimerFactory(), systemHTTPConnectProxy.getAddress().toString(), systemHTTPConnectProxy.getPort()));
}
break;
case ClientOptions::SOCKS5Proxy: {
- SWIFT_LOG(debug) << " with manual configured SOCKS5 proxy" << std::endl;
+ SWIFT_LOG(debug) << " with manual configured SOCKS5 proxy";
std::string proxyHostname = o.manualProxyHostname.empty() ? systemSOCKS5Proxy.getAddress().toString() : o.manualProxyHostname;
- int proxyPort = o.manualProxyPort == -1 ? systemSOCKS5Proxy.getPort() : o.manualProxyPort;
- SWIFT_LOG(debug) << "Proxy: " << proxyHostname << ":" << proxyPort << std::endl;
+ 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();
+ onDisconnected(boost::optional<ClientError>(ClientError::ConnectionError));
+ return;
+ }
+ }
+ SWIFT_LOG(debug) << "Proxy: " << proxyHostname << ":" << proxyPort;
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;
+ SWIFT_LOG(debug) << " with manual configured HTTPConnect proxy";
std::string proxyHostname = o.manualProxyHostname.empty() ? systemHTTPConnectProxy.getAddress().toString() : o.manualProxyHostname;
- int proxyPort = o.manualProxyPort == -1 ? systemHTTPConnectProxy.getPort() : o.manualProxyPort;
- SWIFT_LOG(debug) << "Proxy: " << proxyHostname << ":" << proxyPort << std::endl;
+ 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();
+ onDisconnected(boost::optional<ClientError>(ClientError::ConnectionError));
+ return;
+ }
+ }
+ SWIFT_LOG(debug) << "Proxy: " << proxyHostname << ":" << proxyPort;
proxyConnectionFactories.push_back(new HTTPConnectProxiedConnectionFactory(networkFactories->getDomainNameResolver(), networkFactories->getConnectionFactory(), networkFactories->getTimerFactory(), proxyHostname, proxyPort, o.httpTrafficFilter));
useDirectConnection = false;
break;
@@ -108,7 +128,17 @@ void CoreClient::connect(const ClientOptions& o) {
// Create connector
std::string host = o.manualHostname.empty() ? jid_.getDomain() : o.manualHostname;
- int port = o.manualPort;
+ unsigned short port = 0;
+ if (o.manualPort != -1) {
+ try {
+ port = boost::numeric_cast<unsigned short>(o.manualPort);
+ }
+ catch (const boost::numeric::bad_numeric_cast& e) {
+ SWIFT_LOG(warning) << "Invalid manual port " << o.manualPort << ": " << e.what();
+ onDisconnected(boost::optional<ClientError>(ClientError::ConnectionError));
+ return;
+ }
+ }
boost::optional<std::string> serviceLookupPrefix;
if (o.manualHostname.empty()) {
serviceLookupPrefix = "_xmpp-client._tcp.";
@@ -144,7 +174,7 @@ void CoreClient::connect(const ClientOptions& o) {
sessionStream_->onDataRead.connect(boost::bind(&CoreClient::handleDataRead, this, _1));
sessionStream_->onDataWritten.connect(boost::bind(&CoreClient::handleDataWritten, this, _1));
if (certificate_ && !certificate_->isNull()) {
- SWIFT_LOG(debug) << "set certificate" << std::endl;
+ SWIFT_LOG(debug) << "set certificate";
sessionStream_->setTLSCertificate(certificate_);
}
boshSessionStream_->open();
@@ -286,6 +316,8 @@ void CoreClient::handleSessionFinished(std::shared_ptr<Error> error) {
clientError = ClientError(ClientError::CertificateCardRemoved);
break;
case TLSError::UnknownError:
+ case TLSError::AcceptFailed:
+ case TLSError::ConnectFailed:
clientError = ClientError(ClientError::TLSError);
break;
}
@@ -391,7 +423,7 @@ void CoreClient::sendPresence(std::shared_ptr<Presence> presence) {
void CoreClient::sendData(const std::string& data) {
if (!sessionStream_) {
- SWIFT_LOG(warning) << "Client: Trying to send data while disconnected." << std::endl;
+ SWIFT_LOG(warning) << "Client: Trying to send data while disconnected.";
return;
}
sessionStream_->writeData(data);
@@ -475,11 +507,11 @@ void CoreClient::resetSession() {
void CoreClient::forceReset() {
if (connector_) {
- SWIFT_LOG(warning) << "Client not disconnected properly: Connector still active" << std::endl;
+ SWIFT_LOG(warning) << "Client not disconnected properly: Connector still active";
resetConnector();
}
if (sessionStream_ || connection_) {
- SWIFT_LOG(warning) << "Client not disconnected properly: Session still active" << std::endl;
+ SWIFT_LOG(warning) << "Client not disconnected properly: Session still active";
resetSession();
}
}
diff --git a/Swiften/Client/CoreClient.h b/Swiften/Client/CoreClient.h
index 27031c0..8168e7b 100644
--- a/Swiften/Client/CoreClient.h
+++ b/Swiften/Client/CoreClient.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010-2016 Isode Limited.
+ * Copyright (c) 2010-2017 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -20,22 +20,20 @@
#include <Swiften/TLS/CertificateWithKey.h>
namespace Swift {
+ class CertificateTrustChecker;
class ChainedConnector;
- class Message;
- class Presence;
+ class ClientSession;
+ class ClientSessionStanzaChannel;
+ class Connection;
+ class ConnectionFactory;
class Error;
class IQRouter;
- class TLSContextFactory;
- class ConnectionFactory;
- class Connection;
- class TimerFactory;
- class ClientSession;
- class StanzaChannel;
- class Stanza;
- class SessionStream;
- class CertificateTrustChecker;
+ class Message;
class NetworkFactories;
- class ClientSessionStanzaChannel;
+ class Presence;
+ class SessionStream;
+ class Stanza;
+ class StanzaChannel;
/**
* The central class for communicating with an XMPP server.
diff --git a/Swiften/Client/DummyNickManager.h b/Swiften/Client/DummyNickManager.h
index 52a8401..8ed7701 100644
--- a/Swiften/Client/DummyNickManager.h
+++ b/Swiften/Client/DummyNickManager.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010 Isode Limited.
+ * Copyright (c) 2010-2017 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -9,8 +9,6 @@
#include <Swiften/Client/NickManager.h>
namespace Swift {
- class VCardManager;
-
class DummyNickManager : public NickManager {
public:
std::string getOwnNick() const {
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
@@ -48,8 +48,12 @@ namespace Swift {
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) {
@@ -101,5 +105,6 @@ namespace Swift {
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,5 +1,5 @@
/*
- * Copyright (c) 2010-2017 Isode Limited.
+ * Copyright (c) 2010-2018 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -8,6 +8,9 @@
#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 {
@@ -15,7 +18,7 @@ namespace {
}
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());
@@ -26,7 +29,7 @@ TEST(XMLBeautifierTest, testBeautify) {
}
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());
@@ -40,7 +43,7 @@ TEST(XMLBeautifierTest, testBeautifyMultipleChunks) {
}
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());
@@ -54,7 +57,7 @@ TEST(XMLBeautifierTest, testBeautifyMultipleChunksMiddleElement) {
}
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());