emqx.hrl 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. %% Copyright (c) 2018 EMQ Technologies Co., Ltd. All Rights Reserved.
  2. %%
  3. %% Licensed under the Apache License, Version 2.0 (the "License");
  4. %% you may not use this file except in compliance with the License.
  5. %% You may obtain a copy of the License at
  6. %%
  7. %% http://www.apache.org/licenses/LICENSE-2.0
  8. %%
  9. %% Unless required by applicable law or agreed to in writing, software
  10. %% distributed under the License is distributed on an "AS IS" BASIS,
  11. %% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. %% See the License for the specific language governing permissions and
  13. %% limitations under the License.
  14. -ifndef(EMQ_X_HRL).
  15. -define(EMQ_X_HRL, true).
  16. %%--------------------------------------------------------------------
  17. %% Banner
  18. %%--------------------------------------------------------------------
  19. -define(COPYRIGHT, "Copyright (c) 2018 EMQ Technologies Co., Ltd").
  20. -define(LICENSE_MESSAGE, "Licensed under the Apache License, Version 2.0").
  21. -define(PROTOCOL_VERSION, "MQTT/5.0").
  22. -define(ERTS_MINIMUM_REQUIRED, "10.0").
  23. %%--------------------------------------------------------------------
  24. %% Configs
  25. %%--------------------------------------------------------------------
  26. -define(NO_PRIORITY_TABLE, none).
  27. %%--------------------------------------------------------------------
  28. %% Topics' prefix: $SYS | $queue | $share
  29. %%--------------------------------------------------------------------
  30. %% System topic
  31. -define(SYSTOP, <<"$SYS/">>).
  32. %% Queue topic
  33. -define(QUEUE, <<"$queue/">>).
  34. %%--------------------------------------------------------------------
  35. %% Message and Delivery
  36. %%--------------------------------------------------------------------
  37. -record(session, {sid, pid}).
  38. -record(subscription, {topic, subid, subopts}).
  39. %% See 'Application Message' in MQTT Version 5.0
  40. -record(message, {
  41. %% Global unique message ID
  42. id :: binary(),
  43. %% Message QoS
  44. qos = 0,
  45. %% Message from
  46. from :: atom() | binary(),
  47. %% Message flags
  48. flags :: #{atom() => boolean()},
  49. %% Message headers, or MQTT 5.0 Properties
  50. headers = #{},
  51. %% Topic that the message is published to
  52. topic :: binary(),
  53. %% Message Payload
  54. payload :: binary(),
  55. %% Timestamp
  56. timestamp :: erlang:timestamp()
  57. }).
  58. -record(delivery, {
  59. sender :: pid(), %% Sender of the delivery
  60. message :: #message{}, %% The message delivered
  61. results :: list() %% Dispatches of the message
  62. }).
  63. %%--------------------------------------------------------------------
  64. %% Route
  65. %%--------------------------------------------------------------------
  66. -record(route, {
  67. topic :: binary(),
  68. dest :: node() | {binary(), node()}
  69. }).
  70. %%--------------------------------------------------------------------
  71. %% Trie
  72. %%--------------------------------------------------------------------
  73. -type(trie_node_id() :: binary() | atom()).
  74. -record(trie_node, {
  75. node_id :: trie_node_id(),
  76. edge_count = 0 :: non_neg_integer(),
  77. topic :: binary() | undefined,
  78. flags :: list(atom())
  79. }).
  80. -record(trie_edge, {
  81. node_id :: trie_node_id(),
  82. word :: binary() | atom()
  83. }).
  84. -record(trie, {
  85. edge :: #trie_edge{},
  86. node_id :: trie_node_id()
  87. }).
  88. %%--------------------------------------------------------------------
  89. %% Alarm
  90. %%--------------------------------------------------------------------
  91. -record(alarm, {
  92. id :: binary(),
  93. severity :: notice | warning | error | critical,
  94. title :: iolist(),
  95. summary :: iolist(),
  96. timestamp :: erlang:timestamp()
  97. }).
  98. %%--------------------------------------------------------------------
  99. %% Plugin
  100. %%--------------------------------------------------------------------
  101. -record(plugin, {
  102. name :: atom(),
  103. version :: string(),
  104. dir :: string(),
  105. descr :: string(),
  106. vendor :: string(),
  107. active = false :: boolean(),
  108. info :: map()
  109. }).
  110. %%--------------------------------------------------------------------
  111. %% Command
  112. %%--------------------------------------------------------------------
  113. -record(command, {
  114. name :: atom(),
  115. action :: atom(),
  116. args = [] :: list(),
  117. opts = [] :: list(),
  118. usage :: string(),
  119. descr :: string()
  120. }).
  121. %%--------------------------------------------------------------------
  122. %% Banned
  123. %%--------------------------------------------------------------------
  124. -type(banned_who() :: {client_id, binary()}
  125. | {username, binary()}
  126. | {ip_address, inet:ip_address()}).
  127. -record(banned, {
  128. who :: banned_who(),
  129. reason :: binary(),
  130. by :: binary(),
  131. desc :: binary(),
  132. until :: integer()
  133. }).
  134. -endif.