From 28411b5995553eb3a50c826c55517b4c610959c2 Mon Sep 17 00:00:00 2001 From: Linus Jahn Date: Sat, 14 Dec 2019 22:47:28 +0100 Subject: Move TLS negotiation into new QXmppTlsManager --- src/client/QXmppClient.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) (limited to 'src/client/QXmppClient.cpp') diff --git a/src/client/QXmppClient.cpp b/src/client/QXmppClient.cpp index 523a9e79..db56776a 100644 --- a/src/client/QXmppClient.cpp +++ b/src/client/QXmppClient.cpp @@ -32,6 +32,7 @@ #include "QXmppMessage.h" #include "QXmppUtils.h" +#include "QXmppTlsManager.h" #include "QXmppRosterManager.h" #include "QXmppVCardManager.h" #include "QXmppVersionManager.h" @@ -146,6 +147,7 @@ QXmppClient::QXmppClient(QObject *parent) // logging setLogger(QXmppLogger::getLogger()); + addExtension(new QXmppTlsManager); addExtension(new QXmppRosterManager(this)); addExtension(new QXmppVCardManager); addExtension(new QXmppVersionManager); @@ -447,15 +449,54 @@ QAbstractSocket::SocketError QXmppClient::socketError() } /// Returns the human-readable description of the last socket error if error() is QXmppClient::SocketError. -/// QString QXmppClient::socketErrorString() const { return d->stream->socket()->errorString(); } -/// Returns the XMPP stream error if QXmppClient::Error is QXmppClient::XmppStreamError. +/// Returns true, if the used socket supports SSL / TLS encryption. +/// +/// This is useful for checking whether TLS can be enabled. It is used by the +/// \c QXmppTlsManager. /// +/// \since QXmpp 1.2 + +bool QXmppClient::socketSupportsSsl() const +{ + return d->stream->socket()->supportsSsl(); +} + +/// Returns true, if the socket used for connection to the XMPP server +/// currently uses SSL / TLS encryption. +/// +/// When using STARTTLS, this is false at first and becomes true later. +/// +/// \since QXmpp 1.2 + +bool QXmppClient::isSocketEncrypted() const +{ + return d->stream->socket()->isEncrypted(); +} + +/// If the socket supports SSL / TLS encryption, this method can be used to +/// enable it. +/// +/// This is used by the \c QXmppTlsManager to enable SSL / TLS encryption for +/// STARTTLS. +/// +/// \note You should usually not use this method manually. If you want to +/// enable or disable TLS encryption, you can set this in the +/// \c QXmppConfiguration provided to \c connectToServer(). +/// +/// \since QXmpp 1.2 + +void QXmppClient::startSocketEncryption() +{ + d->stream->socket()->startClientEncryption(); +} + +/// Returns the XMPP stream error if QXmppClient::Error is QXmppClient::XmppStreamError. QXmppStanza::Error::Condition QXmppClient::xmppStreamError() { -- cgit v1.2.3