emqx.hrl 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. %% Copyright (c) 2013-2019 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) 2013-2019 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. }).
  62. %%--------------------------------------------------------------------
  63. %% Route
  64. %%--------------------------------------------------------------------
  65. -record(route, {
  66. topic :: binary(),
  67. dest :: node() | {binary(), node()}
  68. }).
  69. %%--------------------------------------------------------------------
  70. %% Trie
  71. %%--------------------------------------------------------------------
  72. -type(trie_node_id() :: binary() | atom()).
  73. -record(trie_node, {
  74. node_id :: trie_node_id(),
  75. edge_count = 0 :: non_neg_integer(),
  76. topic :: binary() | undefined,
  77. flags :: list(atom())
  78. }).
  79. -record(trie_edge, {
  80. node_id :: trie_node_id(),
  81. word :: binary() | atom()
  82. }).
  83. -record(trie, {
  84. edge :: #trie_edge{},
  85. node_id :: trie_node_id()
  86. }).
  87. %%--------------------------------------------------------------------
  88. %% Alarm
  89. %%--------------------------------------------------------------------
  90. -record(alarm, {
  91. id :: binary(),
  92. severity :: notice | warning | error | critical,
  93. title :: iolist(),
  94. summary :: iolist(),
  95. timestamp :: erlang:timestamp()
  96. }).
  97. %%--------------------------------------------------------------------
  98. %% Plugin
  99. %%--------------------------------------------------------------------
  100. -record(plugin, {
  101. name :: atom(),
  102. version :: string(),
  103. dir :: string(),
  104. descr :: string(),
  105. vendor :: string(),
  106. active = false :: boolean(),
  107. info :: map(),
  108. type :: atom()
  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.
  135. %%--------------------------------------------------------------------
  136. %% Compatible with Windows
  137. %%--------------------------------------------------------------------
  138. -define(compat_windows(Expression, Default),
  139. case os:type() of
  140. {win32, nt} -> Default;
  141. _Unix -> Expression
  142. end).