fix issue#95 - Topic filters in ACL rule should support 'eq' tag

This commit is contained in:
Ery Lee 2015-04-20 04:26:01 +08:00
parent cf0068c2b3
commit 02614e8ae4
1 changed files with 6 additions and 2 deletions

View File

@ -58,7 +58,7 @@ compile({A, all}) when (A =:= allow) orelse (A =:= deny) ->
{A, all}; {A, all};
compile({A, Who, Access, TopicFilters}) when (A =:= allow) orelse (A =:= deny) -> compile({A, Who, Access, TopicFilters}) when (A =:= allow) orelse (A =:= deny) ->
{A, compile(who, Who), Access, [compile(topic, bin(Topic)) || Topic <- TopicFilters]}. {A, compile(who, Who), Access, [compile(topic, Topic) || Topic <- TopicFilters]}.
compile(who, all) -> compile(who, all) ->
all; all;
@ -74,8 +74,10 @@ compile(who, {user, all}) ->
compile(who, {user, Username}) -> compile(who, {user, Username}) ->
{user, bin(Username)}; {user, bin(Username)};
compile(topic, {eq, Topic}) ->
{eq, emqtt_topic:words(bin(Topic))};
compile(topic, Topic) -> compile(topic, Topic) ->
Words = emqtt_topic:words(Topic), Words = emqtt_topic:words(bin(Topic)),
case 'pattern?'(Words) of case 'pattern?'(Words) of
true -> {pattern, Words}; true -> {pattern, Words};
false -> Words false -> Words
@ -138,6 +140,8 @@ match_topics(Client, Topic, [TopicFilter|Filters]) ->
false -> match_topics(Client, Topic, Filters) false -> match_topics(Client, Topic, Filters)
end. end.
match_topic(Topic, {eq, TopicFilter}) ->
Topic =:= TopicFilter;
match_topic(Topic, TopicFilter) -> match_topic(Topic, TopicFilter) ->
emqtt_topic:match(Topic, TopicFilter). emqtt_topic:match(Topic, TopicFilter).