diff --git a/include/emqttd.hrl b/include/emqttd.hrl index ccf4ef47d..4fd6749f0 100644 --- a/include/emqttd.hrl +++ b/include/emqttd.hrl @@ -40,45 +40,17 @@ %% PubSub %%-------------------------------------------------------------------- --type pubsub() :: publish | subscribe. +-type(pubsub() :: publish | subscribe). -define(PUBSUB(PS), (PS =:= publish orelse PS =:= subscribe)). -%%-------------------------------------------------------------------- -%% MQTT Topic -%%-------------------------------------------------------------------- --record(mqtt_topic, { - topic :: binary(), - flags :: [retained | static] -}). - --type(mqtt_topic() :: #mqtt_topic{}). - -%%-------------------------------------------------------------------- -%% MQTT Route -%%-------------------------------------------------------------------- --record(mqtt_route, { - topic :: binary(), - node :: node() -}). - --type(mqtt_route() :: #mqtt_route{}). - -%%-------------------------------------------------------------------- -%% MQTT Subscription -%%-------------------------------------------------------------------- --record(mqtt_subscription, { - subid :: binary() | atom() | pid(), - topic :: binary(), - qos = 0 :: 0 | 1 | 2 -}). - --type(mqtt_subscription() :: #mqtt_subscription{}). - %%-------------------------------------------------------------------- %% MQTT Client %%-------------------------------------------------------------------- +-type(ws_header_key() :: atom() | binary() | string()). +-type(ws_header_val() :: atom() | binary() | string() | integer()). + -record(mqtt_client, { client_id :: binary() | undefined, client_pid :: pid(), @@ -88,9 +60,7 @@ proto_ver :: 3 | 4, keepalive = 0, will_topic :: undefined | binary(), - token :: binary() | undefined, %% auth token - cookie :: binary() | undefined, %% auth cookie - %%ws_initial_headers :: list({ws_header_key(), ws_header_val()}), + ws_initial_headers :: list({ws_header_key(), ws_header_val()}), connected_at :: erlang:timestamp() }). @@ -117,6 +87,7 @@ -record(mqtt_message, { msgid :: mqtt_msgid(), %% Global unique message ID pktid :: mqtt_pktid(), %% PacketId + from :: {binary(), undefined | binary()}, %% ClientId and Username topic :: binary(), %% Topic that the message is published to qos = 0 :: 0 | 1 | 2, %% Message QoS flags = [] :: [retain | dup | sys], %% Message Flags @@ -135,13 +106,22 @@ %%-------------------------------------------------------------------- -record(mqtt_delivery, { sender :: pid(), %% Pid of the sender/publisher - from :: binary(), - message :: mqtt_message(), %% Message + message :: mqtt_message(), %% Message flows :: list() }). -type(mqtt_delivery() :: #mqtt_delivery{}). +%%-------------------------------------------------------------------- +%% MQTT Route +%%-------------------------------------------------------------------- +-record(mqtt_route, { + topic :: binary(), + node :: node() +}). + +-type(mqtt_route() :: #mqtt_route{}). + %%-------------------------------------------------------------------- %% MQTT Alarm %%-------------------------------------------------------------------- diff --git a/include/emqttd_protocol.hrl b/include/emqttd_protocol.hrl index 61b82f02d..8a5e5d0ca 100644 --- a/include/emqttd_protocol.hrl +++ b/include/emqttd_protocol.hrl @@ -26,7 +26,7 @@ {?MQTT_PROTO_V31, <<"MQIsdp">>}, {?MQTT_PROTO_V311, <<"MQTT">>}]). --type mqtt_vsn() :: ?MQTT_PROTO_V31 | ?MQTT_PROTO_V311. +-type(mqtt_vsn() :: ?MQTT_PROTO_V31 | ?MQTT_PROTO_V311). %%-------------------------------------------------------------------- %% MQTT QoS @@ -41,11 +41,11 @@ -define(IS_QOS(I), (I >= ?QOS0 andalso I =< ?QOS2)). --type mqtt_qos() :: ?QOS0 | ?QOS1 | ?QOS2. +-type(mqtt_qos() :: ?QOS0 | ?QOS1 | ?QOS2). --type mqtt_qos_name() :: qos0 | at_most_once | +-type(mqtt_qos_name() :: qos0 | at_most_once | qos1 | at_least_once | - qos2 | exactly_once. + qos2 | exactly_once). -define(QOS_I(Name), begin @@ -102,7 +102,7 @@ 'PINGRESP', 'DISCONNECT']). --type mqtt_packet_type() :: ?RESERVED..?DISCONNECT. +-type(mqtt_packet_type() :: ?RESERVED..?DISCONNECT). %%-------------------------------------------------------------------- %% MQTT Connect Return Codes @@ -114,7 +114,7 @@ -define(CONNACK_CREDENTIALS, 4). %% Username or password is malformed -define(CONNACK_AUTH, 5). %% Client is not authorized to connect --type mqtt_connack() :: ?CONNACK_ACCEPT..?CONNACK_AUTH. +-type(mqtt_connack() :: ?CONNACK_ACCEPT..?CONNACK_AUTH). %%-------------------------------------------------------------------- %% MQTT Parser and Serializer @@ -135,8 +135,9 @@ %%-------------------------------------------------------------------- %% MQTT Packets %%-------------------------------------------------------------------- --type mqtt_client_id() :: binary(). --type mqtt_packet_id() :: 1..16#ffff | undefined. +-type(mqtt_client_id() :: binary()). +-type(mqtt_username() :: binary() | undefined). +-type(mqtt_packet_id() :: 1..16#ffff | undefined). -record(mqtt_packet_connect, { client_id = <<>> :: mqtt_client_id(),