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#include "qcoapresource_p.h"
7
8QT_BEGIN_NAMESPACE
9
10/*!
11 \class QCoapResource
12 \inmodule QtCoap
13
14 \brief The QCoapResource class holds information about a discovered
15 resource.
16
17 \reentrant
18
19 The QCoapRequest contains data as the path and title of the resource
20 and other ancillary information.
21
22 \sa QCoapResourceDiscoveryReply
23*/
24
25/*!
26 Constructs a new QCoapResource.
27 */
28QCoapResource::QCoapResource() :
29 d(new QCoapResourcePrivate)
30{
31}
32
33/*!
34 Constructs a new CoAP resource as a copy of \a other, making the two
35 resources identical.
36*/
37QCoapResource::QCoapResource(const QCoapResource &other) :
38 d(other.d)
39{
40}
41
42/*!
43 Destroy the QCoapResource.
44 */
45QCoapResource::~QCoapResource()
46{
47}
48
49/*!
50 Copies \a other into this resource, making the two resources identical.
51 Returns a reference to this QCoapResource.
52*/
53QCoapResource &QCoapResource::operator=(const QCoapResource &other)
54{
55 d = other.d;
56 return *this;
57}
58
59/*!
60 Swaps this resource with \a other. This operation is very fast and never fails.
61 */
62void QCoapResource::swap(QCoapResource &other) noexcept
63{
64 d.swap(other&: other.d);
65}
66
67/*!
68 Returns the host of the resource.
69
70 \sa setHost()
71 */
72QHostAddress QCoapResource::host() const
73{
74 return d->host;
75}
76
77/*!
78 Returns the path of the resource.
79
80 \sa setPath()
81 */
82QString QCoapResource::path() const
83{
84 return d->path;
85}
86
87/*!
88 Returns the title of the resource.
89
90 \sa setTitle()
91 */
92QString QCoapResource::title() const
93{
94 return d->title;
95}
96
97/*!
98 Returns \c true if the resource is observable
99
100 \sa setObservable()
101 */
102bool QCoapResource::observable() const
103{
104 return d->observable;
105}
106
107/*!
108 Returns the type of the resource.
109
110 \sa setResourceType()
111 */
112QString QCoapResource::resourceType() const
113{
114 return d->resourceType;
115}
116
117/*!
118 Returns the interface description of the resource.
119
120 The Interface Description 'if' attribute is an opaque string used to
121 provide a name or URI indicating a specific interface definition used
122 to interact with the target resource. It is specified in
123 \l{https://tools.ietf.org/html/rfc6690#section-3.2}{RFC 6690}.
124
125 \sa setInterface()
126 */
127QString QCoapResource::interface() const
128{
129 return d->interface;
130}
131
132/*!
133 Returns the maximum size of the resource.
134
135 The maximum size estimate attribute 'sz' gives an indication of the
136 maximum size of the resource representation returned by performing a
137 GET on the target URI. It is specified in
138 \l{https://tools.ietf.org/html/rfc6690#section-3.3}{RFC 6690}.
139
140 \sa setMaximumSize()
141 */
142int QCoapResource::maximumSize() const
143{
144 return d->maximumSize;
145}
146
147/*!
148 Returns the Content-Format code of the resource.
149
150 The Content-Format code corresponds to the 'ct' attribute and provides a
151 hint about the Content-Formats this resource returns. It is specified
152 in \l{https://tools.ietf.org/html/rfc7252#section-7.2.1}{RFC 7252}.
153
154 \sa setContentFormat()
155 */
156uint QCoapResource::contentFormat() const
157{
158 return d->contentFormat;
159}
160
161/*!
162 Sets the host of the resource to \a host.
163
164 \sa host()
165 */
166void QCoapResource::setHost(const QHostAddress &host)
167{
168 d->host = host;
169}
170
171/*!
172 Sets the path of the resource to \a path.
173
174 \sa path()
175 */
176void QCoapResource::setPath(const QString &path)
177{
178 d->path = path;
179}
180
181/*!
182 Sets the title of the resource to \a title.
183
184 \sa title()
185 */
186void QCoapResource::setTitle(const QString &title)
187{
188 d->title = title;
189}
190
191/*!
192 Makes the resource observable if the \a observable
193 parameter is \c true.
194
195 \sa observable()
196 */
197void QCoapResource::setObservable(bool observable)
198{
199 d->observable = observable;
200}
201
202/*!
203 Sets the resource type to \a resourceType.
204
205 \sa resourceType()
206 */
207void QCoapResource::setResourceType(const QString &resourceType)
208{
209 d->resourceType = resourceType;
210}
211
212/*!
213 Sets the interface of the resource to \a interface.
214
215 \sa interface()
216 */
217void QCoapResource::setInterface(const QString &interface)
218{
219 d->interface = interface;
220}
221
222/*!
223 Sets the maximum size of the resource to \a maximumSize.
224
225 \sa maximumSize()
226 */
227void QCoapResource::setMaximumSize(int maximumSize)
228{
229 d->maximumSize = maximumSize;
230}
231
232/*!
233 Sets the content format of the resource to \a contentFormat. The content
234 format can be one of the content formats defined in \l {CoAP Content-Formats Registry}.
235
236 \note CoAP supports common content formats such as XML, JSON, and so on, but
237 these are text based and consequently heavy both in payload and in processing.
238 One of the recommended content formats to use with CoAP is CBOR, which is
239 designed to be used in such contexts.
240
241 \sa contentFormat(), QCborStreamWriter, QCborStreamReader
242 */
243void QCoapResource::setContentFormat(uint contentFormat)
244{
245 d->contentFormat = contentFormat;
246}
247
248QT_END_NAMESPACE
249

source code of qtcoap/src/coap/qcoapresource.cpp