async_mqtt 5.0.0
Loading...
Searching...
No Matches
validate_property.hpp
1// Copyright Takatoshi Kondo 2022
2//
3// Distributed under the Boost Software License, Version 1.0.
4// (See accompanying file LICENSE_1_0.txt or copy at
5// http://www.boost.org/LICENSE_1_0.txt)
6
7#if !defined(ASYNC_MQTT_PACKET_VALIDATE_PROPERTY_HPP)
8#define ASYNC_MQTT_PACKET_VALIDATE_PROPERTY_HPP
9
10
11#include <async_mqtt/packet/property_id.hpp>
12
13namespace async_mqtt {
14
15enum class property_location {
16 connect,
17 will,
18 connack,
19 publish,
20 puback,
21 pubrec,
22 pubrel,
23 pubcomp,
24 subscribe,
25 suback,
26 unsubscribe,
27 unsuback,
28 disconnect,
29 auth
30};
31
32constexpr char const* property_location_to_str(property_location v) {
33 switch (v) {
34 case property_location::connect: return "connect";
35 case property_location::will: return "will";
36 case property_location::connack: return "connack";
37 case property_location::publish: return "publish";
38 case property_location::puback: return "puback";
39 case property_location::pubrec: return "pubrec";
40 case property_location::pubrel: return "pubrel";
41 case property_location::pubcomp: return "pubcomp";
42 case property_location::subscribe: return "subscribe";
43 case property_location::suback: return "suback";
44 case property_location::unsubscribe: return "unsubscribe";
45 case property_location::unsuback: return "unsuback";
46 case property_location::disconnect: return "disconnect";
47 case property_location::auth: return "auth";
48 default: return "invalid property location";
49 }
50}
51
52constexpr bool validate_property(property_location loc, property::id id) {
53 switch (loc) {
54 case property_location::connect:
55 switch (id) {
56 case property::id::session_expiry_interval:
57 case property::id::authentication_method:
58 case property::id::authentication_data:
59 case property::id::request_problem_information:
60 case property::id::request_response_information:
61 case property::id::receive_maximum:
62 case property::id::topic_alias_maximum:
63 case property::id::user_property:
64 case property::id::maximum_packet_size:
65 return true;
66 default:
67 return false;
68 }
69 break;
70 case property_location::will:
71 switch (id) {
72 case property::id::payload_format_indicator:
73 case property::id::message_expiry_interval:
74 case property::id::content_type:
75 case property::id::response_topic:
76 case property::id::correlation_data:
77 case property::id::will_delay_interval:
78 case property::id::user_property:
79 return true;
80 default:
81 return false;
82 }
83 break;
84 case property_location::connack:
85 switch (id) {
86 case property::id::session_expiry_interval:
87 case property::id::assigned_client_identifier:
88 case property::id::server_keep_alive:
89 case property::id::authentication_method:
90 case property::id::authentication_data:
91 case property::id::response_information:
92 case property::id::server_reference:
93 case property::id::reason_string:
94 case property::id::receive_maximum:
95 case property::id::topic_alias_maximum:
96 case property::id::maximum_qos:
97 case property::id::retain_available:
98 case property::id::user_property:
99 case property::id::maximum_packet_size:
100 case property::id::wildcard_subscription_available:
101 case property::id::subscription_identifier_available:
102 case property::id::shared_subscription_available:
103 return true;
104 default:
105 return false;
106 }
107 break;
108 case property_location::publish:
109 switch (id) {
110 case property::id::payload_format_indicator:
111 case property::id::message_expiry_interval:
112 case property::id::content_type:
113 case property::id::response_topic:
114 case property::id::correlation_data:
115 case property::id::subscription_identifier:
116 case property::id::topic_alias:
117 case property::id::user_property:
118 return true;
119 default:
120 return false;
121 }
122 break;
123 case property_location::puback:
124 switch (id) {
125 case property::id::reason_string:
126 case property::id::user_property:
127 return true;
128 default:
129 return false;
130 }
131 break;
132 case property_location::pubrec:
133 switch (id) {
134 case property::id::reason_string:
135 case property::id::user_property:
136 return true;
137 default:
138 return false;
139 }
140 break;
141 case property_location::pubrel:
142 switch (id) {
143 case property::id::reason_string:
144 case property::id::user_property:
145 return true;
146 default:
147 return false;
148 }
149 break;
150 case property_location::pubcomp:
151 switch (id) {
152 case property::id::reason_string:
153 case property::id::user_property:
154 return true;
155 default:
156 return false;
157 }
158 break;
159 case property_location::subscribe:
160 switch (id) {
161 case property::id::subscription_identifier:
162 case property::id::user_property:
163 return true;
164 default:
165 return false;
166 }
167 break;
168 case property_location::suback:
169 switch (id) {
170 case property::id::reason_string:
171 case property::id::user_property:
172 return true;
173 default:
174 return false;
175 }
176 break;
177 case property_location::unsubscribe:
178 switch (id) {
179 case property::id::user_property:
180 return true;
181 default:
182 return false;
183 }
184 break;
185 case property_location::unsuback:
186 switch (id) {
187 case property::id::reason_string:
188 case property::id::user_property:
189 return true;
190 default:
191 return false;
192 }
193 break;
194 case property_location::disconnect:
195 switch (id) {
196 case property::id::session_expiry_interval:
197 case property::id::server_reference:
198 case property::id::reason_string:
199 case property::id::user_property:
200 return true;
201 default:
202 return false;
203 }
204 break;
205 case property_location::auth:
206 switch (id) {
207 case property::id::authentication_method:
208 case property::id::authentication_data:
209 case property::id::reason_string:
210 case property::id::user_property:
211 return true;
212 default:
213 return false;
214 }
215 break;
216 default:
217 break;
218 }
219 return false;
220}
221
222} // namespace async_mqtt
223
224#endif // ASYNC_MQTT_PACKET_VALIDATE_PROPERTY_HPP