From 187a57269387a509e7db34c1a7d51f37acc3ee08 Mon Sep 17 00:00:00 2001 From: Linus Jahn Date: Thu, 29 Sep 2022 15:01:12 +0200 Subject: FileShare: Add encrypted sources Adds new attribute for encrypted sources and parsing. --- src/base/QXmppFileShare.cpp | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) (limited to 'src/base/QXmppFileShare.cpp') diff --git a/src/base/QXmppFileShare.cpp b/src/base/QXmppFileShare.cpp index 9c12ed27..9dd4b686 100644 --- a/src/base/QXmppFileShare.cpp +++ b/src/base/QXmppFileShare.cpp @@ -5,6 +5,7 @@ #include "QXmppFileShare.h" #include "QXmppConstants_p.h" +#include "QXmppEncryptedFileSource.h" #include "QXmppFileMetadata.h" #include "QXmppHttpFileSource.h" @@ -44,6 +45,7 @@ class QXmppFileSharePrivate : public QSharedData public: QXmppFileMetadata metadata; QVector httpSources; + QVector encryptedSources; QXmppFileShare::Disposition disposition = Disposition::Inline; }; /// \endcond @@ -110,6 +112,18 @@ void QXmppFileShare::setHttpSources(const QVector &newHttpS d->httpSources = newHttpSources; } +/// Returns the encrypted sources for this file. +const QVector &QXmppFileShare::encryptedSources() const +{ + return d->encryptedSources; +} + +/// Sets the encrypted sources for this file. +void QXmppFileShare::setEncryptedSourecs(const QVector &newEncryptedSources) +{ + d->encryptedSources = newEncryptedSources; +} + /// \cond bool QXmppFileShare::parse(const QDomElement &el) { @@ -128,12 +142,19 @@ bool QXmppFileShare::parse(const QDomElement &el) // sources: // expect that there's only one sources element with the correct namespace auto sources = el.firstChildElement("sources"); - for (auto urlEl = sources.firstChildElement("url-data"); - !urlEl.isNull(); - urlEl = urlEl.nextSiblingElement("url-data")) { - QXmppHttpFileSource source; - if (source.parse(urlEl)) { - d->httpSources.push_back(std::move(source)); + for (auto sourceEl = sources.firstChildElement(); + !sourceEl.isNull(); + sourceEl = sourceEl.nextSiblingElement()) { + if (sourceEl.tagName() == QStringLiteral("url-data")) { + QXmppHttpFileSource source; + if (source.parse(sourceEl)) { + d->httpSources.push_back(std::move(source)); + } + } else if (sourceEl.tagName() == QStringLiteral("encrypted")) { + QXmppEncryptedFileSource source; + if (source.parse(sourceEl)) { + d->encryptedSources.push_back(std::move(source)); + } } } return true; @@ -151,6 +172,9 @@ void QXmppFileShare::toXml(QXmlStreamWriter *writer) const for (const auto &source : d->httpSources) { source.toXml(writer); } + for (const auto &source : d->encryptedSources) { + source.toXml(writer); + } writer->writeEndElement(); writer->writeEndElement(); } -- cgit v1.2.3