From dd3171106484ecc089a8fee477076ad83e29907d Mon Sep 17 00:00:00 2001 From: Linus Jahn Date: Sun, 19 May 2024 01:33:29 +0200 Subject: [PATCH] Deprecate QXmppStarttlsPacket --- src/CMakeLists.txt | 3 +- src/base/QXmppStartTlsPacket.cpp | 92 --------------------- src/base/{ => compat}/QXmppStartTlsPacket.h | 8 +- src/base/compat/removed_api.cpp | 85 ++++++++++++++++++- tests/qxmppstream/tst_qxmppstream.cpp | 9 +- 5 files changed, 98 insertions(+), 99 deletions(-) delete mode 100644 src/base/QXmppStartTlsPacket.cpp rename src/base/{ => compat}/QXmppStartTlsPacket.h (77%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 11759637f..21763e2d4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -79,7 +79,6 @@ set(INSTALL_HEADER_FILES base/QXmppSendResult.h base/QXmppSocks.h base/QXmppStanza.h - base/QXmppStartTlsPacket.h base/QXmppStream.h base/QXmppStreamError.h base/QXmppStreamFeatures.h @@ -94,6 +93,7 @@ set(INSTALL_HEADER_FILES base/QXmppVCardIq.h base/QXmppVersionIq.h base/compat/QXmppSessionIq.h + base/compat/QXmppStartTlsPacket.h base/compat/QXmppPubSubIq.h base/compat/QXmppPubSubItem.h @@ -221,7 +221,6 @@ set(SOURCE_FILES base/QXmppSasl.cpp base/QXmppSocks.cpp base/QXmppStanza.cpp - base/QXmppStartTlsPacket.cpp base/QXmppStream.cpp base/QXmppStreamFeatures.cpp base/QXmppStreamInitiationIq.cpp diff --git a/src/base/QXmppStartTlsPacket.cpp b/src/base/QXmppStartTlsPacket.cpp deleted file mode 100644 index fe3d89cb1..000000000 --- a/src/base/QXmppStartTlsPacket.cpp +++ /dev/null @@ -1,92 +0,0 @@ -// SPDX-FileCopyrightText: 2019 Linus Jahn -// -// SPDX-License-Identifier: LGPL-2.1-or-later - -#include "QXmppStartTlsPacket.h" - -#include "QXmppConstants_p.h" -#include "QXmppUtils_p.h" - -#include -#include - -using namespace QXmpp::Private; - -constexpr auto STARTTLS_TYPES = to_array({ - u"starttls", - u"proceed", - u"failure", -}); - -/// -/// Constructs a new QXmppStartTlsPacket -/// -/// \param type The type of the new QXmppStartTlsPacket. -/// -QXmppStartTlsPacket::QXmppStartTlsPacket(Type type) - : m_type(type) -{ -} - -QXmppStartTlsPacket::~QXmppStartTlsPacket() = default; - -/// Returns the type of the STARTTLS packet -QXmppStartTlsPacket::Type QXmppStartTlsPacket::type() const -{ - return m_type; -} - -/// Sets the type of the STARTTLS packet -void QXmppStartTlsPacket::setType(QXmppStartTlsPacket::Type type) -{ - m_type = type; -} - -/// \cond -void QXmppStartTlsPacket::parse(const QDomElement &element) -{ - if (!QXmppStartTlsPacket::isStartTlsPacket(element)) { - return; - } - - m_type = enumFromString(STARTTLS_TYPES, element.tagName()).value_or(Invalid); -} - -void QXmppStartTlsPacket::toXml(QXmlStreamWriter *writer) const -{ - if (m_type != Invalid) { - writer->writeStartElement(toString65(STARTTLS_TYPES.at(size_t(m_type)))); - writer->writeDefaultNamespace(toString65(ns_tls)); - writer->writeEndElement(); - } -} -/// \endcond - -/// -/// Checks whether the given \p element is a STARTTLS packet according to -/// RFC6120. -/// -/// \param element The element that should be checked for being a STARTTLS packet. -/// -/// \returns True, if the element is a STARTTLS packet. -/// -bool QXmppStartTlsPacket::isStartTlsPacket(const QDomElement &element) -{ - return element.namespaceURI() == ns_tls && - enumFromString(STARTTLS_TYPES, element.tagName()).has_value(); -} - -/// -/// Checks whether the given \p element is a STARTTLS packet according to -/// RFC6120 -/// and has the correct type. -/// -/// \param element The element that should be checked for being a STARTTLS packet. -/// \param type The type the element needs to have. -/// -/// \returns True, if the element is a STARTTLS packet and has the correct type. -/// -bool QXmppStartTlsPacket::isStartTlsPacket(const QDomElement &element, Type type) -{ - return element.namespaceURI() == ns_tls && element.tagName() == STARTTLS_TYPES.at(size_t(type)); -} diff --git a/src/base/QXmppStartTlsPacket.h b/src/base/compat/QXmppStartTlsPacket.h similarity index 77% rename from src/base/QXmppStartTlsPacket.h rename to src/base/compat/QXmppStartTlsPacket.h index 191b80ce1..cbb4958b6 100644 --- a/src/base/QXmppStartTlsPacket.h +++ b/src/base/compat/QXmppStartTlsPacket.h @@ -13,6 +13,8 @@ /// /// \ingroup Stanzas /// +/// \deprecated STARTTLS packets will be removed from the public API. +/// class QXMPP_EXPORT QXmppStartTlsPacket : public QXmppNonza { public: @@ -24,7 +26,7 @@ class QXMPP_EXPORT QXmppStartTlsPacket : public QXmppNonza Invalid, ///< Invalid type }; - QXmppStartTlsPacket(Type type = StartTls); + [[deprecated]] QXmppStartTlsPacket(Type type = StartTls); ~QXmppStartTlsPacket() override; Type type() const; @@ -35,8 +37,8 @@ class QXMPP_EXPORT QXmppStartTlsPacket : public QXmppNonza void toXml(QXmlStreamWriter *writer) const override; /// \endcond - static bool isStartTlsPacket(const QDomElement &element); - static bool isStartTlsPacket(const QDomElement &element, Type type); + [[deprecated]] static bool isStartTlsPacket(const QDomElement &element); + [[deprecated]] static bool isStartTlsPacket(const QDomElement &element, Type type); private: Type m_type; diff --git a/src/base/compat/removed_api.cpp b/src/base/compat/removed_api.cpp index ee236e24a..35c028b5d 100644 --- a/src/base/compat/removed_api.cpp +++ b/src/base/compat/removed_api.cpp @@ -8,6 +8,7 @@ #include "QXmppPubSubIq.h" #include "QXmppPubSubItem.h" #include "QXmppSessionIq.h" +#include "QXmppStartTlsPacket.h" #include "QXmppUtils_p.h" #include @@ -228,7 +229,6 @@ void QXmppPubSubIq::toXmlElementFromChild(QXmlStreamWriter *writer) const writer->writeEndElement(); writer->writeEndElement(); } -QT_WARNING_POP /// \endcond // PubSubItem @@ -298,3 +298,86 @@ void QXmppPubSubItem::toXml(QXmlStreamWriter *writer) const writer->writeEndElement(); } /// \endcond + +// StarttlsPacket + +constexpr auto STARTTLS_TYPES = to_array({ + u"starttls", + u"proceed", + u"failure", +}); + +/// +/// Constructs a new QXmppStartTlsPacket +/// +/// \param type The type of the new QXmppStartTlsPacket. +/// +QXmppStartTlsPacket::QXmppStartTlsPacket(Type type) + : m_type(type) +{ +} + +QXmppStartTlsPacket::~QXmppStartTlsPacket() = default; + +/// Returns the type of the STARTTLS packet +QXmppStartTlsPacket::Type QXmppStartTlsPacket::type() const +{ + return m_type; +} + +/// Sets the type of the STARTTLS packet +void QXmppStartTlsPacket::setType(QXmppStartTlsPacket::Type type) +{ + m_type = type; +} + +/// \cond +void QXmppStartTlsPacket::parse(const QDomElement &element) +{ + if (!QXmppStartTlsPacket::isStartTlsPacket(element)) { + return; + } + + m_type = enumFromString(STARTTLS_TYPES, element.tagName()).value_or(Invalid); +} + +void QXmppStartTlsPacket::toXml(QXmlStreamWriter *writer) const +{ + if (m_type != Invalid) { + writer->writeStartElement(toString65(STARTTLS_TYPES.at(size_t(m_type)))); + writer->writeDefaultNamespace(toString65(ns_tls)); + writer->writeEndElement(); + } +} +/// \endcond + +/// +/// Checks whether the given \p element is a STARTTLS packet according to +/// RFC6120. +/// +/// \param element The element that should be checked for being a STARTTLS packet. +/// +/// \returns True, if the element is a STARTTLS packet. +/// +bool QXmppStartTlsPacket::isStartTlsPacket(const QDomElement &element) +{ + return element.namespaceURI() == ns_tls && + enumFromString(STARTTLS_TYPES, element.tagName()).has_value(); +} + +/// +/// Checks whether the given \p element is a STARTTLS packet according to +/// RFC6120 +/// and has the correct type. +/// +/// \param element The element that should be checked for being a STARTTLS packet. +/// \param type The type the element needs to have. +/// +/// \returns True, if the element is a STARTTLS packet and has the correct type. +/// +bool QXmppStartTlsPacket::isStartTlsPacket(const QDomElement &element, Type type) +{ + return element.namespaceURI() == ns_tls && element.tagName() == STARTTLS_TYPES.at(size_t(type)); +} + +QT_WARNING_POP diff --git a/tests/qxmppstream/tst_qxmppstream.cpp b/tests/qxmppstream/tst_qxmppstream.cpp index 35a509b30..42c31719f 100644 --- a/tests/qxmppstream/tst_qxmppstream.cpp +++ b/tests/qxmppstream/tst_qxmppstream.cpp @@ -3,12 +3,12 @@ // SPDX-License-Identifier: LGPL-2.1-or-later #include "QXmppConstants_p.h" -#include "QXmppStartTlsPacket.h" #include "QXmppStream.h" #include "QXmppStreamError_p.h" #include "Stream.h" #include "XmppSocket.h" +#include "compat/QXmppStartTlsPacket.h" #include "util.h" using namespace QXmpp; @@ -198,6 +198,8 @@ void tst_QXmppStream::starttlsPackets() void tst_QXmppStream::testStartTlsPacket_data() { + QT_WARNING_PUSH + QT_WARNING_DISABLE_DEPRECATED QTest::addColumn("xml"); QTest::addColumn("valid"); QTest::addColumn("type"); @@ -215,10 +217,14 @@ void tst_QXmppStream::testStartTlsPacket_data() ROW("invalid-tag", R"()", false, QXmppStartTlsPacket::StartTls); #undef ROW + QT_WARNING_POP } void tst_QXmppStream::testStartTlsPacket() { + QT_WARNING_PUSH + QT_WARNING_DISABLE_DEPRECATED + QFETCH(QByteArray, xml); QFETCH(bool, valid); QFETCH(QXmppStartTlsPacket::Type, type); @@ -248,6 +254,7 @@ void tst_QXmppStream::testStartTlsPacket() packet3.setType(type); serializePacket(packet2, xml); } + QT_WARNING_POP } QTEST_MAIN(tst_QXmppStream)