1// Copyright (C) 2017 Witekio.
2// Copyright (C) 2018 The Qt Company Ltd.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
4// Qt-Security score:significant reason:default
5
6#ifndef QCOAPMESSAGE_H
7#define QCOAPMESSAGE_H
8
9#include <QtCore/qglobal.h>
10#include <QtCoap/qcoapglobal.h>
11#include <QtCoap/qcoapoption.h>
12#include <QtCore/qlist.h>
13#include <QtCore/qobject.h>
14#include <QtCore/qshareddata.h>
15
16QT_BEGIN_NAMESPACE
17
18class QCoapMessagePrivate;
19class Q_COAP_EXPORT QCoapMessage
20{
21public:
22 enum class Type : quint8 {
23 Confirmable,
24 NonConfirmable,
25 Acknowledgment,
26 Reset
27 };
28
29 QCoapMessage();
30 QCoapMessage(const QCoapMessage &other);
31 ~QCoapMessage();
32
33 void swap(QCoapMessage &other) noexcept;
34 QCoapMessage &operator=(const QCoapMessage &other);
35 QCoapMessage &operator=(QCoapMessage &&other) noexcept;
36
37 quint8 version() const;
38 Type type() const;
39 QByteArray token() const;
40 quint8 tokenLength() const;
41 quint16 messageId() const;
42 QByteArray payload() const;
43 void setVersion(quint8 version);
44 void setType(const Type &type);
45 void setToken(const QByteArray &token);
46 void setMessageId(quint16);
47 void setPayload(const QByteArray &payload);
48 void setOptions(const QList<QCoapOption> &options);
49
50 QCoapOption optionAt(int index) const;
51 QCoapOption option(QCoapOption::OptionName name) const;
52 bool hasOption(QCoapOption::OptionName name) const;
53 const QList<QCoapOption> &options() const;
54 QList<QCoapOption> options(QCoapOption::OptionName name) const;
55 int optionCount() const;
56 void addOption(QCoapOption::OptionName name, const QByteArray &value = QByteArray());
57 void addOption(const QCoapOption &option);
58 void removeOption(const QCoapOption &option);
59 void removeOption(QCoapOption::OptionName name);
60 void clearOptions();
61
62protected:
63 explicit QCoapMessage(QCoapMessagePrivate &dd);
64
65 QSharedDataPointer<QCoapMessagePrivate> d_ptr;
66
67 // Q_DECLARE_PRIVATE equivalent for shared data pointers
68 inline QCoapMessagePrivate *d_func();
69 const QCoapMessagePrivate *d_func() const { return d_ptr.constData(); }
70};
71
72Q_DECLARE_SHARED(QCoapMessage)
73
74QT_END_NAMESPACE
75
76Q_DECLARE_METATYPE(QCoapMessage)
77Q_DECLARE_METATYPE(QCoapMessage::Type)
78
79#endif // QCOAPMESSAGE_H
80

source code of qtcoap/src/coap/qcoapmessage.h