Skip to content

Commit

Permalink
Message: Add parseExtensions() for parsing additional extensions
Browse files Browse the repository at this point in the history
Useful for encryption when parsing decrypted elements.
  • Loading branch information
melvo authored and lnjX committed Jun 14, 2022
1 parent bcd1c51 commit 550976f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
39 changes: 25 additions & 14 deletions src/base/QXmppMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1188,20 +1188,7 @@ void QXmppMessage::parse(const QDomElement &element, QXmpp::SceMode sceMode)
else
d->type = QXmppMessage::Normal;

QXmppElementList extensions;
for (auto childElement = element.firstChildElement();
!childElement.isNull();
childElement = childElement.nextSiblingElement()) {
if (!checkElement(childElement, QStringLiteral("addresses"), ns_extended_addressing) &&
childElement.tagName() != QStringLiteral("error")) {
// try to parse; add to unknown extensions, if element couldn't be parsed
if (!parseExtension(childElement, sceMode)) {
// other extensions
extensions << QXmppElement(childElement);
}
}
}
setExtensions(extensions);
parseExtensions(element, sceMode);
}

void QXmppMessage::toXml(QXmlStreamWriter *writer) const
Expand Down Expand Up @@ -1229,6 +1216,30 @@ void QXmppMessage::toXml(QXmlStreamWriter *writer, QXmpp::SceMode sceMode) const
}
/// \endcond

///
/// Parses all child elements of a message stanza.
///
/// \param element message element or SCE content element
/// \param sceMode mode to decide which child elements of the message to parse
///
void QXmppMessage::parseExtensions(const QDomElement &element, const QXmpp::SceMode sceMode)
{
QXmppElementList unknownExtensions;
for (auto childElement = element.firstChildElement();
!childElement.isNull();
childElement = childElement.nextSiblingElement()) {
if (!checkElement(childElement, QStringLiteral("addresses"), ns_extended_addressing) &&
childElement.tagName() != QStringLiteral("error")) {
// Try to parse the element and add it as an unknown extension if it
// fails.
if (!parseExtension(childElement, sceMode)) {
unknownExtensions << QXmppElement(childElement);
}
}
}
setExtensions(unknownExtensions);
}

///
/// Parses a child element of the message stanza.
///
Expand Down
1 change: 1 addition & 0 deletions src/base/QXmppMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ class QXMPP_EXPORT QXmppMessage : public QXmppStanza
virtual void toXml(QXmlStreamWriter *writer, QXmpp::SceMode) const;
/// \endcond

void parseExtensions(const QDomElement &element, QXmpp::SceMode sceMode);
virtual bool parseExtension(const QDomElement &element, QXmpp::SceMode);
virtual void serializeExtensions(QXmlStreamWriter *writer, QXmpp::SceMode, const QString &baseNamespace = {}) const;

Expand Down

0 comments on commit 550976f

Please sign in to comment.