fix(coap): remove the leading `/` in assembling publish topic
This commit is contained in:
parent
f188808e67
commit
55c1a1868a
|
@ -153,7 +153,7 @@ init(
|
||||||
mountpoint => Mountpoint
|
mountpoint => Mountpoint
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
|
%% FIXME: it should coap.hearbeat instead of idle_timeout?
|
||||||
Heartbeat = ?GET_IDLE_TIME(Config),
|
Heartbeat = ?GET_IDLE_TIME(Config),
|
||||||
#channel{
|
#channel{
|
||||||
ctx = Ctx,
|
ctx = Ctx,
|
||||||
|
@ -447,6 +447,7 @@ enrich_conninfo(
|
||||||
conninfo = ConnInfo
|
conninfo = ConnInfo
|
||||||
}
|
}
|
||||||
) ->
|
) ->
|
||||||
|
%% FIXME: generate a random clientid if absent
|
||||||
case Queries of
|
case Queries of
|
||||||
#{<<"clientid">> := ClientId} ->
|
#{<<"clientid">> := ClientId} ->
|
||||||
Interval = maps:get(interval, emqx_keepalive:info(KeepAlive)),
|
Interval = maps:get(interval, emqx_keepalive:info(KeepAlive)),
|
||||||
|
@ -467,6 +468,9 @@ enrich_clientinfo(
|
||||||
{Queries, Msg},
|
{Queries, Msg},
|
||||||
Channel = #channel{clientinfo = ClientInfo0}
|
Channel = #channel{clientinfo = ClientInfo0}
|
||||||
) ->
|
) ->
|
||||||
|
%% FIXME:
|
||||||
|
%% 1. generate a random clientid if absent;
|
||||||
|
%% 2. assgin username, password to `undefined` if absent
|
||||||
case Queries of
|
case Queries of
|
||||||
#{
|
#{
|
||||||
<<"username">> := UserName,
|
<<"username">> := UserName,
|
||||||
|
@ -542,6 +546,7 @@ process_connect(
|
||||||
)
|
)
|
||||||
of
|
of
|
||||||
{ok, _Sess} ->
|
{ok, _Sess} ->
|
||||||
|
%% FIXME: Token in cluster wide?
|
||||||
RandVal = rand:uniform(?TOKEN_MAXIMUM),
|
RandVal = rand:uniform(?TOKEN_MAXIMUM),
|
||||||
Token = erlang:list_to_binary(erlang:integer_to_list(RandVal)),
|
Token = erlang:list_to_binary(erlang:integer_to_list(RandVal)),
|
||||||
NResult = Result#{events => [{event, connected}]},
|
NResult = Result#{events => [{event, connected}]},
|
||||||
|
|
|
@ -69,17 +69,7 @@ handle_method(_, _, Msg, _, _) ->
|
||||||
check_topic([]) ->
|
check_topic([]) ->
|
||||||
error;
|
error;
|
||||||
check_topic(Path) ->
|
check_topic(Path) ->
|
||||||
Sep = <<"/">>,
|
{ok, emqx_http_lib:uri_decode(iolist_to_binary(lists:join(<<"/">>, Path)))}.
|
||||||
{ok,
|
|
||||||
emqx_http_lib:uri_decode(
|
|
||||||
lists:foldl(
|
|
||||||
fun(Part, Acc) ->
|
|
||||||
<<Acc/binary, Sep/binary, Part/binary>>
|
|
||||||
end,
|
|
||||||
<<>>,
|
|
||||||
Path
|
|
||||||
)
|
|
||||||
)}.
|
|
||||||
|
|
||||||
get_sub_opts(#coap_message{options = Opts} = Msg) ->
|
get_sub_opts(#coap_message{options = Opts} = Msg) ->
|
||||||
SubOpts = maps:fold(fun parse_sub_opts/3, #{}, Opts),
|
SubOpts = maps:fold(fun parse_sub_opts/3, #{}, Opts),
|
||||||
|
@ -124,6 +114,10 @@ get_publish_qos(Msg) ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
apply_publish_opts(Msg, MQTTMsg) ->
|
apply_publish_opts(Msg, MQTTMsg) ->
|
||||||
|
case emqx_coap_message:get_option(uri_query, Msg) of
|
||||||
|
undefined ->
|
||||||
|
MQTTMsg;
|
||||||
|
Qs ->
|
||||||
maps:fold(
|
maps:fold(
|
||||||
fun
|
fun
|
||||||
(<<"retain">>, V, Acc) ->
|
(<<"retain">>, V, Acc) ->
|
||||||
|
@ -141,8 +135,9 @@ apply_publish_opts(Msg, MQTTMsg) ->
|
||||||
Acc
|
Acc
|
||||||
end,
|
end,
|
||||||
MQTTMsg,
|
MQTTMsg,
|
||||||
emqx_coap_message:get_option(uri_query, Msg)
|
Qs
|
||||||
).
|
)
|
||||||
|
end.
|
||||||
|
|
||||||
subscribe(#coap_message{token = <<>>} = Msg, _, _, _) ->
|
subscribe(#coap_message{token = <<>>} = Msg, _, _, _) ->
|
||||||
reply({error, bad_request}, <<"observe without token">>, Msg);
|
reply({error, bad_request}, <<"observe without token">>, Msg);
|
||||||
|
|
Loading…
Reference in New Issue