emqx_mqtt.hrl 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  1. %%--------------------------------------------------------------------
  2. %% Copyright (c) 2019 EMQ Technologies Co., Ltd. All Rights Reserved.
  3. %%
  4. %% Licensed under the Apache License, Version 2.0 (the "License");
  5. %% you may not use this file except in compliance with the License.
  6. %% You may obtain a copy of the License at
  7. %%
  8. %% http://www.apache.org/licenses/LICENSE-2.0
  9. %%
  10. %% Unless required by applicable law or agreed to in writing, software
  11. %% distributed under the License is distributed on an "AS IS" BASIS,
  12. %% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. %% See the License for the specific language governing permissions and
  14. %% limitations under the License.
  15. %%--------------------------------------------------------------------
  16. -ifndef(EMQ_X_MQTT_HRL).
  17. -define(EMQ_X_MQTT_HRL, true).
  18. %%--------------------------------------------------------------------
  19. %% MQTT SockOpts
  20. %%--------------------------------------------------------------------
  21. -define(MQTT_SOCKOPTS, [binary, {packet, raw}, {reuseaddr, true},
  22. {backlog, 512}, {nodelay, true}]).
  23. %%--------------------------------------------------------------------
  24. %% MQTT Protocol Version and Names
  25. %%--------------------------------------------------------------------
  26. -define(MQTT_PROTO_V3, 3).
  27. -define(MQTT_PROTO_V4, 4).
  28. -define(MQTT_PROTO_V5, 5).
  29. -define(PROTOCOL_NAMES, [
  30. {?MQTT_PROTO_V3, <<"MQIsdp">>},
  31. {?MQTT_PROTO_V4, <<"MQTT">>},
  32. {?MQTT_PROTO_V5, <<"MQTT">>}]).
  33. %%--------------------------------------------------------------------
  34. %% MQTT QoS Levels
  35. %%--------------------------------------------------------------------
  36. -define(QOS_0, 0). %% At most once
  37. -define(QOS_1, 1). %% At least once
  38. -define(QOS_2, 2). %% Exactly once
  39. -define(IS_QOS(I), (I >= ?QOS_0 andalso I =< ?QOS_2)).
  40. -define(QOS_I(Name),
  41. begin
  42. (case Name of
  43. ?QOS_0 -> ?QOS_0;
  44. qos0 -> ?QOS_0;
  45. at_most_once -> ?QOS_0;
  46. ?QOS_1 -> ?QOS_1;
  47. qos1 -> ?QOS_1;
  48. at_least_once -> ?QOS_1;
  49. ?QOS_2 -> ?QOS_2;
  50. qos2 -> ?QOS_2;
  51. exactly_once -> ?QOS_2
  52. end)
  53. end).
  54. -define(IS_QOS_NAME(I),
  55. (I =:= qos0 orelse I =:= at_most_once orelse
  56. I =:= qos1 orelse I =:= at_least_once orelse
  57. I =:= qos2 orelse I =:= exactly_once)).
  58. %%--------------------------------------------------------------------
  59. %% Maximum ClientId Length.
  60. %%--------------------------------------------------------------------
  61. -define(MAX_CLIENTID_LEN, 65535).
  62. %%--------------------------------------------------------------------
  63. %% MQTT Control Packet Types
  64. %%--------------------------------------------------------------------
  65. -define(RESERVED, 0). %% Reserved
  66. -define(CONNECT, 1). %% Client request to connect to Server
  67. -define(CONNACK, 2). %% Server to Client: Connect acknowledgment
  68. -define(PUBLISH, 3). %% Publish message
  69. -define(PUBACK, 4). %% Publish acknowledgment
  70. -define(PUBREC, 5). %% Publish received (assured delivery part 1)
  71. -define(PUBREL, 6). %% Publish release (assured delivery part 2)
  72. -define(PUBCOMP, 7). %% Publish complete (assured delivery part 3)
  73. -define(SUBSCRIBE, 8). %% Client subscribe request
  74. -define(SUBACK, 9). %% Server Subscribe acknowledgment
  75. -define(UNSUBSCRIBE, 10). %% Unsubscribe request
  76. -define(UNSUBACK, 11). %% Unsubscribe acknowledgment
  77. -define(PINGREQ, 12). %% PING request
  78. -define(PINGRESP, 13). %% PING response
  79. -define(DISCONNECT, 14). %% Client or Server is disconnecting
  80. -define(AUTH, 15). %% Authentication exchange
  81. -define(TYPE_NAMES, [
  82. 'CONNECT',
  83. 'CONNACK',
  84. 'PUBLISH',
  85. 'PUBACK',
  86. 'PUBREC',
  87. 'PUBREL',
  88. 'PUBCOMP',
  89. 'SUBSCRIBE',
  90. 'SUBACK',
  91. 'UNSUBSCRIBE',
  92. 'UNSUBACK',
  93. 'PINGREQ',
  94. 'PINGRESP',
  95. 'DISCONNECT',
  96. 'AUTH']).
  97. %%--------------------------------------------------------------------
  98. %% MQTT V3.1.1 Connect Return Codes
  99. %%--------------------------------------------------------------------
  100. -define(CONNACK_ACCEPT, 0). %% Connection accepted
  101. -define(CONNACK_PROTO_VER, 1). %% Unacceptable protocol version
  102. -define(CONNACK_INVALID_ID, 2). %% Client Identifier is correct UTF-8 but not allowed by the Server
  103. -define(CONNACK_SERVER, 3). %% Server unavailable
  104. -define(CONNACK_CREDENTIALS, 4). %% Username or password is malformed
  105. -define(CONNACK_AUTH, 5). %% Client is not authorized to connect
  106. %%--------------------------------------------------------------------
  107. %% MQTT V5.0 Reason Codes
  108. %%--------------------------------------------------------------------
  109. -define(RC_SUCCESS, 16#00).
  110. -define(RC_NORMAL_DISCONNECTION, 16#00).
  111. -define(RC_GRANTED_QOS_0, 16#00).
  112. -define(RC_GRANTED_QOS_1, 16#01).
  113. -define(RC_GRANTED_QOS_2, 16#02).
  114. -define(RC_DISCONNECT_WITH_WILL_MESSAGE, 16#04).
  115. -define(RC_NO_MATCHING_SUBSCRIBERS, 16#10).
  116. -define(RC_NO_SUBSCRIPTION_EXISTED, 16#11).
  117. -define(RC_CONTINUE_AUTHENTICATION, 16#18).
  118. -define(RC_RE_AUTHENTICATE, 16#19).
  119. -define(RC_UNSPECIFIED_ERROR, 16#80).
  120. -define(RC_MALFORMED_PACKET, 16#81).
  121. -define(RC_PROTOCOL_ERROR, 16#82).
  122. -define(RC_IMPLEMENTATION_SPECIFIC_ERROR, 16#83).
  123. -define(RC_UNSUPPORTED_PROTOCOL_VERSION, 16#84).
  124. -define(RC_CLIENT_IDENTIFIER_NOT_VALID, 16#85).
  125. -define(RC_BAD_USER_NAME_OR_PASSWORD, 16#86).
  126. -define(RC_NOT_AUTHORIZED, 16#87).
  127. -define(RC_SERVER_UNAVAILABLE, 16#88).
  128. -define(RC_SERVER_BUSY, 16#89).
  129. -define(RC_BANNED, 16#8A).
  130. -define(RC_SERVER_SHUTTING_DOWN, 16#8B).
  131. -define(RC_BAD_AUTHENTICATION_METHOD, 16#8C).
  132. -define(RC_KEEP_ALIVE_TIMEOUT, 16#8D).
  133. -define(RC_SESSION_TAKEN_OVER, 16#8E).
  134. -define(RC_TOPIC_FILTER_INVALID, 16#8F).
  135. -define(RC_TOPIC_NAME_INVALID, 16#90).
  136. -define(RC_PACKET_IDENTIFIER_IN_USE, 16#91).
  137. -define(RC_PACKET_IDENTIFIER_NOT_FOUND, 16#92).
  138. -define(RC_RECEIVE_MAXIMUM_EXCEEDED, 16#93).
  139. -define(RC_TOPIC_ALIAS_INVALID, 16#94).
  140. -define(RC_PACKET_TOO_LARGE, 16#95).
  141. -define(RC_MESSAGE_RATE_TOO_HIGH, 16#96).
  142. -define(RC_QUOTA_EXCEEDED, 16#97).
  143. -define(RC_ADMINISTRATIVE_ACTION, 16#98).
  144. -define(RC_PAYLOAD_FORMAT_INVALID, 16#99).
  145. -define(RC_RETAIN_NOT_SUPPORTED, 16#9A).
  146. -define(RC_QOS_NOT_SUPPORTED, 16#9B).
  147. -define(RC_USE_ANOTHER_SERVER, 16#9C).
  148. -define(RC_SERVER_MOVED, 16#9D).
  149. -define(RC_SHARED_SUBSCRIPTIONS_NOT_SUPPORTED, 16#9E).
  150. -define(RC_CONNECTION_RATE_EXCEEDED, 16#9F).
  151. -define(RC_MAXIMUM_CONNECT_TIME, 16#A0).
  152. -define(RC_SUBSCRIPTION_IDENTIFIERS_NOT_SUPPORTED, 16#A1).
  153. -define(RC_WILDCARD_SUBSCRIPTIONS_NOT_SUPPORTED, 16#A2).
  154. %%--------------------------------------------------------------------
  155. %% Maximum MQTT Packet ID and Length
  156. %%--------------------------------------------------------------------
  157. -define(MAX_PACKET_ID, 16#ffff).
  158. -define(MAX_PACKET_SIZE, 16#fffffff).
  159. %%--------------------------------------------------------------------
  160. %% MQTT Frame Mask
  161. %%--------------------------------------------------------------------
  162. -define(HIGHBIT, 2#10000000).
  163. -define(LOWBITS, 2#01111111).
  164. %%--------------------------------------------------------------------
  165. %% MQTT Packet Fixed Header
  166. %%--------------------------------------------------------------------
  167. -record(mqtt_packet_header, {
  168. type = ?RESERVED,
  169. dup = false,
  170. qos = ?QOS_0,
  171. retain = false
  172. }).
  173. %%--------------------------------------------------------------------
  174. %% MQTT Packets
  175. %%--------------------------------------------------------------------
  176. -define(DEFAULT_SUBOPTS, #{rh => 0, %% Retain Handling
  177. rap => 0, %% Retain as Publish
  178. nl => 0, %% No Local
  179. qos => 0 %% QoS
  180. }).
  181. -record(mqtt_packet_connect, {
  182. proto_name = <<"MQTT">>,
  183. proto_ver = ?MQTT_PROTO_V4,
  184. is_bridge = false,
  185. clean_start = true,
  186. will_flag = false,
  187. will_qos = ?QOS_0,
  188. will_retain = false,
  189. keepalive = 0,
  190. properties = undefined,
  191. client_id = <<>>,
  192. will_props = undefined,
  193. will_topic = undefined,
  194. will_payload = undefined,
  195. username = undefined,
  196. password = undefined
  197. }).
  198. -record(mqtt_packet_connack, {
  199. ack_flags,
  200. reason_code,
  201. properties
  202. }).
  203. -record(mqtt_packet_publish, {
  204. topic_name,
  205. packet_id,
  206. properties
  207. }).
  208. -record(mqtt_packet_puback, {
  209. packet_id,
  210. reason_code,
  211. properties
  212. }).
  213. -record(mqtt_packet_subscribe, {
  214. packet_id,
  215. properties,
  216. topic_filters
  217. }).
  218. -record(mqtt_packet_suback, {
  219. packet_id,
  220. properties,
  221. reason_codes
  222. }).
  223. -record(mqtt_packet_unsubscribe, {
  224. packet_id,
  225. properties,
  226. topic_filters
  227. }).
  228. -record(mqtt_packet_unsuback, {
  229. packet_id,
  230. properties,
  231. reason_codes
  232. }).
  233. -record(mqtt_packet_disconnect, {
  234. reason_code,
  235. properties
  236. }).
  237. -record(mqtt_packet_auth, {
  238. reason_code,
  239. properties
  240. }).
  241. %%--------------------------------------------------------------------
  242. %% MQTT Control Packet
  243. %%--------------------------------------------------------------------
  244. -record(mqtt_packet, {
  245. header :: #mqtt_packet_header{},
  246. variable :: #mqtt_packet_connect{}
  247. | #mqtt_packet_connack{}
  248. | #mqtt_packet_publish{}
  249. | #mqtt_packet_puback{}
  250. | #mqtt_packet_subscribe{}
  251. | #mqtt_packet_suback{}
  252. | #mqtt_packet_unsubscribe{}
  253. | #mqtt_packet_unsuback{}
  254. | #mqtt_packet_disconnect{}
  255. | #mqtt_packet_auth{}
  256. | pos_integer()
  257. | undefined,
  258. payload :: binary() | undefined
  259. }).
  260. %%--------------------------------------------------------------------
  261. %% MQTT Message Internal
  262. %%--------------------------------------------------------------------
  263. -record(mqtt_msg, {
  264. qos = ?QOS_0,
  265. retain = false,
  266. dup = false,
  267. packet_id,
  268. topic,
  269. props,
  270. payload
  271. }).
  272. %%--------------------------------------------------------------------
  273. %% MQTT Packet Match
  274. %%--------------------------------------------------------------------
  275. -define(CONNECT_PACKET(Var),
  276. #mqtt_packet{header = #mqtt_packet_header{type = ?CONNECT},
  277. variable = Var}).
  278. -define(CONNACK_PACKET(ReasonCode),
  279. #mqtt_packet{header = #mqtt_packet_header{type = ?CONNACK},
  280. variable = #mqtt_packet_connack{ack_flags = 0,
  281. reason_code = ReasonCode}
  282. }).
  283. -define(CONNACK_PACKET(ReasonCode, SessPresent),
  284. #mqtt_packet{header = #mqtt_packet_header{type = ?CONNACK},
  285. variable = #mqtt_packet_connack{ack_flags = SessPresent,
  286. reason_code = ReasonCode}
  287. }).
  288. -define(CONNACK_PACKET(ReasonCode, SessPresent, Properties),
  289. #mqtt_packet{header = #mqtt_packet_header{type = ?CONNACK},
  290. variable = #mqtt_packet_connack{ack_flags = SessPresent,
  291. reason_code = ReasonCode,
  292. properties = Properties}
  293. }).
  294. -define(AUTH_PACKET(),
  295. #mqtt_packet{header = #mqtt_packet_header{type = ?AUTH},
  296. variable = #mqtt_packet_auth{reason_code = 0}
  297. }).
  298. -define(AUTH_PACKET(ReasonCode),
  299. #mqtt_packet{header = #mqtt_packet_header{type = ?AUTH},
  300. variable = #mqtt_packet_auth{reason_code = ReasonCode}
  301. }).
  302. -define(AUTH_PACKET(ReasonCode, Properties),
  303. #mqtt_packet{header = #mqtt_packet_header{type = ?AUTH},
  304. variable = #mqtt_packet_auth{reason_code = ReasonCode,
  305. properties = Properties}
  306. }).
  307. -define(PUBLISH_PACKET(QoS),
  308. #mqtt_packet{header = #mqtt_packet_header{type = ?PUBLISH, qos = QoS}}).
  309. -define(PUBLISH_PACKET(QoS, PacketId),
  310. #mqtt_packet{header = #mqtt_packet_header{type = ?PUBLISH,
  311. qos = QoS},
  312. variable = #mqtt_packet_publish{packet_id = PacketId}
  313. }).
  314. -define(PUBLISH_PACKET(QoS, Topic, PacketId),
  315. #mqtt_packet{header = #mqtt_packet_header{type = ?PUBLISH,
  316. qos = QoS},
  317. variable = #mqtt_packet_publish{topic_name = Topic,
  318. packet_id = PacketId}
  319. }).
  320. -define(PUBLISH_PACKET(QoS, Topic, PacketId, Payload),
  321. #mqtt_packet{header = #mqtt_packet_header{type = ?PUBLISH,
  322. qos = QoS},
  323. variable = #mqtt_packet_publish{topic_name = Topic,
  324. packet_id = PacketId},
  325. payload = Payload
  326. }).
  327. -define(PUBLISH_PACKET(QoS, Topic, PacketId, Properties, Payload),
  328. #mqtt_packet{header = #mqtt_packet_header{type = ?PUBLISH,
  329. qos = QoS},
  330. variable = #mqtt_packet_publish{topic_name = Topic,
  331. packet_id = PacketId,
  332. properties = Properties},
  333. payload = Payload
  334. }).
  335. -define(PUBACK_PACKET(PacketId),
  336. #mqtt_packet{header = #mqtt_packet_header{type = ?PUBACK},
  337. variable = #mqtt_packet_puback{packet_id = PacketId,
  338. reason_code = 0}
  339. }).
  340. -define(PUBACK_PACKET(PacketId, ReasonCode),
  341. #mqtt_packet{header = #mqtt_packet_header{type = ?PUBACK},
  342. variable = #mqtt_packet_puback{packet_id = PacketId,
  343. reason_code = ReasonCode}
  344. }).
  345. -define(PUBACK_PACKET(PacketId, ReasonCode, Properties),
  346. #mqtt_packet{header = #mqtt_packet_header{type = ?PUBACK},
  347. variable = #mqtt_packet_puback{packet_id = PacketId,
  348. reason_code = ReasonCode,
  349. properties = Properties}
  350. }).
  351. -define(PUBREC_PACKET(PacketId),
  352. #mqtt_packet{header = #mqtt_packet_header{type = ?PUBREC},
  353. variable = #mqtt_packet_puback{packet_id = PacketId,
  354. reason_code = 0}
  355. }).
  356. -define(PUBREC_PACKET(PacketId, ReasonCode),
  357. #mqtt_packet{header = #mqtt_packet_header{type = ?PUBREC},
  358. variable = #mqtt_packet_puback{packet_id = PacketId,
  359. reason_code = ReasonCode}
  360. }).
  361. -define(PUBREC_PACKET(PacketId, ReasonCode, Properties),
  362. #mqtt_packet{header = #mqtt_packet_header{type = ?PUBREC},
  363. variable = #mqtt_packet_puback{packet_id = PacketId,
  364. reason_code = ReasonCode,
  365. properties = Properties}
  366. }).
  367. -define(PUBREL_PACKET(PacketId),
  368. #mqtt_packet{header = #mqtt_packet_header{type = ?PUBREL,
  369. qos = ?QOS_1},
  370. variable = #mqtt_packet_puback{packet_id = PacketId,
  371. reason_code = 0}
  372. }).
  373. -define(PUBREL_PACKET(PacketId, ReasonCode),
  374. #mqtt_packet{header = #mqtt_packet_header{type = ?PUBREL,
  375. qos = ?QOS_1},
  376. variable = #mqtt_packet_puback{packet_id = PacketId,
  377. reason_code = ReasonCode}
  378. }).
  379. -define(PUBREL_PACKET(PacketId, ReasonCode, Properties),
  380. #mqtt_packet{header = #mqtt_packet_header{type = ?PUBREL,
  381. qos = ?QOS_1},
  382. variable = #mqtt_packet_puback{packet_id = PacketId,
  383. reason_code = ReasonCode,
  384. properties = Properties}
  385. }).
  386. -define(PUBCOMP_PACKET(PacketId),
  387. #mqtt_packet{header = #mqtt_packet_header{type = ?PUBCOMP},
  388. variable = #mqtt_packet_puback{packet_id = PacketId,
  389. reason_code = 0}
  390. }).
  391. -define(PUBCOMP_PACKET(PacketId, ReasonCode),
  392. #mqtt_packet{header = #mqtt_packet_header{type = ?PUBCOMP},
  393. variable = #mqtt_packet_puback{packet_id = PacketId,
  394. reason_code = ReasonCode}
  395. }).
  396. -define(PUBCOMP_PACKET(PacketId, ReasonCode, Properties),
  397. #mqtt_packet{header = #mqtt_packet_header{type = ?PUBCOMP},
  398. variable = #mqtt_packet_puback{packet_id = PacketId,
  399. reason_code = ReasonCode,
  400. properties = Properties}
  401. }).
  402. -define(SUBSCRIBE_PACKET(PacketId, TopicFilters),
  403. #mqtt_packet{header = #mqtt_packet_header{type = ?SUBSCRIBE,
  404. qos = ?QOS_1},
  405. variable = #mqtt_packet_subscribe{packet_id = PacketId,
  406. topic_filters = TopicFilters}
  407. }).
  408. -define(SUBSCRIBE_PACKET(PacketId, Properties, TopicFilters),
  409. #mqtt_packet{header = #mqtt_packet_header{type = ?SUBSCRIBE,
  410. qos = ?QOS_1},
  411. variable = #mqtt_packet_subscribe{packet_id = PacketId,
  412. properties = Properties,
  413. topic_filters = TopicFilters}
  414. }).
  415. -define(SUBACK_PACKET(PacketId, ReasonCodes),
  416. #mqtt_packet{header = #mqtt_packet_header{type = ?SUBACK},
  417. variable = #mqtt_packet_suback{packet_id = PacketId,
  418. reason_codes = ReasonCodes}
  419. }).
  420. -define(SUBACK_PACKET(PacketId, Properties, ReasonCodes),
  421. #mqtt_packet{header = #mqtt_packet_header{type = ?SUBACK},
  422. variable = #mqtt_packet_suback{packet_id = PacketId,
  423. properties = Properties,
  424. reason_codes = ReasonCodes}
  425. }).
  426. -define(UNSUBSCRIBE_PACKET(PacketId, TopicFilters),
  427. #mqtt_packet{header = #mqtt_packet_header{type = ?UNSUBSCRIBE,
  428. qos = ?QOS_1},
  429. variable = #mqtt_packet_unsubscribe{packet_id = PacketId,
  430. topic_filters = TopicFilters}
  431. }).
  432. -define(UNSUBSCRIBE_PACKET(PacketId, Properties, TopicFilters),
  433. #mqtt_packet{header = #mqtt_packet_header{type = ?UNSUBSCRIBE,
  434. qos = ?QOS_1},
  435. variable = #mqtt_packet_unsubscribe{packet_id = PacketId,
  436. properties = Properties,
  437. topic_filters = TopicFilters}
  438. }).
  439. -define(UNSUBACK_PACKET(PacketId),
  440. #mqtt_packet{header = #mqtt_packet_header{type = ?UNSUBACK},
  441. variable = #mqtt_packet_unsuback{packet_id = PacketId}
  442. }).
  443. -define(UNSUBACK_PACKET(PacketId, ReasonCodes),
  444. #mqtt_packet{header = #mqtt_packet_header{type = ?UNSUBACK},
  445. variable = #mqtt_packet_unsuback{packet_id = PacketId,
  446. reason_codes = ReasonCodes}
  447. }).
  448. -define(UNSUBACK_PACKET(PacketId, Properties, ReasonCodes),
  449. #mqtt_packet{header = #mqtt_packet_header{type = ?UNSUBACK},
  450. variable = #mqtt_packet_unsuback{packet_id = PacketId,
  451. properties = Properties,
  452. reason_codes = ReasonCodes}
  453. }).
  454. -define(DISCONNECT_PACKET(),
  455. #mqtt_packet{header = #mqtt_packet_header{type = ?DISCONNECT},
  456. variable = #mqtt_packet_disconnect{reason_code = 0}
  457. }).
  458. -define(DISCONNECT_PACKET(ReasonCode),
  459. #mqtt_packet{header = #mqtt_packet_header{type = ?DISCONNECT},
  460. variable = #mqtt_packet_disconnect{reason_code = ReasonCode}
  461. }).
  462. -define(DISCONNECT_PACKET(ReasonCode, Properties),
  463. #mqtt_packet{header = #mqtt_packet_header{type = ?DISCONNECT},
  464. variable = #mqtt_packet_disconnect{reason_code = ReasonCode,
  465. properties = Properties}
  466. }).
  467. -define(PACKET(Type), #mqtt_packet{header = #mqtt_packet_header{type = Type}}).
  468. -define(SHARE, "$share").
  469. -define(SHARE(Group, Topic), emqx_topic:join([<<?SHARE>>, Group, Topic])).
  470. -define(IS_SHARE(Topic), case Topic of <<?SHARE, _/binary>> -> true; _ -> false end).
  471. -endif.