check topic alias
This commit is contained in:
parent
f0f818ab1a
commit
c8b92a59b1
|
@ -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.
|
||||||
|
|
||||||
|
|
|
@ -33,36 +33,36 @@
|
||||||
-export([shutdown/2]).
|
-export([shutdown/2]).
|
||||||
|
|
||||||
-record(pstate, {
|
-record(pstate, {
|
||||||
zone,
|
zone,
|
||||||
sendfun,
|
sendfun,
|
||||||
peername,
|
peername,
|
||||||
peercert,
|
peercert,
|
||||||
proto_ver,
|
proto_ver,
|
||||||
proto_name,
|
proto_name,
|
||||||
ackprops,
|
ackprops,
|
||||||
client_id,
|
client_id,
|
||||||
is_assigned,
|
is_assigned,
|
||||||
conn_pid,
|
conn_pid,
|
||||||
conn_props,
|
conn_props,
|
||||||
ack_props,
|
ack_props,
|
||||||
username,
|
username,
|
||||||
session,
|
session,
|
||||||
clean_start,
|
clean_start,
|
||||||
topic_aliases,
|
topic_aliases,
|
||||||
packet_size,
|
packet_size,
|
||||||
will_topic,
|
will_topic,
|
||||||
will_msg,
|
will_msg,
|
||||||
keepalive,
|
keepalive,
|
||||||
mountpoint,
|
mountpoint,
|
||||||
is_super,
|
is_super,
|
||||||
is_bridge,
|
is_bridge,
|
||||||
enable_ban,
|
enable_ban,
|
||||||
enable_acl,
|
enable_acl,
|
||||||
recv_stats,
|
recv_stats,
|
||||||
send_stats,
|
send_stats,
|
||||||
connected,
|
connected,
|
||||||
connected_at
|
connected_at
|
||||||
}).
|
}).
|
||||||
|
|
||||||
-type(state() :: #pstate{}).
|
-type(state() :: #pstate{}).
|
||||||
-export_type([state/0]).
|
-export_type([state/0]).
|
||||||
|
@ -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) ->
|
||||||
|
|
Loading…
Reference in New Issue