emqx.hrl 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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 :: pid(), %% Sender of the delivery
  63. message :: #message{} %% The message delivered
  64. }).
  65. %%--------------------------------------------------------------------
  66. %% Route
  67. %%--------------------------------------------------------------------
  68. -record(route, {
  69. topic :: binary(),
  70. dest :: node() | {binary(), node()}
  71. }).
  72. %%--------------------------------------------------------------------
  73. %% Trie
  74. %%--------------------------------------------------------------------
  75. -type(trie_node_id() :: binary() | atom()).
  76. -record(trie_node, {
  77. node_id :: trie_node_id(),
  78. edge_count = 0 :: non_neg_integer(),
  79. topic :: binary() | undefined,
  80. flags :: list(atom())
  81. }).
  82. -record(trie_edge, {
  83. node_id :: trie_node_id(),
  84. word :: binary() | atom()
  85. }).
  86. -record(trie, {
  87. edge :: #trie_edge{},
  88. node_id :: trie_node_id()
  89. }).
  90. %%--------------------------------------------------------------------
  91. %% Alarm
  92. %%--------------------------------------------------------------------
  93. -record(alarm, {
  94. id :: binary(),
  95. severity :: notice | warning | error | critical,
  96. title :: iolist(),
  97. summary :: iolist(),
  98. timestamp :: erlang:timestamp()
  99. }).
  100. %%--------------------------------------------------------------------
  101. %% Plugin
  102. %%--------------------------------------------------------------------
  103. -record(plugin, {
  104. name :: atom(),
  105. version :: string(),
  106. dir :: string(),
  107. descr :: string(),
  108. vendor :: string(),
  109. active = false :: boolean(),
  110. info :: map(),
  111. type :: atom()
  112. }).
  113. %%--------------------------------------------------------------------
  114. %% Command
  115. %%--------------------------------------------------------------------
  116. -record(command, {
  117. name :: atom(),
  118. action :: atom(),
  119. args = [] :: list(),
  120. opts = [] :: list(),
  121. usage :: string(),
  122. descr :: string()
  123. }).
  124. %%--------------------------------------------------------------------
  125. %% Banned
  126. %%--------------------------------------------------------------------
  127. -type(banned_who() :: {client_id, binary()}
  128. | {username, binary()}
  129. | {ip_address, inet:ip_address()}).
  130. -record(banned, {
  131. who :: banned_who(),
  132. reason :: binary(),
  133. by :: binary(),
  134. desc :: binary(),
  135. until :: integer()
  136. }).
  137. -endif.