client(State)

This commit is contained in:
Feng 2015-11-01 20:44:21 +08:00
parent c7f0e33674
commit 4b26291cb9
1 changed files with 7 additions and 6 deletions

View File

@ -182,7 +182,7 @@ process(Packet = ?CONNECT_PACKET(Var), State0) ->
send(?CONNACK_PACKET(ReturnCode1), State3); send(?CONNACK_PACKET(ReturnCode1), State3);
process(Packet = ?PUBLISH_PACKET(_Qos, Topic, _PacketId, _Payload), State) -> process(Packet = ?PUBLISH_PACKET(_Qos, Topic, _PacketId, _Payload), State) ->
case check_acl(publish, Topic, State) of case check_acl(publish, Topic, client(State)) of
allow -> allow ->
publish(Packet, State); publish(Packet, State);
deny -> deny ->
@ -210,7 +210,8 @@ process(?SUBSCRIBE_PACKET(PacketId, []), State) ->
send(?SUBACK_PACKET(PacketId, []), State); send(?SUBACK_PACKET(PacketId, []), State);
process(?SUBSCRIBE_PACKET(PacketId, TopicTable), State = #proto_state{session = Session}) -> process(?SUBSCRIBE_PACKET(PacketId, TopicTable), State = #proto_state{session = Session}) ->
AllowDenies = [check_acl(subscribe, Topic, State) || {Topic, _Qos} <- TopicTable], Client = client(State),
AllowDenies = [check_acl(subscribe, Topic, Client) || {Topic, _Qos} <- TopicTable],
case lists:member(deny, AllowDenies) of case lists:member(deny, AllowDenies) of
true -> true ->
?LOG(error, "Cannot SUBSCRIBE ~p for ACL Deny", [TopicTable], State), ?LOG(error, "Cannot SUBSCRIBE ~p for ACL Deny", [TopicTable], State),
@ -391,16 +392,16 @@ validate_qos(_) ->
false. false.
%% PUBLISH ACL is cached in process dictionary. %% PUBLISH ACL is cached in process dictionary.
check_acl(publish, Topic, State) -> check_acl(publish, Topic, Client) ->
case get({acl, publish, Topic}) of case get({acl, publish, Topic}) of
undefined -> undefined ->
AllowDeny = emqttd_access_control:check_acl(client(State), publish, Topic), AllowDeny = emqttd_access_control:check_acl(Client, publish, Topic),
put({acl, publish, Topic}, AllowDeny), put({acl, publish, Topic}, AllowDeny),
AllowDeny; AllowDeny;
AllowDeny -> AllowDeny ->
AllowDeny AllowDeny
end; end;
check_acl(subscribe, Topic, State) -> check_acl(subscribe, Topic, Client) ->
emqttd_access_control:check_acl(client(State), subscribe, Topic). emqttd_access_control:check_acl(Client, subscribe, Topic).