emqttd.hrl 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. %%%-----------------------------------------------------------------------------
  2. %%% Copyright (c) 2012-2015 eMQTT.IO, All Rights Reserved.
  3. %%%
  4. %%% Permission is hereby granted, free of charge, to any person obtaining a copy
  5. %%% of this software and associated documentation files (the "Software"), to deal
  6. %%% in the Software without restriction, including without limitation the rights
  7. %%% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. %%% copies of the Software, and to permit persons to whom the Software is
  9. %%% furnished to do so, subject to the following conditions:
  10. %%%
  11. %%% The above copyright notice and this permission notice shall be included in all
  12. %%% copies or substantial portions of the Software.
  13. %%%
  14. %%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. %%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. %%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. %%% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. %%% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. %%% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. %%% SOFTWARE.
  21. %%%-----------------------------------------------------------------------------
  22. %%% @doc
  23. %%% MQTT Broker Header.
  24. %%%
  25. %%% @end
  26. %%%-----------------------------------------------------------------------------
  27. %%------------------------------------------------------------------------------
  28. %% Banner
  29. %%------------------------------------------------------------------------------
  30. -define(COPYRIGHT, "Copyright (C) 2012-2015, Feng Lee <feng@emqtt.io>").
  31. -define(LICENSE_MESSAGE, "Licensed under MIT").
  32. -define(PROTOCOL_VERSION, "MQTT/3.1.1").
  33. -define(ERTS_MINIMUM, "6.0").
  34. %% System Topics.
  35. -define(SYSTOP, <<"$SYS">>).
  36. %% Queue Topics.
  37. -define(QTop, <<"$Q">>).
  38. %%------------------------------------------------------------------------------
  39. %% PubSub
  40. %%------------------------------------------------------------------------------
  41. -type pubsub() :: publish | subscribe.
  42. -define(IS_PUBSUB(PS), (PS =:= publish orelse PS =:= subscribe)).
  43. %%------------------------------------------------------------------------------
  44. %% MQTT Topic
  45. %%------------------------------------------------------------------------------
  46. -record(mqtt_topic, {
  47. topic :: binary(),
  48. node :: node()
  49. }).
  50. -type mqtt_topic() :: #mqtt_topic{}.
  51. %%------------------------------------------------------------------------------
  52. %% MQTT Subscriber
  53. %%------------------------------------------------------------------------------
  54. -record(mqtt_subscriber, {
  55. topic :: binary(),
  56. subpid :: pid(),
  57. qos = 0 :: 0 | 1 | 2
  58. }).
  59. -type mqtt_subscriber() :: #mqtt_subscriber{}.
  60. %%------------------------------------------------------------------------------
  61. %% P2P Queue Subscriber
  62. %%------------------------------------------------------------------------------
  63. -record(mqtt_queue, {
  64. name :: binary(),
  65. qpid :: pid(),
  66. qos = 0 :: 0 | 1 | 2
  67. }).
  68. -type mqtt_queue() :: #mqtt_queue{}.
  69. %%------------------------------------------------------------------------------
  70. %% MQTT Client
  71. %%------------------------------------------------------------------------------
  72. -type header_key() :: atom() | binary() | string().
  73. -type header_val() :: atom() | binary() | string() | integer().
  74. -record(mqtt_client, {
  75. client_id :: binary() | undefined,
  76. client_pid :: pid(),
  77. username :: binary() | undefined,
  78. peername :: {inet:ip_address(), integer()},
  79. clean_sess :: boolean(),
  80. proto_ver :: 3 | 4,
  81. keepalive = 0,
  82. will_topic :: undefined | binary(),
  83. ws_initial_headers :: list({header_key(), header_val()}),
  84. connected_at :: erlang:timestamp()
  85. }).
  86. -type mqtt_client() :: #mqtt_client{}.
  87. %%------------------------------------------------------------------------------
  88. %% MQTT Session
  89. %%------------------------------------------------------------------------------
  90. -record(mqtt_session, {
  91. client_id :: binary(),
  92. sess_pid :: pid(),
  93. persistent :: boolean()
  94. }).
  95. -type mqtt_session() :: #mqtt_session{}.
  96. %%------------------------------------------------------------------------------
  97. %% MQTT Message
  98. %%------------------------------------------------------------------------------
  99. -type mqtt_msgid() :: binary() | undefined.
  100. -type mqtt_pktid() :: 1..16#ffff | undefined.
  101. -record(mqtt_message, {
  102. msgid :: mqtt_msgid(), %% Global unique message ID
  103. pktid :: mqtt_pktid(), %% PacketId
  104. topic :: binary(), %% Topic that the message is published to
  105. from :: binary() | atom(), %% ClientId of publisher
  106. qos = 0 :: 0 | 1 | 2, %% Message QoS
  107. retain = false :: boolean(), %% Retain flag
  108. dup = false :: boolean(), %% Dup flag
  109. sys = false :: boolean(), %% $SYS flag
  110. payload :: binary(), %% Payload
  111. timestamp :: erlang:timestamp() %% os:timestamp
  112. }).
  113. -type mqtt_message() :: #mqtt_message{}.
  114. %%------------------------------------------------------------------------------
  115. %% MQTT Alarm
  116. %%------------------------------------------------------------------------------
  117. -record(mqtt_alarm, {
  118. id :: binary(),
  119. severity :: warning | error | critical,
  120. title :: binary(),
  121. summary :: binary(),
  122. timestamp :: erlang:timestamp() %% Timestamp
  123. }).
  124. -type mqtt_alarm() :: #mqtt_alarm{}.
  125. %%------------------------------------------------------------------------------
  126. %% MQTT Plugin
  127. %%------------------------------------------------------------------------------
  128. -record(mqtt_plugin, {
  129. name,
  130. version,
  131. descr,
  132. config,
  133. active = false
  134. }).
  135. -type mqtt_plugin() :: #mqtt_plugin{}.
  136. %%------------------------------------------------------------------------------
  137. %% MQTT CLI Command
  138. %% For example: 'broker metrics'
  139. %%------------------------------------------------------------------------------
  140. -record(mqtt_cli, {
  141. name,
  142. action,
  143. args = [],
  144. opts = [],
  145. usage,
  146. descr
  147. }).
  148. -type mqtt_cli() :: #mqtt_cli{}.