From c85c9c460907e26604554f1b2c6f54734bc8f303 Mon Sep 17 00:00:00 2001 From: Linus Jahn Date: Sun, 16 Oct 2022 21:54:40 +0200 Subject: Add checkIqType() function to IQs This is required so they can be parsed just be specifying the type. --- src/base/QXmppDiscoveryIq.cpp | 11 ++++++++--- src/base/QXmppDiscoveryIq.h | 3 ++- src/base/QXmppEntityTimeIq.cpp | 5 +++++ src/base/QXmppEntityTimeIq.h | 3 ++- src/base/QXmppVCardIq.cpp | 5 +++++ src/base/QXmppVCardIq.h | 1 + src/base/QXmppVersionIq.cpp | 5 +++++ src/base/QXmppVersionIq.h | 1 + 8 files changed, 29 insertions(+), 5 deletions(-) (limited to 'src/base') diff --git a/src/base/QXmppDiscoveryIq.cpp b/src/base/QXmppDiscoveryIq.cpp index 99860c9b..414a2d0f 100644 --- a/src/base/QXmppDiscoveryIq.cpp +++ b/src/base/QXmppDiscoveryIq.cpp @@ -433,12 +433,17 @@ QByteArray QXmppDiscoveryIq::verificationString() const /// bool QXmppDiscoveryIq::isDiscoveryIq(const QDomElement &element) { - QDomElement queryElement = element.firstChildElement("query"); - return (queryElement.namespaceURI() == ns_disco_info || - queryElement.namespaceURI() == ns_disco_items); + QDomElement queryElement = element.firstChildElement(); + return checkIqType(queryElement.tagName(), queryElement.namespaceURI()); } /// \cond +bool QXmppDiscoveryIq::checkIqType(const QString &tagName, const QString &xmlNamespace) +{ + return tagName == QStringLiteral("query") && + (xmlNamespace == ns_disco_info || xmlNamespace == ns_disco_items); +} + void QXmppDiscoveryIq::parseElementFromChild(const QDomElement &element) { QDomElement queryElement = element.firstChildElement("query"); diff --git a/src/base/QXmppDiscoveryIq.h b/src/base/QXmppDiscoveryIq.h index 805d22cf..6e7d47a9 100644 --- a/src/base/QXmppDiscoveryIq.h +++ b/src/base/QXmppDiscoveryIq.h @@ -102,9 +102,10 @@ public: QByteArray verificationString() const; static bool isDiscoveryIq(const QDomElement &element); + /// \cond + static bool checkIqType(const QString &tagName, const QString &xmlNamespace); protected: - /// \cond void parseElementFromChild(const QDomElement &element) override; void toXmlElementFromChild(QXmlStreamWriter *writer) const override; /// \endcond diff --git a/src/base/QXmppEntityTimeIq.cpp b/src/base/QXmppEntityTimeIq.cpp index 6e4e4e27..e51fb1b5 100644 --- a/src/base/QXmppEntityTimeIq.cpp +++ b/src/base/QXmppEntityTimeIq.cpp @@ -55,6 +55,11 @@ bool QXmppEntityTimeIq::isEntityTimeIq(const QDomElement &element) } /// \cond +bool QXmppEntityTimeIq::checkIqType(const QString &tagName, const QString &xmlns) +{ + return tagName == QStringLiteral("time") && xmlns == ns_entity_time; +} + void QXmppEntityTimeIq::parseElementFromChild(const QDomElement &element) { QDomElement timeElement = element.firstChildElement("time"); diff --git a/src/base/QXmppEntityTimeIq.h b/src/base/QXmppEntityTimeIq.h index 1d9f5b15..7525617c 100644 --- a/src/base/QXmppEntityTimeIq.h +++ b/src/base/QXmppEntityTimeIq.h @@ -25,9 +25,10 @@ public: void setUtc(const QDateTime &utc); static bool isEntityTimeIq(const QDomElement &element); + /// \cond + static bool checkIqType(const QString &tagName, const QString &xmlns); protected: - /// \cond void parseElementFromChild(const QDomElement &element) override; void toXmlElementFromChild(QXmlStreamWriter *writer) const override; /// \endcond diff --git a/src/base/QXmppVCardIq.cpp b/src/base/QXmppVCardIq.cpp index fa8e7444..59023ebb 100644 --- a/src/base/QXmppVCardIq.cpp +++ b/src/base/QXmppVCardIq.cpp @@ -984,6 +984,11 @@ bool QXmppVCardIq::isVCard(const QDomElement &nodeRecv) return nodeRecv.firstChildElement(QStringLiteral("vCard")).namespaceURI() == ns_vcard; } +bool QXmppVCardIq::checkIqType(const QString &tagName, const QString &xmlNamespace) +{ + return tagName == "vCard" && xmlNamespace == ns_vcard; +} + void QXmppVCardIq::parseElementFromChild(const QDomElement &nodeRecv) { // vCard diff --git a/src/base/QXmppVCardIq.h b/src/base/QXmppVCardIq.h index ea918c41..c8be6e36 100644 --- a/src/base/QXmppVCardIq.h +++ b/src/base/QXmppVCardIq.h @@ -262,6 +262,7 @@ public: /// \cond static bool isVCard(const QDomElement &element); + static bool checkIqType(const QString &tagName, const QString &xmlNamespace); /// \endcond protected: diff --git a/src/base/QXmppVersionIq.cpp b/src/base/QXmppVersionIq.cpp index 039ba48a..a610bfc1 100644 --- a/src/base/QXmppVersionIq.cpp +++ b/src/base/QXmppVersionIq.cpp @@ -67,6 +67,11 @@ bool QXmppVersionIq::isVersionIq(const QDomElement &element) return queryElement.namespaceURI() == ns_version; } +bool QXmppVersionIq::checkIqType(const QString &tagName, const QString &xmlNamespace) +{ + return tagName == "query" && xmlNamespace == ns_version; +} + void QXmppVersionIq::parseElementFromChild(const QDomElement &element) { QDomElement queryElement = element.firstChildElement(QStringLiteral("query")); diff --git a/src/base/QXmppVersionIq.h b/src/base/QXmppVersionIq.h index ba92827a..4fd9ee5f 100644 --- a/src/base/QXmppVersionIq.h +++ b/src/base/QXmppVersionIq.h @@ -26,6 +26,7 @@ public: /// \cond static bool isVersionIq(const QDomElement &element); + static bool checkIqType(const QString &tagName, const QString &xmlNamespace); /// \endcond protected: -- cgit v1.2.3