check topic alias

This commit is contained in:
Gilbert Wong 2018-09-05 19:06:34 +08:00
parent f0f818ab1a
commit c8b92a59b1
2 changed files with 42 additions and 34 deletions

View File

@ -43,7 +43,9 @@
{mqtt_wildcard_subscription, true}]). {mqtt_wildcard_subscription, true}]).
-define(PUBCAP_KEYS, [max_qos_allowed, -define(PUBCAP_KEYS, [max_qos_allowed,
mqtt_retain_available]). mqtt_retain_available,
mqtt_topic_alias
]).
-define(SUBCAP_KEYS, [max_qos_allowed, -define(SUBCAP_KEYS, [max_qos_allowed,
max_topic_levels, max_topic_levels,
mqtt_shared_subscription, mqtt_shared_subscription,
@ -60,6 +62,11 @@ do_check_pub(Props = #{qos := QoS}, [{max_qos_allowed, MaxQoS}|Caps]) ->
true -> {error, ?RC_QOS_NOT_SUPPORTED}; true -> {error, ?RC_QOS_NOT_SUPPORTED};
false -> do_check_pub(Props, Caps) false -> do_check_pub(Props, Caps)
end; end;
do_check_pub(Props = #{ topic_alias := TopicAlias}, [{max_topic_alias, MaxTopicAlias}| Caps]) ->
case TopicAlias =< MaxTopicAlias andalso TopicAlias > 0 of
false -> {error, ?RC_TOPIC_ALIAS_INVALID};
true -> do_check_pub(Props, Caps)
end;
do_check_pub(#{retain := true}, [{mqtt_retain_available, false}|_Caps]) -> do_check_pub(#{retain := true}, [{mqtt_retain_available, false}|_Caps]) ->
{error, ?RC_RETAIN_NOT_SUPPORTED}; {error, ?RC_RETAIN_NOT_SUPPORTED};
do_check_pub(Props, [{mqtt_retain_available, _}|Caps]) -> do_check_pub(Props, [{mqtt_retain_available, _}|Caps]) ->
@ -136,4 +143,3 @@ with_env(Zone, Key, InitFun) ->
Caps; Caps;
ZoneCaps -> ZoneCaps ZoneCaps -> ZoneCaps
end. end.

View File

@ -631,9 +631,11 @@ check_publish(Packet, PState) ->
run_check_steps([fun check_pub_caps/2, run_check_steps([fun check_pub_caps/2,
fun check_pub_acl/2], Packet, PState). fun check_pub_acl/2], Packet, PState).
check_pub_caps(#mqtt_packet{header = #mqtt_packet_header{qos = QoS, retain = R}}, check_pub_caps(#mqtt_packet{header = #mqtt_packet_header{qos = QoS, retain = Retain},
variable = #mqtt_packet_publish{ properties = Properties}},
#pstate{zone = Zone}) -> #pstate{zone = Zone}) ->
emqx_mqtt_caps:check_pub(Zone, #{qos => QoS, retain => R}). #{'Topic-Alias' := TopicAlias} = Properties,
emqx_mqtt_caps:check_pub(Zone, #{qos => QoS, retain => Retain, topic_alias => TopicAlias}).
check_pub_acl(_Packet, #pstate{is_super = IsSuper, enable_acl = EnableAcl}) check_pub_acl(_Packet, #pstate{is_super = IsSuper, enable_acl = EnableAcl})
when IsSuper orelse (not EnableAcl) -> when IsSuper orelse (not EnableAcl) ->