Skip to content

Commit

Permalink
Mqtt5 properties rework (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
larshesel authored Mar 11, 2019
1 parent 01edaa7 commit 741655f
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 27 deletions.
31 changes: 24 additions & 7 deletions src/auth_on_publish_m5_hook.erl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
p_response_topic => topic(),
p_correlation_data => binary(),
p_topic_alias => 1..65535,
p_user_property => [user_property()]
p_user_property => nonempty_list(user_property())
}.

-type msg_modifier() ::
Expand All @@ -49,13 +49,30 @@
%% back-pressure for websocket connections.
throttle => milliseconds(),

%% Override the message expiry from the properties or set it
%% if not present.
message_expiry_interval => seconds(),
properties =>
#{
%% Override the payload format indicator
p_payload_format_indicator => unspecified | utf8,

%% Override the user properties from the properties or set
%% them if not present.
user_property => [user_property()]
%% Override the content type
p_content_type => utf8string(),

%% Override the message expiry from the properties or set it
%% if not present.
p_message_expiry_interval => seconds(),

%% Override the user properties from the properties or set
%% them if not present.
p_user_property => nonempty_list(user_property()),

%% Override the response topic from the properties or set if
%% not present.
p_response_topic => topic(),

%% Override the correlation data from the properties or set
%% if not present.
p_correlation_data => binary()
}
}.


Expand Down
10 changes: 6 additions & 4 deletions src/auth_on_register_m5_hook.erl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
p_max_packet_size => 1..4294967296,
p_request_response_info => boolean(),
p_request_problem_info => boolean(),
p_user_property => [user_property()]
p_user_property => nonempty_list(user_property())
}.

-type reg_modifiers() ::
Expand Down Expand Up @@ -52,9 +52,11 @@
%% for this session.
max_offline_messages => non_neg_integer(),

%% Override the session expiry from the properties or set it
%% if not present.
session_expiry_interval => seconds()
properties => #{
%% Override the session expiry from the
%% properties or set it if not present.
p_session_expiry_interval => seconds()
}
}.

-type err_reason_code_name() :: ?UNSPECIFIED_ERROR
Expand Down
2 changes: 1 addition & 1 deletion src/auth_on_subscribe_m5_hook.erl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
-type sub_properties() ::
#{
p_subscription_id => [subscription_id()],
p_user_property => [user_property()]
p_user_property => nonempty_list(user_property())
}.

-type sub_modifiers() ::
Expand Down
21 changes: 12 additions & 9 deletions src/on_auth_m5_hook.erl
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,24 @@

-type auth_properties() ::
#{
p_authentication_method => utf8string(),
p_authentication_data => binary()
p_authentication_method := utf8string(),
p_authentication_data := binary()
}.

-type auth_modifiers() ::
#{
%% Indicate towards the client if the authentication was
%% successful or should be continued.
reason_code => ?SUCCESS | ?CONTINUE_AUTHENTICATION,
%% Indicate towards the client if the authentication was
%% successful or should be continued.
reason_code => ?SUCCESS | ?CONTINUE_AUTHENTICATION,

%% Specify the authentication method to send to the client.
auth_method => binary(),
properties :=
#{
%% Specify the authentication method to send to the client.
p_authentication_method := binary(),

%% Specify the authentication data to send to the client.
auth_data => binary()
%% Specify the authentication data to send to the client.
p_authentication_data := binary()
}
}.

-type err_values() ::
Expand Down
30 changes: 25 additions & 5 deletions src/on_deliver_m5_hook.erl
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
-callback on_deliver_m5(UserName :: username(),
SubscriberId :: subscriber_id(),
Topic :: topic(),
Properties :: deliver_properties(),
Payload :: payload()) ->
Payload :: payload(),
Properties :: deliver_properties()) ->
ok |
{ok, Payload :: payload()} |
{ok, Modifiers :: msg_modifier()} |
next.

Expand All @@ -19,7 +18,7 @@
p_topic_alias => 1..65535,
p_response_topic => topic(),
p_correlation_data => binary(),
p_user_property => [user_property()],
p_user_property => nonempty_list(user_property()),
p_subscription_id => [subscription_id()],
p_content_type => utf8string()
}.
Expand All @@ -30,7 +29,28 @@
topic => topic(),

%% Rewrite the payload of the message.
payload => payload()
payload => payload(),

properties =>
#{
%% Override the payload format indicator
p_payload_format_indicator => unspecified | utf8,

%% Override the content type
p_content_type => utf8string(),

%% Override the user properties from the properties or set
%% them if not present.
p_user_property => nonempty_list(user_property()),

%% Override the response topic from the properties or set if
%% not present.
p_response_topic => topic(),

%% Override the correlation data from the properties or set
%% if not present.
p_correlation_data => binary()
}
}.

-export_type([msg_modifier/0]).
2 changes: 1 addition & 1 deletion src/on_unsubscribe_m5_hook.erl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

-type unsub_properties() ::
#{
p_user_property => [user_property()]
p_user_property => nonempty_list(user_property())
}.

-type unsub_modifiers() ::
Expand Down

0 comments on commit 741655f

Please sign in to comment.