| 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 <QtCoap/qcoapglobal.h> |
| 7 | #include <QtCore/qobject.h> |
| 8 | #include <QtCore/qrandom.h> |
| 9 | |
| 10 | #ifndef QCOAPNAMESPACE_H |
| 11 | #define QCOAPNAMESPACE_H |
| 12 | |
| 13 | QT_BEGIN_NAMESPACE |
| 14 | |
| 15 | #define FOR_EACH_COAP_ERROR(X) \ |
| 16 | X(BadRequest, 0x80) X(Unauthorized, 0x81) X(BadOption, 0x82) X(Forbidden, 0x83) \ |
| 17 | X(NotFound, 0x84) X(MethodNotAllowed, 0x85) X(NotAcceptable, 0x86) \ |
| 18 | X(RequestEntityIncomplete, 0x88) X(PreconditionFailed, 0x8C) X(RequestEntityTooLarge, 0x8D) \ |
| 19 | X(UnsupportedContentFormat, 0x8E) X(InternalServerFault, 0xA0) X(NotImplemented, 0xA1) \ |
| 20 | X(BadGateway, 0xA2) X(ServiceUnavailable, 0xA3) X(GatewayTimeout, 0xA4) \ |
| 21 | X(ProxyingNotSupported, 0xA5) |
| 22 | |
| 23 | namespace QtCoap |
| 24 | { |
| 25 | Q_NAMESPACE_EXPORT(Q_COAP_EXPORT) |
| 26 | |
| 27 | enum class ResponseCode : quint8 { |
| 28 | EmptyMessage = 0x00, |
| 29 | Created = 0x41, // 2.01 |
| 30 | Deleted = 0x42, // 2.02 |
| 31 | Valid = 0x43, // 2.03 |
| 32 | Changed = 0x44, // 2.04 |
| 33 | Content = 0x45, // 2.05 |
| 34 | Continue = 0x5F, // 2.31 |
| 35 | |
| 36 | #define SINGLE_CODE(name, value) name = value, |
| 37 | FOR_EACH_COAP_ERROR(SINGLE_CODE) |
| 38 | #undef SINGLE_CODE |
| 39 | |
| 40 | InvalidCode = 0xFF |
| 41 | }; |
| 42 | Q_ENUM_NS(ResponseCode) |
| 43 | |
| 44 | enum class Error : quint8 { |
| 45 | Ok, |
| 46 | HostNotFound, |
| 47 | AddressInUse, |
| 48 | TimeOut, |
| 49 | |
| 50 | #define SINGLE_ERROR(name, ignored) name, |
| 51 | FOR_EACH_COAP_ERROR(SINGLE_ERROR) |
| 52 | #undef SINGLE_ERROR |
| 53 | |
| 54 | Unknown |
| 55 | }; |
| 56 | Q_ENUM_NS(Error) |
| 57 | |
| 58 | enum class Method : quint8 { |
| 59 | Invalid, |
| 60 | Get, |
| 61 | Post, |
| 62 | Put, |
| 63 | Delete, |
| 64 | #if 0 |
| 65 | //! TODO Support other methods included in RFC 8132 |
| 66 | //! https://tools.ietf.org/html/rfc8132 |
| 67 | Fetch, |
| 68 | Patch, |
| 69 | IPatch, |
| 70 | #endif |
| 71 | Other |
| 72 | }; |
| 73 | Q_ENUM_NS(Method) |
| 74 | |
| 75 | enum Port { |
| 76 | DefaultPort = 5683, |
| 77 | DefaultSecurePort = 5684 |
| 78 | }; |
| 79 | Q_ENUM_NS(Port) |
| 80 | |
| 81 | enum class SecurityMode : quint8 { |
| 82 | NoSecurity = 0, |
| 83 | PreSharedKey, |
| 84 | RawPublicKey, |
| 85 | Certificate |
| 86 | }; |
| 87 | Q_ENUM_NS(SecurityMode) |
| 88 | |
| 89 | enum class MulticastGroup : quint8 { |
| 90 | AllCoapNodesIPv4, |
| 91 | AllCoapNodesIPv6LinkLocal, |
| 92 | AllCoapNodesIPv6SiteLocal |
| 93 | }; |
| 94 | Q_ENUM_NS(MulticastGroup) |
| 95 | |
| 96 | Q_CLASSINFO("RegisterEnumClassesUnscoped" , "false" ) |
| 97 | } |
| 98 | |
| 99 | QT_END_NAMESPACE |
| 100 | |
| 101 | Q_DECLARE_METATYPE(QtCoap::ResponseCode) |
| 102 | Q_DECLARE_METATYPE(QtCoap::Error) |
| 103 | Q_DECLARE_METATYPE(QtCoap::Method) |
| 104 | Q_DECLARE_METATYPE(QtCoap::SecurityMode) |
| 105 | Q_DECLARE_METATYPE(QtCoap::MulticastGroup) |
| 106 | |
| 107 | #endif // QCOAPNAMESPACE_H |
| 108 | |