Skip to content

Commit

Permalink
Deprecate QXmppStarttlsPacket
Browse files Browse the repository at this point in the history
  • Loading branch information
lnjX committed May 19, 2024
1 parent 3b44c8a commit dd31711
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 99 deletions.
3 changes: 1 addition & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down
92 changes: 0 additions & 92 deletions src/base/QXmppStartTlsPacket.cpp

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
///
/// \ingroup Stanzas
///
/// \deprecated STARTTLS packets will be removed from the public API.
///
class QXMPP_EXPORT QXmppStartTlsPacket : public QXmppNonza
{
public:
Expand All @@ -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;
Expand All @@ -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;
Expand Down
85 changes: 84 additions & 1 deletion src/base/compat/removed_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "QXmppPubSubIq.h"
#include "QXmppPubSubItem.h"
#include "QXmppSessionIq.h"
#include "QXmppStartTlsPacket.h"
#include "QXmppUtils_p.h"

#include <QDomElement>
Expand Down Expand Up @@ -228,7 +229,6 @@ void QXmppPubSubIq::toXmlElementFromChild(QXmlStreamWriter *writer) const
writer->writeEndElement();
writer->writeEndElement();
}
QT_WARNING_POP
/// \endcond

// PubSubItem
Expand Down Expand Up @@ -298,3 +298,86 @@ void QXmppPubSubItem::toXml(QXmlStreamWriter *writer) const
writer->writeEndElement();
}
/// \endcond

// StarttlsPacket

constexpr auto STARTTLS_TYPES = to_array<QStringView>({
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<Type>(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
/// <a href="https://xmpp.org/rfcs/rfc6120.html#tls-process-initiate">RFC6120</a>.
///
/// \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<Type>(STARTTLS_TYPES, element.tagName()).has_value();
}

///
/// Checks whether the given \p element is a STARTTLS packet according to
/// <a href="https://xmpp.org/rfcs/rfc6120.html#tls-process-initiate">RFC6120</a>
/// 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
9 changes: 8 additions & 1 deletion tests/qxmppstream/tst_qxmppstream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -198,6 +198,8 @@ void tst_QXmppStream::starttlsPackets()

void tst_QXmppStream::testStartTlsPacket_data()
{
QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED
QTest::addColumn<QByteArray>("xml");
QTest::addColumn<bool>("valid");
QTest::addColumn<QXmppStartTlsPacket::Type>("type");
Expand All @@ -215,10 +217,14 @@ void tst_QXmppStream::testStartTlsPacket_data()
ROW("invalid-tag", R"(<invalid-tag-name xmlns="urn:ietf:params:xml:ns:xmpp-tls"/>)", 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);
Expand Down Expand Up @@ -248,6 +254,7 @@ void tst_QXmppStream::testStartTlsPacket()
packet3.setType(type);
serializePacket(packet2, xml);
}
QT_WARNING_POP
}

QTEST_MAIN(tst_QXmppStream)
Expand Down

0 comments on commit dd31711

Please sign in to comment.