1// Copyright (C) 2019 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#include "qcoapnamespace_p.h"
6
7QT_BEGIN_NAMESPACE
8
9/*!
10 \namespace QtCoap
11
12 \inmodule QtCoap
13 \brief Contains miscellaneous identifiers used throughout the Qt CoAP module.
14 \keyword {QtCoap Namespace}
15*/
16
17/*!
18 \enum QtCoap::ResponseCode
19
20 This enum represents the response code from the CoAP protocol, as defined in
21 \l{https://tools.ietf.org/html/rfc7252#section-5.9}{RFC 7252} and
22 \l{https://tools.ietf.org/html/rfc7959#section-2.9}{RFC 7959}.
23
24 \value EmptyMessage The response code for an empty message.
25
26 \value Created The request was successful and has resulted in new resources
27 being created.
28 This response code corresponds to HTTP 201 "Created".
29
30 \value Deleted The resource has been successfully deleted. This response code
31 corresponds to HTTP 204 "No Content" but is only used in
32 response to requests that cause the resource to cease being
33 available, such as DELETE and, in certain circumstances, POST.
34
35 \value Valid This response code is related to HTTP 304 "Not Modified" but
36 is only used to indicate that the response identified by the
37 entity-tag given in the ETag Option is valid.
38
39 \value Changed The resource has been successfully modified.
40 This response code corresponds to HTTP 204 "No Content" but
41 is only used in response to POST and PUT requests.
42
43 \value Content The request has succeeded. This response code corresponds to
44 HTTP 200 "OK" but is only used in response to GET requests.
45
46 \value Continue Indicates that the transfer of the current block was successful,
47 and the server will send more blocks.
48
49 \value BadRequest The request was not recognized.
50 This response code corresponds to HTTP 400 "Bad Request".
51
52 \value Unauthorized The client is not authorized to perform the requested action.
53 This response code corresponds to HTTP 401 "Unauthorized".
54
55 \value BadOption The request could not be understood by the server due to
56 unrecognized options.
57
58 \value Forbidden Access to this resource is forbidden.
59 This response code corresponds to HTTP 403 "Forbidden".
60
61 \value NotFound The resource requested was not found.
62 This response code corresponds to HTTP 404 "Not Found".
63
64 \value MethodNotAllowed The server does not allow the method used for the URL requested.
65 This response code corresponds to HTTP 405 "Method Not Allowed"
66 but with no parallel to the "Allow" header field.
67
68 \value NotAcceptable No resource satisfying the request's acceptance criteria
69 was found. This response code corresponds to HTTP 406
70 "Not Acceptable", but with no response entity.
71
72 \value RequestEntityIncomplete The server has not received all blocks, of the request body,
73 that it needs to proceed.
74
75 \value PreconditionFailed Preconditions given in the request header fields evaluated to
76 \c false when tested on the server.
77 This response code corresponds to HTTP 412
78 "Precondition Failed".
79
80 \value RequestEntityTooLarge The request payload is larger than the server is willing or
81 able to process. This response code corresponds to HTTP 413
82 "Request Entity Too Large".
83
84 \value UnsupportedContentFormat The payload is in a format not supported by this method on
85 the target resource. This response code corresponds to HTTP 415
86 "Unsupported Media Type".
87
88 \value InternalServerFault The server encountered an unexpected condition that prevented
89 it from fulfilling the request. This response code corresponds
90 to HTTP 500 "Internal Server Error".
91
92 \value NotImplemented The server does not support the functionality required to
93 fulfill the request. This response code corresponds to HTTP 501
94 "Not Implemented".
95
96 \value BadGateway An error occurred with an upstream server.
97 This response code corresponds to HTTP 502 "Bad Gateway".
98
99 \value ServiceUnavailable The service is currently unavailable.
100 This response code corresponds to HTTP 503
101 "Service Unavailable".
102
103 \value GatewayTimeout The server, while acting as a gateway or proxy, did not
104 receive a timely response from an upstream server.
105 This response code corresponds to HTTP 504 "Gateway Timeout".
106
107 \value ProxyingNotSupported The server is unable or unwilling to act as a forward-proxy
108 for the URI specified in the Proxy-Uri Option or using
109 the scheme specified in Proxy-Scheme.
110
111 \value InvalidCode An invalid response code.
112*/
113
114/*!
115 \enum QtCoap::Error
116
117 Indicates the error condition found during processing of the request.
118
119 \value Ok No error condition.
120
121 \value HostNotFound The remote host name was not found.
122
123 \value AddressInUse The address is already in use.
124
125 \value TimeOut The response did not arrive in time.
126
127 \value BadRequest The request was not recognized.
128
129 \value Unauthorized The client is not authorized to perform
130 the requested action.
131
132 \value BadOption The request could not be understood by
133 the server due to one or more unrecognized
134 or malformed options.
135
136 \value Forbidden Access to this resource is forbidden.
137
138 \value NotFound The resource requested was not found.
139
140 \value MethodNotAllowed The server does not allow the method used
141 for the URL requested.
142
143 \value NotAcceptable No resource satisfying the request's acceptance
144 criteria was found.
145
146 \value RequestEntityIncomplete The server has not received the blocks of
147 the request body that it needs to proceed.
148 The client has not sent all blocks,
149 has not sent them in the order required by the
150 server, or sent them long enough ago
151 that the server has already discarded them.
152
153 \value PreconditionFailed One or more conditions given in the request
154 header fields evaluated to false when tested
155 on the server.
156
157 \value RequestEntityTooLarge The request payload is larger than the
158 server is willing or able to process.
159
160 \value UnsupportedContentFormat The payload is in a format not supported
161 by this method on the target resource.
162
163 \value InternalServerFault The server encountered an unexpected
164 condition that prevented it from
165 fulfilling the request.
166
167 \value NotImplemented The server does not support the
168 functionality required to fulfill the
169 request.
170
171 \value BadGateway An error occurred with an upstream
172 server.
173
174 \value ServiceUnavailable The service is currently unavailable.
175
176 \value GatewayTimeout The server, while acting as a gateway
177 or proxy, did not receive a timely
178 response from an upstream server it needed
179 to access in order to complete the request.
180
181 \value ProxyingNotSupported The server is unable or unwilling to act
182 as a forward-proxy for the URI specified
183 in the Proxy-Uri Option or using the scheme
184 specified in Proxy-Scheme.
185
186 \value Unknown An unknown error occurred.
187*/
188
189/*!
190 \enum QtCoap::Method
191
192 This enum specifies CoAP request methods.
193
194 \value Invalid The default request method for an empty request.
195 \value Get GET method.
196 \value Post POST method.
197 \value Put PUT method.
198 \value Delete DELETE method.
199 \value Other Other request method.
200*/
201
202/*!
203 \enum QtCoap::Port
204
205 This enum specifies the default CoAP port values.
206
207 \value DefaultPort The default port used for the non-secure transmission.
208 \value DefaultSecurePort The default port used for the secure transmission.
209*/
210
211/*!
212 \enum QtCoap::SecurityMode
213
214 Specifies the security mode used for securing a CoAP connection, as defined in
215 \l{https://tools.ietf.org/html/rfc7252#section-9}{RFC 7252}.
216
217 \value NoSecurity There is no protocol-level security (DTLS is disabled).
218
219 \value PreSharedKey DTLS is enabled. PSK authentication will be used for security.
220
221 \value RawPublicKey DTLS is enabled. An asymmetric key pair without a certificate
222 (a raw public key) will be used for security. This mode is not
223 supported yet.
224
225 \value Certificate DTLS is enabled. An asymmetric key pair with an X.509 certificate
226 will be used for security.
227*/
228
229/*!
230 \enum QtCoap::MulticastGroup
231
232 This enum represents CoAP multicast group addresses defined in
233 \l{https://tools.ietf.org/html/rfc7252#section-12.8}{RFC 7252}.
234
235 \value AllCoapNodesIPv4 IPv4 "All CoAP Nodes" address \e {224.0.1.187}, from
236 the "IPv4 Multicast Address Space Registry".
237
238 \value AllCoapNodesIPv6LinkLocal IPv6 "All CoAP Nodes" link-local scoped address
239 \e {FF02::FD}, from the "IPv6 Multicast Address Space
240 Registry".
241
242 \value AllCoapNodesIPv6SiteLocal IPv6 "All CoAP Nodes" site-local scoped address
243 \e {FF05::FD}, from the "IPv6 Multicast Address Space
244 Registry".
245*/
246
247/*!
248 \internal
249
250 Returns \c true if \a code corresponds to an error, returns \c false otherwise.
251*/
252bool QtCoap::isError(QtCoap::ResponseCode code)
253{
254 return static_cast<int>(code) >= 0x80;
255}
256
257/*!
258 \internal
259
260 Returns the QtCoap::Error corresponding to the \a code passed to this
261 method.
262*/
263QtCoap::Error QtCoap::errorForResponseCode(QtCoap::ResponseCode code)
264{
265 if (!isError(code))
266 return QtCoap::Error::Ok;
267
268 switch (code) {
269#define SINGLE_CASE(name, ignored) case ResponseCode::name: return Error::name;
270 FOR_EACH_COAP_ERROR(SINGLE_CASE)
271#undef SINGLE_CASE
272 default:
273 return Error::Unknown;
274 }
275}
276
277/*!
278 \internal
279
280 Returns the internal random generator used for generating token values and
281 message IDs.
282*/
283QRandomGenerator &QtCoap::randomGenerator()
284{
285 static QRandomGenerator randomGenerator = QRandomGenerator::securelySeeded();
286 return randomGenerator;
287}
288
289QT_END_NAMESPACE
290

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