From 42e193d9be5dd5ce4fd6cd18883a53b744625f82 Mon Sep 17 00:00:00 2001 From: JianBo He Date: Tue, 3 May 2022 16:54:14 +0800 Subject: [PATCH] refactor(mqttsn): create subscription with any topic format --- .../src/mqttsn/emqx_sn_channel.erl | 24 ++++--------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/apps/emqx_gateway/src/mqttsn/emqx_sn_channel.erl b/apps/emqx_gateway/src/mqttsn/emqx_sn_channel.erl index cf0681c25..9955f75d9 100644 --- a/apps/emqx_gateway/src/mqttsn/emqx_sn_channel.erl +++ b/apps/emqx_gateway/src/mqttsn/emqx_sn_channel.erl @@ -1782,25 +1782,11 @@ message_to_packet( | {shutdown, Reason :: term(), Reply :: term(), channel()} | {shutdown, Reason :: term(), Reply :: term(), emqx_types:packet(), channel()}. handle_call({subscribe, Topic, SubOpts}, _From, Channel) -> - %% XXX: Only support short_topic_name - SubProps = maps:get(sub_props, SubOpts, #{}), - case maps:get(subtype, SubProps, short_topic_name) of - short_topic_name -> - case byte_size(Topic) of - 2 -> - case do_subscribe({?SN_INVALID_TOPIC_ID, Topic, SubOpts}, Channel) of - {ok, {_, NTopicName, NSubOpts}, NChannel} -> - reply({ok, {NTopicName, NSubOpts}}, NChannel); - {error, ?SN_RC2_EXCEED_LIMITATION} -> - reply({error, exceed_limitation}, Channel) - end; - _ -> - reply({error, bad_topic_name}, Channel) - end; - predefined_topic_id -> - reply({error, only_support_short_name_topic}, Channel); - _ -> - reply({error, only_support_short_name_topic}, Channel) + case do_subscribe({?SN_INVALID_TOPIC_ID, Topic, SubOpts}, Channel) of + {ok, {_, NTopicName, NSubOpts}, NChannel} -> + reply({ok, {NTopicName, NSubOpts}}, NChannel); + {error, ?SN_RC2_EXCEED_LIMITATION} -> + reply({error, exceed_limitation}, Channel) end; handle_call({unsubscribe, Topic}, _From, Channel) -> TopicFilters = [emqx_topic:parse(Topic)],