diff options
| author | Linus Jahn <lnj@kaidan.im> | 2023-03-09 20:36:08 +0100 |
|---|---|---|
| committer | Linus Jahn <lnj@kaidan.im> | 2023-03-09 20:38:05 +0100 |
| commit | 7c7ce1ac0b06455cf08186543452c65410fe79a9 (patch) | |
| tree | 275080c868beb9baf82d614dc740cf009260ecec | |
| parent | fcd8224256e38d50d4ec67b71c504dcb6e480e95 (diff) | |
Readd old PubSubIq and PubSubItem for compatibility
There is at least one package that actually uses this API and this way
QXmpp 1.5 can be easily adopted.
| -rw-r--r-- | src/CMakeLists.txt | 4 | ||||
| -rw-r--r-- | src/base/compat/QXmppPubSubIq.cpp | 210 | ||||
| -rw-r--r-- | src/base/compat/QXmppPubSubIq.h | 66 | ||||
| -rw-r--r-- | src/base/compat/QXmppPubSubItem.cpp | 76 | ||||
| -rw-r--r-- | src/base/compat/QXmppPubSubItem.h | 42 |
5 files changed, 398 insertions, 0 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0f533a01..54120b8a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -81,6 +81,8 @@ set(INSTALL_HEADER_FILES base/QXmppUtils.h base/QXmppVCardIq.h base/QXmppVersionIq.h + base/compat/QXmppPubSubIq.h + base/compat/QXmppPubSubItem.h # Client client/QXmppArchiveManager.h @@ -212,6 +214,8 @@ set(SOURCE_FILES base/QXmppUtils.cpp base/QXmppVCardIq.cpp base/QXmppVersionIq.cpp + base/compat/QXmppPubSubIq.cpp + base/compat/QXmppPubSubItem.cpp # Client client/QXmppArchiveManager.cpp diff --git a/src/base/compat/QXmppPubSubIq.cpp b/src/base/compat/QXmppPubSubIq.cpp new file mode 100644 index 00000000..9df2fdf1 --- /dev/null +++ b/src/base/compat/QXmppPubSubIq.cpp @@ -0,0 +1,210 @@ +// SPDX-FileCopyrightText: 2010 Jeremy Lainé <jeremy.laine@m4x.org> +// +// SPDX-License-Identifier: LGPL-2.1-or-later + +#include "QXmppPubSubIq.h" + +#include "QXmppConstants_p.h" +#include "QXmppUtils.h" + +#include <QDomElement> +#include <QSharedData> + +/// \cond +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED + +static const QStringList PUBSUB_QUERIES = { + QStringLiteral("affiliations"), + QStringLiteral("default"), + QStringLiteral("items"), + QStringLiteral("publish"), + QStringLiteral("retract"), + QStringLiteral("subscribe"), + QStringLiteral("subscription"), + QStringLiteral("subscriptions"), + QStringLiteral("unsubscribe"), +}; + +class QXmppPubSubIqPrivate : public QSharedData +{ +public: + QXmppPubSubIqPrivate(); + + QXmppPubSubIq::QueryType queryType; + QString queryJid; + QString queryNode; + QList<QXmppPubSubItem> items; + QString subscriptionId; + QString subscriptionType; +}; + +QXmppPubSubIqPrivate::QXmppPubSubIqPrivate() + : queryType(QXmppPubSubIq::ItemsQuery) +{ +} + +QXmppPubSubIq::QXmppPubSubIq() + : d(new QXmppPubSubIqPrivate) +{ +} + +QXmppPubSubIq::QXmppPubSubIq(const QXmppPubSubIq &iq) = default; + +QXmppPubSubIq::~QXmppPubSubIq() = default; + +QXmppPubSubIq &QXmppPubSubIq::operator=(const QXmppPubSubIq &iq) = default; + +/// Returns the PubSub queryType for this IQ. + +QXmppPubSubIq::QueryType QXmppPubSubIq::queryType() const +{ + return d->queryType; +} + +/// Sets the PubSub queryType for this IQ. +/// +/// \param queryType + +void QXmppPubSubIq::setQueryType(QXmppPubSubIq::QueryType queryType) +{ + d->queryType = queryType; +} + +/// Returns the JID being queried. + +QString QXmppPubSubIq::queryJid() const +{ + return d->queryJid; +} + +/// Sets the JID being queried. +/// +/// \param queryJid + +void QXmppPubSubIq::setQueryJid(const QString &queryJid) +{ + d->queryJid = queryJid; +} + +/// Returns the node being queried. + +QString QXmppPubSubIq::queryNode() const +{ + return d->queryNode; +} + +/// Sets the node being queried. +/// +/// \param queryNode + +void QXmppPubSubIq::setQueryNode(const QString &queryNode) +{ + d->queryNode = queryNode; +} + +/// Returns the subscription ID. + +QString QXmppPubSubIq::subscriptionId() const +{ + return d->subscriptionId; +} + +/// Sets the subscription ID. +/// +/// \param subscriptionId + +void QXmppPubSubIq::setSubscriptionId(const QString &subscriptionId) +{ + d->subscriptionId = subscriptionId; +} + +/// Returns the IQ's items. + +QList<QXmppPubSubItem> QXmppPubSubIq::items() const +{ + return d->items; +} + +/// Sets the IQ's items. +/// +/// \param items + +void QXmppPubSubIq::setItems(const QList<QXmppPubSubItem> &items) +{ + d->items = items; +} + +bool QXmppPubSubIq::isPubSubIq(const QDomElement &element) +{ + return element.firstChildElement(QStringLiteral("pubsub")).namespaceURI() == ns_pubsub; +} + +void QXmppPubSubIq::parseElementFromChild(const QDomElement &element) +{ + const QDomElement pubSubElement = element.firstChildElement(QStringLiteral("pubsub")); + + const QDomElement queryElement = pubSubElement.firstChildElement(); + + // determine query type + const QString tagName = queryElement.tagName(); + int queryType = PUBSUB_QUERIES.indexOf(queryElement.tagName()); + if (queryType > -1) + d->queryType = QueryType(queryType); + + d->queryJid = queryElement.attribute(QStringLiteral("jid")); + d->queryNode = queryElement.attribute(QStringLiteral("node")); + + // parse contents + QDomElement childElement; + switch (d->queryType) { + case QXmppPubSubIq::ItemsQuery: + case QXmppPubSubIq::PublishQuery: + case QXmppPubSubIq::RetractQuery: + childElement = queryElement.firstChildElement(QStringLiteral("item")); + while (!childElement.isNull()) { + QXmppPubSubItem item; + item.parse(childElement); + d->items << item; + childElement = childElement.nextSiblingElement(QStringLiteral("item")); + } + break; + case QXmppPubSubIq::SubscriptionQuery: + d->subscriptionId = queryElement.attribute(QStringLiteral("subid")); + d->subscriptionType = queryElement.attribute(QStringLiteral("subscription")); + break; + default: + break; + } +} + +void QXmppPubSubIq::toXmlElementFromChild(QXmlStreamWriter *writer) const +{ + writer->writeStartElement(QStringLiteral("pubsub")); + writer->writeDefaultNamespace(ns_pubsub); + + // write query type + writer->writeStartElement(PUBSUB_QUERIES.at(d->queryType)); + helperToXmlAddAttribute(writer, QStringLiteral("jid"), d->queryJid); + helperToXmlAddAttribute(writer, QStringLiteral("node"), d->queryNode); + + // write contents + switch (d->queryType) { + case QXmppPubSubIq::ItemsQuery: + case QXmppPubSubIq::PublishQuery: + case QXmppPubSubIq::RetractQuery: + for (const auto &item : d->items) + item.toXml(writer); + break; + case QXmppPubSubIq::SubscriptionQuery: + helperToXmlAddAttribute(writer, QStringLiteral("subid"), d->subscriptionId); + helperToXmlAddAttribute(writer, QStringLiteral("subscription"), d->subscriptionType); + break; + default: + break; + } + writer->writeEndElement(); + writer->writeEndElement(); +} +QT_WARNING_POP +/// \endcond diff --git a/src/base/compat/QXmppPubSubIq.h b/src/base/compat/QXmppPubSubIq.h new file mode 100644 index 00000000..057efa98 --- /dev/null +++ b/src/base/compat/QXmppPubSubIq.h @@ -0,0 +1,66 @@ +// SPDX-FileCopyrightText: 2010 Jeremy Lainé <jeremy.laine@m4x.org> +// +// SPDX-License-Identifier: LGPL-2.1-or-later + +#ifndef QXMPPPUBSUBIQ_H +#define QXMPPPUBSUBIQ_H + +#include "QXmppIq.h" + +#include <QSharedDataPointer> + +#if QXMPP_DEPRECATED_SINCE(1, 2) +#include "QXmppPubSubItem.h" +#endif + +class QXmppPubSubIqPrivate; + +#if QXMPP_DEPRECATED_SINCE(1, 5) +class QXMPP_EXPORT QXmppPubSubIq : public QXmppIq +{ +public: + enum [[deprecated]] QueryType { + AffiliationsQuery, + DefaultQuery, + ItemsQuery, + PublishQuery, + RetractQuery, + SubscribeQuery, + SubscriptionQuery, + SubscriptionsQuery, + UnsubscribeQuery + }; + + [[deprecated]] QXmppPubSubIq(); + QXmppPubSubIq(const QXmppPubSubIq &iq); + ~QXmppPubSubIq(); + + QXmppPubSubIq &operator=(const QXmppPubSubIq &iq); + + [[deprecated]] QXmppPubSubIq::QueryType queryType() const; + [[deprecated]] void setQueryType(QXmppPubSubIq::QueryType queryType); + + [[deprecated]] QString queryJid() const; + [[deprecated]] void setQueryJid(const QString &jid); + + [[deprecated]] QString queryNode() const; + [[deprecated]] void setQueryNode(const QString &node); + + [[deprecated]] QList<QXmppPubSubItem> items() const; + [[deprecated]] void setItems(const QList<QXmppPubSubItem> &items); + + [[deprecated]] QString subscriptionId() const; + [[deprecated]] void setSubscriptionId(const QString &id); + + [[deprecated]] static bool isPubSubIq(const QDomElement &element); + +protected: + void parseElementFromChild(const QDomElement &) override; + void toXmlElementFromChild(QXmlStreamWriter *writer) const override; + +private: + QSharedDataPointer<QXmppPubSubIqPrivate> d; +}; +#endif + +#endif // QXMPPPUBSUBIQ_H diff --git a/src/base/compat/QXmppPubSubItem.cpp b/src/base/compat/QXmppPubSubItem.cpp new file mode 100644 index 00000000..cfd2724e --- /dev/null +++ b/src/base/compat/QXmppPubSubItem.cpp @@ -0,0 +1,76 @@ +// SPDX-FileCopyrightText: 2010 Jeremy Lainé <jeremy.laine@m4x.org> +// +// SPDX-License-Identifier: LGPL-2.1-or-later + +#include "QXmppPubSubItem.h" + +#include "QXmppElement.h" +#include "QXmppUtils.h" + +#include <QDomElement> + +/// \cond +class QXmppPubSubItemPrivate : public QSharedData +{ +public: + QString id; + QXmppElement contents; +}; + +QXmppPubSubItem::QXmppPubSubItem() + : d(new QXmppPubSubItemPrivate) +{ +} + +QXmppPubSubItem::QXmppPubSubItem(const QXmppPubSubItem &iq) = default; + +QXmppPubSubItem::~QXmppPubSubItem() = default; + +QXmppPubSubItem &QXmppPubSubItem::operator=(const QXmppPubSubItem &iq) = default; + +/// Returns the ID of the PubSub item. + +QString QXmppPubSubItem::id() const +{ + return d->id; +} + +/// Sets the ID of the PubSub item. +/// +/// \param id + +void QXmppPubSubItem::setId(const QString &id) +{ + d->id = id; +} + +/// Returns the contents of the PubSub item. + +QXmppElement QXmppPubSubItem::contents() const +{ + return d->contents; +} + +/// Sets the contents of the PubSub item. +/// +/// \param contents + +void QXmppPubSubItem::setContents(const QXmppElement &contents) +{ + d->contents = contents; +} + +void QXmppPubSubItem::parse(const QDomElement &element) +{ + d->id = element.attribute(QStringLiteral("id")); + d->contents = QXmppElement(element.firstChildElement()); +} + +void QXmppPubSubItem::toXml(QXmlStreamWriter *writer) const +{ + writer->writeStartElement(QStringLiteral("item")); + helperToXmlAddAttribute(writer, QStringLiteral("id"), d->id); + d->contents.toXml(writer); + writer->writeEndElement(); +} +/// \endcond diff --git a/src/base/compat/QXmppPubSubItem.h b/src/base/compat/QXmppPubSubItem.h new file mode 100644 index 00000000..1d8dc4d3 --- /dev/null +++ b/src/base/compat/QXmppPubSubItem.h @@ -0,0 +1,42 @@ +// SPDX-FileCopyrightText: 2010 Jeremy Lainé <jeremy.laine@m4x.org> +// +// SPDX-License-Identifier: LGPL-2.1-or-later + +#ifndef QXMPPPUBSUBITEM_H +#define QXMPPPUBSUBITEM_H + +#include "QXmppGlobal.h" + +#include <QSharedDataPointer> + +class QDomElement; +class QXmlStreamWriter; + +class QXmppElement; +class QXmppPubSubItemPrivate; + +#if QXMPP_DEPRECATED_SINCE(1, 5) +class QXMPP_EXPORT QXmppPubSubItem +{ +public: + [[deprecated]] QXmppPubSubItem(); + QXmppPubSubItem(const QXmppPubSubItem &iq); + ~QXmppPubSubItem(); + + QXmppPubSubItem &operator=(const QXmppPubSubItem &iq); + + [[deprecated]] QString id() const; + [[deprecated]] void setId(const QString &id); + + [[deprecated]] QXmppElement contents() const; + [[deprecated]] void setContents(const QXmppElement &contents); + + [[deprecated]] void parse(const QDomElement &element); + [[deprecated]] void toXml(QXmlStreamWriter *writer) const; + +private: + QSharedDataPointer<QXmppPubSubItemPrivate> d; +}; +#endif + +#endif // QXMPPPUBSUBITEM_H |
