aboutsummaryrefslogtreecommitdiff
path: root/src/base
diff options
context:
space:
mode:
authorLinus Jahn <lnj@kaidan.im>2019-11-16 23:02:57 +0100
committerLNJ <lnj@kaidan.im>2019-12-06 22:26:12 +0100
commit0ef3588af37a7eb28af1dd33c9c3ad06b29f80d7 (patch)
tree1641812cf2d83ddfaae9579ebae9881165385bf9 /src/base
parent69050deaffe471a603eddc55289c1a3a1e1e7850 (diff)
downloadqxmpp-0ef3588af37a7eb28af1dd33c9c3ad06b29f80d7.tar.gz
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.
Diffstat (limited to 'src/base')
-rw-r--r--src/base/QXmppBitsOfBinaryDataList.cpp58
-rw-r--r--src/base/QXmppBitsOfBinaryDataList.h51
2 files changed, 109 insertions, 0 deletions
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 <QDomElement>
+
+#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 <data/> 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 <QVector>
+
+#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<QXmppBitsOfBinaryData>
+{
+public:
+ QXmppBitsOfBinaryDataList();
+ ~QXmppBitsOfBinaryDataList();
+
+ /// \cond
+ void parse(const QDomElement &element);
+ void toXml(QXmlStreamWriter *writer) const;
+ /// \endcond
+};
+
+#endif // QXMPPBITSOFBINARYDATACONTAINER_H