emqx.hrl 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. %%--------------------------------------------------------------------
  2. %% Copyright (c) 2020 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 = #{} :: emqx_types:flags(),
  52. %% Message headers. May contain any metadata. e.g. the
  53. %% protocol version number, username, peerhost or
  54. %% the PUBLISH properties (MQTT 5.0).
  55. headers = #{} :: emqx_types:headers(),
  56. %% Topic that the message is published to
  57. topic :: emqx_types:topic(),
  58. %% Message Payload
  59. payload :: emqx_types:payload(),
  60. %% Timestamp (Unit: millisecond)
  61. timestamp :: integer()
  62. }).
  63. -record(delivery, {
  64. sender :: pid(), %% Sender of the delivery
  65. message :: #message{} %% The message delivered
  66. }).
  67. %%--------------------------------------------------------------------
  68. %% Route
  69. %%--------------------------------------------------------------------
  70. -record(route, {
  71. topic :: binary(),
  72. dest :: node() | {binary(), node()}
  73. }).
  74. %%--------------------------------------------------------------------
  75. %% Trie
  76. %%--------------------------------------------------------------------
  77. -type(trie_node_id() :: binary() | atom()).
  78. -record(trie_node, {
  79. node_id :: trie_node_id(),
  80. edge_count = 0 :: non_neg_integer(),
  81. topic :: binary() | undefined,
  82. flags :: list(atom()) | undefined
  83. }).
  84. -record(trie_edge, {
  85. node_id :: trie_node_id(),
  86. word :: binary() | atom()
  87. }).
  88. -record(trie, {
  89. edge :: #trie_edge{},
  90. node_id :: trie_node_id()
  91. }).
  92. -type(trie_node() :: #trie_node{}).
  93. %%--------------------------------------------------------------------
  94. %% Plugin
  95. %%--------------------------------------------------------------------
  96. -record(plugin, {
  97. name :: atom(),
  98. dir :: string() | undefined,
  99. descr :: string(),
  100. vendor :: string() | undefined,
  101. active = false :: boolean(),
  102. info = #{} :: map(),
  103. type :: atom()
  104. }).
  105. %%--------------------------------------------------------------------
  106. %% Command
  107. %%--------------------------------------------------------------------
  108. -record(command, {
  109. name :: atom(),
  110. action :: atom(),
  111. args = [] :: list(),
  112. opts = [] :: list(),
  113. usage :: string(),
  114. descr :: string()
  115. }).
  116. %%--------------------------------------------------------------------
  117. %% Banned
  118. %%--------------------------------------------------------------------
  119. -record(banned, {
  120. who :: {clientid, binary()}
  121. | {peerhost, inet:ip_address()}
  122. | {username, binary()}
  123. | {ip_address, inet:ip_address()},
  124. by :: binary(),
  125. reason :: binary(),
  126. at :: integer(),
  127. until :: integer()
  128. }).
  129. -endif.