From 0ef3588af37a7eb28af1dd33c9c3ad06b29f80d7 Mon Sep 17 00:00:00 2001 From: Linus Jahn Date: Sat, 16 Nov 2019 23:02:57 +0100 Subject: Implement XEP-0231: Bits of Binary: stanza extension This adds a type that may be used as a stanza extension. It is useful, when a stanza contains (possibly multiple) XEP-0231: Bits of Binary data elements. --- src/base/QXmppBitsOfBinaryDataList.cpp | 58 ++++++++++++++++++++++++++++++++++ src/base/QXmppBitsOfBinaryDataList.h | 51 ++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 src/base/QXmppBitsOfBinaryDataList.cpp create mode 100644 src/base/QXmppBitsOfBinaryDataList.h (limited to 'src/base') diff --git a/src/base/QXmppBitsOfBinaryDataList.cpp b/src/base/QXmppBitsOfBinaryDataList.cpp new file mode 100644 index 00000000..a9de33e1 --- /dev/null +++ b/src/base/QXmppBitsOfBinaryDataList.cpp @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2008-2019 The QXmpp developers + * + * Author: + * Linus Jahn + * + * Source: + * https://github.com/qxmpp-project/qxmpp + * + * This file is a part of QXmpp library. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + */ + +#include "QXmppBitsOfBinaryDataList.h" + +#include + +#include "QXmppBitsOfBinaryData.h" +#include "QXmppConstants_p.h" + +QXmppBitsOfBinaryDataList::QXmppBitsOfBinaryDataList() = default; + +QXmppBitsOfBinaryDataList::~QXmppBitsOfBinaryDataList() = default; + +/// \cond +void QXmppBitsOfBinaryDataList::parse(const QDomElement &element) +{ + // clear previous data elements + clear(); + + // parse all elements + QDomElement child = element.firstChildElement(); + while (!child.isNull()) { + if (QXmppBitsOfBinaryData::isBitsOfBinaryData(child)) { + QXmppBitsOfBinaryData data; + data.parseElementFromChild(child); + append(data); + } + child = child.nextSiblingElement(); + } +} + +void QXmppBitsOfBinaryDataList::toXml(QXmlStreamWriter *writer) const +{ + for (const auto &bitsOfBinaryData : *this) + bitsOfBinaryData.toXmlElementFromChild(writer); +} +/// \endcond diff --git a/src/base/QXmppBitsOfBinaryDataList.h b/src/base/QXmppBitsOfBinaryDataList.h new file mode 100644 index 00000000..2a6f5311 --- /dev/null +++ b/src/base/QXmppBitsOfBinaryDataList.h @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2008-2019 The QXmpp developers + * + * Author: + * Linus Jahn + * + * Source: + * https://github.com/qxmpp-project/qxmpp + * + * This file is a part of QXmpp library. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + */ + +#ifndef QXMPPBITSOFBINARYDATACONTAINER_H +#define QXMPPBITSOFBINARYDATACONTAINER_H + +#include + +#include "QXmppBitsOfBinaryData.h" + +class QDomElement; +class QXmlStreamWriter; + +/// \class QXmppBitsOfBinaryDataList represents a list of data elements from +/// XEP-0231: Bits of Binary. +/// +/// \since QXmpp 1.2 + +class QXMPP_EXPORT QXmppBitsOfBinaryDataList : public QVector +{ +public: + QXmppBitsOfBinaryDataList(); + ~QXmppBitsOfBinaryDataList(); + + /// \cond + void parse(const QDomElement &element); + void toXml(QXmlStreamWriter *writer) const; + /// \endcond +}; + +#endif // QXMPPBITSOFBINARYDATACONTAINER_H -- cgit v1.2.3