aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLinus Jahn <lnj@kaidan.im>2023-01-28 17:36:09 +0100
committerLinus Jahn <lnj@kaidan.im>2023-01-28 17:36:45 +0100
commit95c8d120b40e0bca89d1b6f83e902de9529e8006 (patch)
treeb04490ee0f61e0720a771d0362aae43fcad12f36 /src
parent8ac881a544e8fc7f85d78132610fce1b696d2025 (diff)
downloadqxmpp-95c8d120b40e0bca89d1b6f83e902de9529e8006.tar.gz
IqHandling: Don't accept IQ results/errors
Diffstat (limited to 'src')
-rw-r--r--src/base/QXmppPromise.h1
-rw-r--r--src/client/QXmppIqHandling.cpp13
-rw-r--r--src/client/QXmppIqHandling.h8
3 files changed, 17 insertions, 5 deletions
diff --git a/src/base/QXmppPromise.h b/src/base/QXmppPromise.h
index 91443c7f..4900dae1 100644
--- a/src/base/QXmppPromise.h
+++ b/src/base/QXmppPromise.h
@@ -22,6 +22,7 @@ template<typename T>
class QXmppPromise
{
static_assert(!std::is_abstract_v<T>);
+
public:
template<typename U = T, std::enable_if_t<std::is_void_v<U>> * = nullptr>
QXmppPromise()
diff --git a/src/client/QXmppIqHandling.cpp b/src/client/QXmppIqHandling.cpp
index be164f0f..ddc980fe 100644
--- a/src/client/QXmppIqHandling.cpp
+++ b/src/client/QXmppIqHandling.cpp
@@ -25,3 +25,16 @@ void QXmpp::Private::sendIqReply(QXmppClient *client,
iq.setId(requestId);
client->reply(std::move(iq), e2eeMetadata);
}
+
+std::tuple<bool, QString, QString> QXmpp::Private::checkIsIqRequest(const QDomElement &el)
+{
+ if (el.tagName() != QStringLiteral("iq")) {
+ return { false, {}, {} };
+ }
+ auto queryElement = el.firstChildElement();
+ auto iqType = el.attribute(QStringLiteral("type"));
+ if (iqType != QStringLiteral("get") && iqType != QStringLiteral("set")) {
+ return { false, {}, {} };
+ }
+ return { true, queryElement.tagName(), queryElement.namespaceURI() };
+}
diff --git a/src/client/QXmppIqHandling.h b/src/client/QXmppIqHandling.h
index 0782dd89..7535bc30 100644
--- a/src/client/QXmppIqHandling.h
+++ b/src/client/QXmppIqHandling.h
@@ -22,6 +22,8 @@ namespace Private {
const std::optional<QXmppE2eeMetadata> &e2eeMetadata,
QXmppIq &&iq);
+ QXMPP_EXPORT std::tuple<bool, QString, QString> checkIsIqRequest(const QDomElement &el);
+
template<typename... VariantTypes>
void processHandleIqResult(QXmppClient *client,
const QString &requestId,
@@ -188,11 +190,7 @@ bool handleIqRequests(const QDomElement &element,
QXmppClient *client,
Handler handler)
{
- if (element.tagName() == "iq") {
- auto queryElement = element.firstChildElement();
- auto tagName = queryElement.tagName();
- auto xmlns = queryElement.namespaceURI();
-
+ if (auto [isRequest, tagName, xmlns] = Private::checkIsIqRequest(element); isRequest) {
return (Private::handleIqType<IqTypes>(handler, client, element, e2eeMetadata, tagName, xmlns) || ...);
}
return false;