From ff6acbf29370bc2151b9b3bf8a61f3ad96eaab92 Mon Sep 17 00:00:00 2001 From: Lei Chen Date: Mon, 16 Jan 2017 16:24:19 +0800 Subject: [PATCH 1/2] Client unsubscribe hook does not handle 'stop' value. Insert a statement to prevent calling emqttd_session:unsubscribe() if hook returns stop. --- src/emqttd_protocol.erl | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/emqttd_protocol.erl b/src/emqttd_protocol.erl index e892c6158..2b524d1a9 100644 --- a/src/emqttd_protocol.erl +++ b/src/emqttd_protocol.erl @@ -130,9 +130,12 @@ handle({subscribe, RawTopicTable}, ProtoState = #proto_state{client_id = ClientI handle({unsubscribe, RawTopics}, ProtoState = #proto_state{client_id = ClientId, username = Username, session = Session}) -> - {ok, TopicTable} = emqttd:run_hooks('client.unsubscribe', - [ClientId, Username], parse_topics(RawTopics)), - emqttd_session:unsubscribe(Session, TopicTable), + case emqttd:run_hooks('client.unsubscribe', [ClientId, Username], parse_topics(RawTopics)) of + {ok, TopicTable} -> + emqttd_session:unsubscribe(Session, TopicTable); + {stop, _} -> + ok + end, {ok, ProtoState}. process(Packet = ?CONNECT_PACKET(Var), State0) -> @@ -243,8 +246,13 @@ process(?UNSUBSCRIBE_PACKET(PacketId, []), State) -> process(?UNSUBSCRIBE_PACKET(PacketId, RawTopics), State = #proto_state{ client_id = ClientId, username = Username, session = Session}) -> - {ok, TopicTable} = emqttd:run_hooks('client.unsubscribe', [ClientId, Username], parse_topics(RawTopics)), - emqttd_session:unsubscribe(Session, TopicTable), + case emqttd:run_hooks('client.unsubscribe', [ClientId, Username], parse_topics(RawTopics)) of + {ok, TopicTable} -> + emqttd_session:unsubscribe(Session, TopicTable); + {stop, _} -> + ok + end, + , send(?UNSUBACK_PACKET(PacketId), State); process(?PACKET(?PINGREQ), State) -> From 4606eaeb5859b401696b88aab2c3e1fbba7c6366 Mon Sep 17 00:00:00 2001 From: Lei Chen Date: Mon, 16 Jan 2017 16:27:10 +0800 Subject: [PATCH 2/2] delete a comma. --- src/emqttd_protocol.erl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/emqttd_protocol.erl b/src/emqttd_protocol.erl index 2b524d1a9..f0b877dc5 100644 --- a/src/emqttd_protocol.erl +++ b/src/emqttd_protocol.erl @@ -252,7 +252,6 @@ process(?UNSUBSCRIBE_PACKET(PacketId, RawTopics), State = #proto_state{ {stop, _} -> ok end, - , send(?UNSUBACK_PACKET(PacketId), State); process(?PACKET(?PINGREQ), State) ->