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

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