emqx.hrl 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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_HRL).
  17. -define(EMQ_X_HRL, true).
  18. %%--------------------------------------------------------------------
  19. %% Common
  20. %%--------------------------------------------------------------------
  21. -define(Otherwise, true).
  22. %%--------------------------------------------------------------------
  23. %% Banner
  24. %%--------------------------------------------------------------------
  25. -define(PROTOCOL_VERSION, "MQTT/5.0").
  26. -define(ERTS_MINIMUM_REQUIRED, "10.0").
  27. %%--------------------------------------------------------------------
  28. %% Configs
  29. %%--------------------------------------------------------------------
  30. -define(NO_PRIORITY_TABLE, none).
  31. %%--------------------------------------------------------------------
  32. %% Topics' prefix: $SYS | $queue | $share
  33. %%--------------------------------------------------------------------
  34. %% System topic
  35. -define(SYSTOP, <<"$SYS/">>).
  36. %% Queue topic
  37. -define(QUEUE, <<"$queue/">>).
  38. %%--------------------------------------------------------------------
  39. %% Message and Delivery
  40. %%--------------------------------------------------------------------
  41. -record(subscription, {topic, subid, subopts}).
  42. %% See 'Application Message' in MQTT Version 5.0
  43. -record(message, {
  44. %% Global unique message ID
  45. id :: binary(),
  46. %% Message QoS
  47. qos = 0,
  48. %% Message from
  49. from :: atom() | binary(),
  50. %% Message flags
  51. flags :: #{atom() => boolean()},
  52. %% Message headers, or MQTT 5.0 Properties
  53. headers = #{},
  54. %% Topic that the message is published to
  55. topic :: binary(),
  56. %% Message Payload
  57. payload :: binary(),
  58. %% Timestamp
  59. timestamp :: erlang:timestamp()
  60. }).
  61. -record(delivery, {
  62. %% Sender of the delivery
  63. sender :: pid(),
  64. %% The message delivered
  65. message :: #message{},
  66. %% Dispatches of the message
  67. results :: list()
  68. }).
  69. %%--------------------------------------------------------------------
  70. %% Route
  71. %%--------------------------------------------------------------------
  72. -record(route, {
  73. topic :: binary(),
  74. dest :: node() | {binary(), node()}
  75. }).
  76. %%--------------------------------------------------------------------
  77. %% Trie
  78. %%--------------------------------------------------------------------
  79. -type(trie_node_id() :: binary() | atom()).
  80. -record(trie_node, {
  81. node_id :: trie_node_id(),
  82. edge_count = 0 :: non_neg_integer(),
  83. topic :: binary() | undefined,
  84. flags :: list(atom())
  85. }).
  86. -record(trie_edge, {
  87. node_id :: trie_node_id(),
  88. word :: binary() | atom()
  89. }).
  90. -record(trie, {
  91. edge :: #trie_edge{},
  92. node_id :: trie_node_id()
  93. }).
  94. %%--------------------------------------------------------------------
  95. %% Alarm
  96. %%--------------------------------------------------------------------
  97. -record(alarm, {
  98. id :: binary(),
  99. severity :: notice | warning | error | critical,
  100. title :: iolist(),
  101. summary :: iolist(),
  102. timestamp :: erlang:timestamp()
  103. }).
  104. %%--------------------------------------------------------------------
  105. %% Plugin
  106. %%--------------------------------------------------------------------
  107. -record(plugin, {
  108. name :: atom(),
  109. version :: string(),
  110. dir :: string(),
  111. descr :: string(),
  112. vendor :: string(),
  113. active = false :: boolean(),
  114. info :: map(),
  115. type :: atom()
  116. }).
  117. %%--------------------------------------------------------------------
  118. %% Command
  119. %%--------------------------------------------------------------------
  120. -record(command, {
  121. name :: atom(),
  122. action :: atom(),
  123. args = [] :: list(),
  124. opts = [] :: list(),
  125. usage :: string(),
  126. descr :: string()
  127. }).
  128. %%--------------------------------------------------------------------
  129. %% Banned
  130. %%--------------------------------------------------------------------
  131. -type(banned_who() :: {client_id, binary()}
  132. | {username, binary()}
  133. | {ip_address, inet:ip_address()}).
  134. -record(banned, {
  135. who :: banned_who(),
  136. reason :: binary(),
  137. by :: binary(),
  138. desc :: binary(),
  139. until :: integer()
  140. }).
  141. -endif.