emqttd.hrl 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. %%--------------------------------------------------------------------
  2. %% Copyright (c) 2012-2016 Feng Lee <feng@emqtt.io>.
  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. %%--------------------------------------------------------------------
  17. %% Banner
  18. %%--------------------------------------------------------------------
  19. -define(COPYRIGHT, "Copyright (C) 2012-2016, Feng Lee <feng@emqtt.io>").
  20. -define(LICENSE_MESSAGE, "Licensed under the Apache License, Version 2.0").
  21. -define(PROTOCOL_VERSION, "MQTT/3.1.1").
  22. -define(ERTS_MINIMUM, "7.0").
  23. %%--------------------------------------------------------------------
  24. %% Sys/Queue/Share Topics' Prefix
  25. %%--------------------------------------------------------------------
  26. -define(SYSTOP, <<"$SYS/">>). %% System Topic
  27. -define(QUEUE, <<"$queue/">>). %% Queue Topic
  28. -define(SHARE, <<"$share/">>). %% Shared Topic
  29. %%--------------------------------------------------------------------
  30. %% PubSub
  31. %%--------------------------------------------------------------------
  32. -type(pubsub() :: publish | subscribe).
  33. -define(PUBSUB(PS), (PS =:= publish orelse PS =:= subscribe)).
  34. %%--------------------------------------------------------------------
  35. %% MQTT Topic
  36. %%--------------------------------------------------------------------
  37. -record(mqtt_topic, {
  38. topic :: binary(),
  39. flags = [] :: [retained | static]
  40. }).
  41. -type(mqtt_topic() :: #mqtt_topic{}).
  42. %%--------------------------------------------------------------------
  43. %% MQTT Client
  44. %%--------------------------------------------------------------------
  45. -type(ws_header_key() :: atom() | binary() | string()).
  46. -type(ws_header_val() :: atom() | binary() | string() | integer()).
  47. -record(mqtt_client, {
  48. client_id :: binary() | undefined,
  49. client_pid :: pid(),
  50. username :: binary() | undefined,
  51. peername :: {inet:ip_address(), integer()},
  52. clean_sess :: boolean(),
  53. proto_ver :: 3 | 4,
  54. keepalive = 0,
  55. will_topic :: undefined | binary(),
  56. ws_initial_headers :: list({ws_header_key(), ws_header_val()}),
  57. connected_at :: erlang:timestamp()
  58. }).
  59. -type(mqtt_client() :: #mqtt_client{}).
  60. %%--------------------------------------------------------------------
  61. %% MQTT Session
  62. %%--------------------------------------------------------------------
  63. -record(mqtt_session, {
  64. client_id :: binary(),
  65. sess_pid :: pid(),
  66. persistent :: boolean()
  67. }).
  68. -type(mqtt_session() :: #mqtt_session{}).
  69. %%--------------------------------------------------------------------
  70. %% MQTT Message
  71. %%--------------------------------------------------------------------
  72. -type(mqtt_msgid() :: binary() | undefined).
  73. -type(mqtt_pktid() :: 1..16#ffff | undefined).
  74. -record(mqtt_message, {
  75. id :: mqtt_msgid(), %% Global unique message ID
  76. pktid :: mqtt_pktid(), %% PacketId
  77. from :: {binary(), undefined | binary()}, %% ClientId and Username
  78. topic :: binary(), %% Topic that the message is published to
  79. qos = 0 :: 0 | 1 | 2, %% Message QoS
  80. flags = [] :: [retain | dup | sys], %% Message Flags
  81. retain = false :: boolean(), %% Retain flag
  82. dup = false :: boolean(), %% Dup flag
  83. sys = false :: boolean(), %% $SYS flag
  84. headers = [] :: list(),
  85. payload :: binary(), %% Payload
  86. timestamp :: pos_integer() %% os:timestamp to seconds
  87. }).
  88. -type(mqtt_message() :: #mqtt_message{}).
  89. %%--------------------------------------------------------------------
  90. %% MQTT Delivery
  91. %%--------------------------------------------------------------------
  92. -record(mqtt_delivery, {
  93. sender :: pid(), %% Pid of the sender/publisher
  94. message :: mqtt_message(), %% Message
  95. flows :: list()
  96. }).
  97. -type(mqtt_delivery() :: #mqtt_delivery{}).
  98. %%--------------------------------------------------------------------
  99. %% MQTT Route
  100. %%--------------------------------------------------------------------
  101. -record(mqtt_route, {
  102. topic :: binary(),
  103. node :: node()
  104. }).
  105. -type(mqtt_route() :: #mqtt_route{}).
  106. %%--------------------------------------------------------------------
  107. %% MQTT Alarm
  108. %%--------------------------------------------------------------------
  109. -record(mqtt_alarm, {
  110. id :: binary(),
  111. severity :: warning | error | critical,
  112. title :: iolist() | binary(),
  113. summary :: iolist() | binary(),
  114. timestamp :: erlang:timestamp() %% Timestamp
  115. }).
  116. -type(mqtt_alarm() :: #mqtt_alarm{}).
  117. %%--------------------------------------------------------------------
  118. %% MQTT Plugin
  119. %%--------------------------------------------------------------------
  120. -record(mqtt_plugin, {
  121. name,
  122. version,
  123. descr,
  124. active = false
  125. }).
  126. -type(mqtt_plugin() :: #mqtt_plugin{}).
  127. %%--------------------------------------------------------------------
  128. %% MQTT CLI Command
  129. %% For example: 'broker metrics'
  130. %%--------------------------------------------------------------------
  131. -record(mqtt_cli, {
  132. name,
  133. action,
  134. args = [],
  135. opts = [],
  136. usage,
  137. descr
  138. }).
  139. -type(mqtt_cli() :: #mqtt_cli{}).