Merge pull request #5913 from lafirest/fix/format
fix: change all ~s in io format to ~ts
This commit is contained in:
commit
5dc11e5323
|
@ -81,7 +81,7 @@ set_debug_secret(PathToSecretFile) ->
|
||||||
catch _ : _ -> error({badfile, PathToSecretFile})
|
catch _ : _ -> error({badfile, PathToSecretFile})
|
||||||
end;
|
end;
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
?ULOG("Failed to read debug_info encryption key file ~s: ~p~n",
|
?ULOG("Failed to read debug_info encryption key file ~ts: ~p~n",
|
||||||
[PathToSecretFile, Reason]),
|
[PathToSecretFile, Reason]),
|
||||||
error(Reason)
|
error(Reason)
|
||||||
end,
|
end,
|
||||||
|
|
|
@ -415,16 +415,16 @@ normalize_message(high_system_memory_usage, #{high_watermark := HighWatermark})
|
||||||
normalize_message(high_process_memory_usage, #{high_watermark := HighWatermark}) ->
|
normalize_message(high_process_memory_usage, #{high_watermark := HighWatermark}) ->
|
||||||
list_to_binary(io_lib:format("Process memory usage is higher than ~p%", [HighWatermark]));
|
list_to_binary(io_lib:format("Process memory usage is higher than ~p%", [HighWatermark]));
|
||||||
normalize_message(high_cpu_usage, #{usage := Usage}) ->
|
normalize_message(high_cpu_usage, #{usage := Usage}) ->
|
||||||
list_to_binary(io_lib:format("~s cpu usage", [Usage]));
|
list_to_binary(io_lib:format("~ts cpu usage", [Usage]));
|
||||||
normalize_message(too_many_processes, #{usage := Usage}) ->
|
normalize_message(too_many_processes, #{usage := Usage}) ->
|
||||||
list_to_binary(io_lib:format("~s process usage", [Usage]));
|
list_to_binary(io_lib:format("~ts process usage", [Usage]));
|
||||||
normalize_message(cluster_rpc_apply_failed, #{tnx_id := TnxId}) ->
|
normalize_message(cluster_rpc_apply_failed, #{tnx_id := TnxId}) ->
|
||||||
list_to_binary(io_lib:format("cluster_rpc_apply_failed:~w", [TnxId]));
|
list_to_binary(io_lib:format("cluster_rpc_apply_failed:~w", [TnxId]));
|
||||||
normalize_message(partition, #{occurred := Node}) ->
|
normalize_message(partition, #{occurred := Node}) ->
|
||||||
list_to_binary(io_lib:format("Partition occurs at node ~s", [Node]));
|
list_to_binary(io_lib:format("Partition occurs at node ~ts", [Node]));
|
||||||
normalize_message(<<"resource", _/binary>>, #{type := Type, id := ID}) ->
|
normalize_message(<<"resource", _/binary>>, #{type := Type, id := ID}) ->
|
||||||
list_to_binary(io_lib:format("Resource ~s(~s) is down", [Type, ID]));
|
list_to_binary(io_lib:format("Resource ~ts(~ts) is down", [Type, ID]));
|
||||||
normalize_message(<<"conn_congestion/", Info/binary>>, _) ->
|
normalize_message(<<"conn_congestion/", Info/binary>>, _) ->
|
||||||
list_to_binary(io_lib:format("connection congested: ~s", [Info]));
|
list_to_binary(io_lib:format("connection congested: ~ts", [Info]));
|
||||||
normalize_message(_Name, _UnknownDetails) ->
|
normalize_message(_Name, _UnknownDetails) ->
|
||||||
<<"Unknown alarm">>.
|
<<"Unknown alarm">>.
|
||||||
|
|
|
@ -57,8 +57,8 @@ run(#{subscribers := Subs,
|
||||||
lists:foreach(fun(Pid) -> Pid ! start_subscribe end, SubsPids),
|
lists:foreach(fun(Pid) -> Pid ! start_subscribe end, SubsPids),
|
||||||
collect_results(SubsPids, subscribe_time)
|
collect_results(SubsPids, subscribe_time)
|
||||||
end),
|
end),
|
||||||
io:format(user, "InsertTotalTime: ~s~n", [ns(T1)]),
|
io:format(user, "InsertTotalTime: ~ts~n", [ns(T1)]),
|
||||||
io:format(user, "InsertTimeAverage: ~s~n", [ns(SubsTime / Subs)]),
|
io:format(user, "InsertTimeAverage: ~ts~n", [ns(SubsTime / Subs)]),
|
||||||
io:format(user, "InsertRps: ~p~n", [rps(Subs * SubOps, T1)]),
|
io:format(user, "InsertRps: ~p~n", [rps(Subs * SubOps, T1)]),
|
||||||
|
|
||||||
io:format(user, "lookup ...~n", []),
|
io:format(user, "lookup ...~n", []),
|
||||||
|
@ -67,8 +67,8 @@ run(#{subscribers := Subs,
|
||||||
lists:foreach(fun(Pid) -> Pid ! start_lookup end, PubsPids),
|
lists:foreach(fun(Pid) -> Pid ! start_lookup end, PubsPids),
|
||||||
collect_results(PubsPids, lookup_time)
|
collect_results(PubsPids, lookup_time)
|
||||||
end),
|
end),
|
||||||
io:format(user, "LookupTotalTime: ~s~n", [ns(T2)]),
|
io:format(user, "LookupTotalTime: ~ts~n", [ns(T2)]),
|
||||||
io:format(user, "LookupTimeAverage: ~s~n", [ns(PubsTime / Pubs)]),
|
io:format(user, "LookupTimeAverage: ~ts~n", [ns(PubsTime / Pubs)]),
|
||||||
io:format(user, "LookupRps: ~p~n", [rps(Pubs * PubOps, T2)]),
|
io:format(user, "LookupRps: ~p~n", [rps(Pubs * PubOps, T2)]),
|
||||||
|
|
||||||
io:format(user, "mnesia table(s) RAM: ~p~n", [ram_bytes()]),
|
io:format(user, "mnesia table(s) RAM: ~p~n", [ram_bytes()]),
|
||||||
|
@ -79,7 +79,7 @@ run(#{subscribers := Subs,
|
||||||
lists:foreach(fun(Pid) -> Pid ! stop end, SubsPids),
|
lists:foreach(fun(Pid) -> Pid ! stop end, SubsPids),
|
||||||
wait_until_empty()
|
wait_until_empty()
|
||||||
end),
|
end),
|
||||||
io:format(user, "TimeToUnsubscribeAll: ~s~n", [ns(T3)]).
|
io:format(user, "TimeToUnsubscribeAll: ~ts~n", [ns(T3)]).
|
||||||
|
|
||||||
wait_until_empty() ->
|
wait_until_empty() ->
|
||||||
case emqx_trie:empty() of
|
case emqx_trie:empty() of
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
-define(ALARM_CONN_CONGEST(Channel, Reason),
|
-define(ALARM_CONN_CONGEST(Channel, Reason),
|
||||||
list_to_binary(
|
list_to_binary(
|
||||||
io_lib:format("~s/~s/~s",
|
io_lib:format("~ts/~ts/~ts",
|
||||||
[Reason, emqx_channel:info(clientid, Channel),
|
[Reason, emqx_channel:info(clientid, Channel),
|
||||||
maps:get(username, emqx_channel:info(clientinfo, Channel),
|
maps:get(username, emqx_channel:info(clientinfo, Channel),
|
||||||
<<"unknown_user">>)]))).
|
<<"unknown_user">>)]))).
|
||||||
|
|
|
@ -116,7 +116,7 @@
|
||||||
-define(ENABLED(X), (X =/= undefined)).
|
-define(ENABLED(X), (X =/= undefined)).
|
||||||
|
|
||||||
-define(ALARM_TCP_CONGEST(Channel),
|
-define(ALARM_TCP_CONGEST(Channel),
|
||||||
list_to_binary(io_lib:format("mqtt_conn/congested/~s/~s",
|
list_to_binary(io_lib:format("mqtt_conn/congested/~ts/~ts",
|
||||||
[emqx_channel:info(clientid, Channel),
|
[emqx_channel:info(clientid, Channel),
|
||||||
emqx_channel:info(username, Channel)]))).
|
emqx_channel:info(username, Channel)]))).
|
||||||
|
|
||||||
|
|
|
@ -128,7 +128,7 @@ help() ->
|
||||||
[] ->
|
[] ->
|
||||||
print("No commands available.~n");
|
print("No commands available.~n");
|
||||||
Cmds ->
|
Cmds ->
|
||||||
print("Usage: ~s~n", [?MODULE]),
|
print("Usage: ~ts~n", [?MODULE]),
|
||||||
lists:foreach(fun({_, {Mod, Cmd}, _}) ->
|
lists:foreach(fun({_, {Mod, Cmd}, _}) ->
|
||||||
print("~110..-s~n", [""]), Mod:Cmd(usage)
|
print("~110..-s~n", [""]), Mod:Cmd(usage)
|
||||||
end, Cmds)
|
end, Cmds)
|
||||||
|
@ -136,11 +136,11 @@ help() ->
|
||||||
|
|
||||||
-spec(print(io:format()) -> ok).
|
-spec(print(io:format()) -> ok).
|
||||||
print(Msg) ->
|
print(Msg) ->
|
||||||
io:format("~s", [format(Msg)]).
|
io:format("~ts", [format(Msg)]).
|
||||||
|
|
||||||
-spec(print(io:format(), [term()]) -> ok).
|
-spec(print(io:format(), [term()]) -> ok).
|
||||||
print(Format, Args) ->
|
print(Format, Args) ->
|
||||||
io:format("~s", [format(Format, Args)]).
|
io:format("~ts", [format(Format, Args)]).
|
||||||
|
|
||||||
-spec(usage([cmd_usage()]) -> ok).
|
-spec(usage([cmd_usage()]) -> ok).
|
||||||
usage(UsageList) ->
|
usage(UsageList) ->
|
||||||
|
@ -152,7 +152,7 @@ usage(CmdParams, Desc) ->
|
||||||
|
|
||||||
-spec(format(io:format()) -> string()).
|
-spec(format(io:format()) -> string()).
|
||||||
format(Msg) ->
|
format(Msg) ->
|
||||||
lists:flatten(io_lib:format("~s", [Msg])).
|
lists:flatten(io_lib:format("~ts", [Msg])).
|
||||||
|
|
||||||
-spec(format(io:format(), [term()]) -> string()).
|
-spec(format(io:format(), [term()]) -> string()).
|
||||||
format(Format, Args) ->
|
format(Format, Args) ->
|
||||||
|
@ -170,7 +170,7 @@ format_usage(CmdParams, Desc) ->
|
||||||
CmdLines = split_cmd(CmdParams),
|
CmdLines = split_cmd(CmdParams),
|
||||||
DescLines = split_cmd(Desc),
|
DescLines = split_cmd(Desc),
|
||||||
lists:foldl(fun({CmdStr, DescStr}, Usage) ->
|
lists:foldl(fun({CmdStr, DescStr}, Usage) ->
|
||||||
Usage ++ format("~-70s# ~s~n", [CmdStr, DescStr])
|
Usage ++ format("~-70s# ~ts~n", [CmdStr, DescStr])
|
||||||
end, "", zip_cmd(CmdLines, DescLines)).
|
end, "", zip_cmd(CmdLines, DescLines)).
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
|
|
@ -131,15 +131,15 @@ start_listener(Type, ListenerName, #{bind := Bind} = Conf) ->
|
||||||
case do_start_listener(Type, ListenerName, Conf) of
|
case do_start_listener(Type, ListenerName, Conf) of
|
||||||
{ok, {skipped, Reason}} when Reason =:= listener_disabled;
|
{ok, {skipped, Reason}} when Reason =:= listener_disabled;
|
||||||
Reason =:= quic_app_missing ->
|
Reason =:= quic_app_missing ->
|
||||||
console_print("- Skip - starting listener ~s on ~s ~n due to ~p",
|
console_print("- Skip - starting listener ~ts on ~ts ~n due to ~p",
|
||||||
[listener_id(Type, ListenerName), format_addr(Bind), Reason]);
|
[listener_id(Type, ListenerName), format_addr(Bind), Reason]);
|
||||||
{ok, _} ->
|
{ok, _} ->
|
||||||
console_print("Listener ~s on ~s started.~n",
|
console_print("Listener ~ts on ~ts started.~n",
|
||||||
[listener_id(Type, ListenerName), format_addr(Bind)]);
|
[listener_id(Type, ListenerName), format_addr(Bind)]);
|
||||||
{error, {already_started, Pid}} ->
|
{error, {already_started, Pid}} ->
|
||||||
{error, {already_started, Pid}};
|
{error, {already_started, Pid}};
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
?ELOG("Failed to start listener ~s on ~s: ~0p~n",
|
?ELOG("Failed to start listener ~ts on ~ts: ~0p~n",
|
||||||
[listener_id(Type, ListenerName), format_addr(Bind), Reason]),
|
[listener_id(Type, ListenerName), format_addr(Bind), Reason]),
|
||||||
error(Reason)
|
error(Reason)
|
||||||
end.
|
end.
|
||||||
|
@ -180,11 +180,11 @@ stop_listener(ListenerId) ->
|
||||||
stop_listener(Type, ListenerName, #{bind := Bind} = Conf) ->
|
stop_listener(Type, ListenerName, #{bind := Bind} = Conf) ->
|
||||||
case do_stop_listener(Type, ListenerName, Conf) of
|
case do_stop_listener(Type, ListenerName, Conf) of
|
||||||
ok ->
|
ok ->
|
||||||
console_print("Listener ~s on ~s stopped.~n",
|
console_print("Listener ~ts on ~ts stopped.~n",
|
||||||
[listener_id(Type, ListenerName), format_addr(Bind)]),
|
[listener_id(Type, ListenerName), format_addr(Bind)]),
|
||||||
ok;
|
ok;
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
?ELOG("Failed to stop listener ~s on ~s: ~0p~n",
|
?ELOG("Failed to stop listener ~ts on ~ts: ~0p~n",
|
||||||
[listener_id(Type, ListenerName), format_addr(Bind), Reason]),
|
[listener_id(Type, ListenerName), format_addr(Bind), Reason]),
|
||||||
{error, Reason}
|
{error, Reason}
|
||||||
end.
|
end.
|
||||||
|
@ -342,9 +342,9 @@ merge_default(Options) ->
|
||||||
format_addr(Port) when is_integer(Port) ->
|
format_addr(Port) when is_integer(Port) ->
|
||||||
io_lib:format("0.0.0.0:~w", [Port]);
|
io_lib:format("0.0.0.0:~w", [Port]);
|
||||||
format_addr({Addr, Port}) when is_list(Addr) ->
|
format_addr({Addr, Port}) when is_list(Addr) ->
|
||||||
io_lib:format("~s:~w", [Addr, Port]);
|
io_lib:format("~ts:~w", [Addr, Port]);
|
||||||
format_addr({Addr, Port}) when is_tuple(Addr) ->
|
format_addr({Addr, Port}) when is_tuple(Addr) ->
|
||||||
io_lib:format("~s:~w", [inet:ntoa(Addr), Port]).
|
io_lib:format("~ts:~w", [inet:ntoa(Addr), Port]).
|
||||||
|
|
||||||
listener_id(Type, ListenerName) ->
|
listener_id(Type, ListenerName) ->
|
||||||
list_to_atom(lists:append([str(Type), ":", str(ListenerName)])).
|
list_to_atom(lists:append([str(Type), ":", str(ListenerName)])).
|
||||||
|
|
|
@ -32,7 +32,7 @@ enrich(Report, #{mfa := Mfa, line := Line}) ->
|
||||||
enrich(Report, _) -> Report.
|
enrich(Report, _) -> Report.
|
||||||
|
|
||||||
enrich_fmt({Fmt, Args}, #{mfa := Mfa, line := Line}) when is_list(Fmt) ->
|
enrich_fmt({Fmt, Args}, #{mfa := Mfa, line := Line}) when is_list(Fmt) ->
|
||||||
{Fmt ++ " mfa: ~s line: ~w", Args ++ [mfa(Mfa), Line]};
|
{Fmt ++ " mfa: ~ts line: ~w", Args ++ [mfa(Mfa), Line]};
|
||||||
enrich_fmt(Msg, _) ->
|
enrich_fmt(Msg, _) ->
|
||||||
Msg.
|
Msg.
|
||||||
|
|
||||||
|
|
|
@ -446,14 +446,14 @@ format_header(#mqtt_packet_header{type = Type,
|
||||||
true -> <<>>;
|
true -> <<>>;
|
||||||
false -> [", ", S]
|
false -> [", ", S]
|
||||||
end,
|
end,
|
||||||
io_lib:format("~s(Q~p, R~p, D~p~s)", [type_name(Type), QoS, i(Retain), i(Dup), S1]).
|
io_lib:format("~ts(Q~p, R~p, D~p~ts)", [type_name(Type), QoS, i(Retain), i(Dup), S1]).
|
||||||
|
|
||||||
format_variable(undefined, _) ->
|
format_variable(undefined, _) ->
|
||||||
undefined;
|
undefined;
|
||||||
format_variable(Variable, undefined) ->
|
format_variable(Variable, undefined) ->
|
||||||
format_variable(Variable);
|
format_variable(Variable);
|
||||||
format_variable(Variable, Payload) ->
|
format_variable(Variable, Payload) ->
|
||||||
io_lib:format("~s, Payload=~0p", [format_variable(Variable), Payload]).
|
io_lib:format("~ts, Payload=~0p", [format_variable(Variable), Payload]).
|
||||||
|
|
||||||
format_variable(#mqtt_packet_connect{
|
format_variable(#mqtt_packet_connect{
|
||||||
proto_ver = ProtoVer,
|
proto_ver = ProtoVer,
|
||||||
|
@ -468,10 +468,10 @@ format_variable(#mqtt_packet_connect{
|
||||||
will_payload = WillPayload,
|
will_payload = WillPayload,
|
||||||
username = Username,
|
username = Username,
|
||||||
password = Password}) ->
|
password = Password}) ->
|
||||||
Format = "ClientId=~s, ProtoName=~s, ProtoVsn=~p, CleanStart=~s, KeepAlive=~p, Username=~s, Password=~s",
|
Format = "ClientId=~ts, ProtoName=~ts, ProtoVsn=~p, CleanStart=~ts, KeepAlive=~p, Username=~ts, Password=~ts",
|
||||||
Args = [ClientId, ProtoName, ProtoVer, CleanStart, KeepAlive, Username, format_password(Password)],
|
Args = [ClientId, ProtoName, ProtoVer, CleanStart, KeepAlive, Username, format_password(Password)],
|
||||||
{Format1, Args1} = if
|
{Format1, Args1} = if
|
||||||
WillFlag -> {Format ++ ", Will(Q~p, R~p, Topic=~s, Payload=~0p)",
|
WillFlag -> {Format ++ ", Will(Q~p, R~p, Topic=~ts, Payload=~0p)",
|
||||||
Args ++ [WillQoS, i(WillRetain), WillTopic, WillPayload]};
|
Args ++ [WillQoS, i(WillRetain), WillTopic, WillPayload]};
|
||||||
true -> {Format, Args}
|
true -> {Format, Args}
|
||||||
end,
|
end,
|
||||||
|
@ -487,7 +487,7 @@ format_variable(#mqtt_packet_connack{ack_flags = AckFlags,
|
||||||
|
|
||||||
format_variable(#mqtt_packet_publish{topic_name = TopicName,
|
format_variable(#mqtt_packet_publish{topic_name = TopicName,
|
||||||
packet_id = PacketId}) ->
|
packet_id = PacketId}) ->
|
||||||
io_lib:format("Topic=~s, PacketId=~p", [TopicName, PacketId]);
|
io_lib:format("Topic=~ts, PacketId=~p", [TopicName, PacketId]);
|
||||||
|
|
||||||
format_variable(#mqtt_packet_puback{packet_id = PacketId,
|
format_variable(#mqtt_packet_puback{packet_id = PacketId,
|
||||||
reason_code = ReasonCode}) ->
|
reason_code = ReasonCode}) ->
|
||||||
|
|
|
@ -151,7 +151,7 @@ load_ext_plugin(PluginDir) ->
|
||||||
% catch
|
% catch
|
||||||
% throw : {conf_file_not_found, ConfFile} ->
|
% throw : {conf_file_not_found, ConfFile} ->
|
||||||
% %% this is maybe a dependency of an external plugin
|
% %% this is maybe a dependency of an external plugin
|
||||||
% ?LOG(debug, "config_load_error_ignored for app=~p, path=~s", [AppName, ConfFile]),
|
% ?LOG(debug, "config_load_error_ignored for app=~p, path=~ts", [AppName, ConfFile]),
|
||||||
% ok
|
% ok
|
||||||
% end.
|
% end.
|
||||||
|
|
||||||
|
|
|
@ -177,7 +177,7 @@ topics() ->
|
||||||
-spec(print_routes(emqx_types:topic()) -> ok).
|
-spec(print_routes(emqx_types:topic()) -> ok).
|
||||||
print_routes(Topic) ->
|
print_routes(Topic) ->
|
||||||
lists:foreach(fun(#route{topic = To, dest = Dest}) ->
|
lists:foreach(fun(#route{topic = To, dest = Dest}) ->
|
||||||
io:format("~s -> ~s~n", [To, Dest])
|
io:format("~ts -> ~ts~n", [To, Dest])
|
||||||
end, match_routes(Topic)).
|
end, match_routes(Topic)).
|
||||||
|
|
||||||
call(Router, Msg) ->
|
call(Router, Msg) ->
|
||||||
|
|
|
@ -1280,7 +1280,7 @@ validate_heap_size(Siz) ->
|
||||||
(1 bsl 27) - 1
|
(1 bsl 27) - 1
|
||||||
end,
|
end,
|
||||||
case Siz > MaxSiz of
|
case Siz > MaxSiz of
|
||||||
true -> error(io_lib:format("force_shutdown_policy: heap-size ~s is too large", [Siz]));
|
true -> error(io_lib:format("force_shutdown_policy: heap-size ~ts is too large", [Siz]));
|
||||||
false -> ok
|
false -> ok
|
||||||
end.
|
end.
|
||||||
parse_user_lookup_fun(StrConf) ->
|
parse_user_lookup_fun(StrConf) ->
|
||||||
|
|
|
@ -70,7 +70,7 @@ trace(publish, #message{from = From, topic = Topic, payload = Payload})
|
||||||
when is_binary(From); is_atom(From) ->
|
when is_binary(From); is_atom(From) ->
|
||||||
emqx_logger:info(#{topic => Topic,
|
emqx_logger:info(#{topic => Topic,
|
||||||
mfa => {?MODULE, ?FUNCTION_NAME, ?FUNCTION_ARITY} },
|
mfa => {?MODULE, ?FUNCTION_NAME, ?FUNCTION_ARITY} },
|
||||||
"PUBLISH to ~s: ~0p", [Topic, Payload]).
|
"PUBLISH to ~ts: ~0p", [Topic, Payload]).
|
||||||
|
|
||||||
%% @doc Start to trace clientid or topic.
|
%% @doc Start to trace clientid or topic.
|
||||||
-spec(start_trace(trace_who(), logger:level() | all, string()) -> ok | {error, term()}).
|
-spec(start_trace(trace_who(), logger:level() | all, string()) -> ok | {error, term()}).
|
||||||
|
@ -83,8 +83,8 @@ start_trace(Who, Level, LogFile) ->
|
||||||
try logger:compare_levels(Level, PrimaryLevel) of
|
try logger:compare_levels(Level, PrimaryLevel) of
|
||||||
lt ->
|
lt ->
|
||||||
{error,
|
{error,
|
||||||
io_lib:format("Cannot trace at a log level (~s) "
|
io_lib:format("Cannot trace at a log level (~ts) "
|
||||||
"lower than the primary log level (~s)",
|
"lower than the primary log level (~ts)",
|
||||||
[Level, PrimaryLevel])};
|
[Level, PrimaryLevel])};
|
||||||
_GtOrEq ->
|
_GtOrEq ->
|
||||||
install_trace_handler(Who, Level, LogFile)
|
install_trace_handler(Who, Level, LogFile)
|
||||||
|
|
|
@ -66,13 +66,13 @@ t_run_commands(_) ->
|
||||||
|
|
||||||
t_print(_) ->
|
t_print(_) ->
|
||||||
ok = emqx_ctl:print("help"),
|
ok = emqx_ctl:print("help"),
|
||||||
ok = emqx_ctl:print("~s", [help]),
|
ok = emqx_ctl:print("~ts", [help]),
|
||||||
ok = emqx_ctl:print("~s", [<<"~!@#$%^&*()">>]),
|
ok = emqx_ctl:print("~ts", [<<"~!@#$%^&*()">>]),
|
||||||
% - check the output of the usage
|
% - check the output of the usage
|
||||||
mock_print(),
|
mock_print(),
|
||||||
?assertEqual("help", emqx_ctl:print("help")),
|
?assertEqual("help", emqx_ctl:print("help")),
|
||||||
?assertEqual("help", emqx_ctl:print("~s", [help])),
|
?assertEqual("help", emqx_ctl:print("~ts", [help])),
|
||||||
?assertEqual("~!@#$%^&*()", emqx_ctl:print("~s", [<<"~!@#$%^&*()">>])),
|
?assertEqual("~!@#$%^&*()", emqx_ctl:print("~ts", [<<"~!@#$%^&*()">>])),
|
||||||
unmock_print().
|
unmock_print().
|
||||||
|
|
||||||
t_usage(_) ->
|
t_usage(_) ->
|
||||||
|
|
|
@ -290,24 +290,24 @@ t_will_msg(_) ->
|
||||||
?assertEqual(<<"topic">>, Msg2#message.topic).
|
?assertEqual(<<"topic">>, Msg2#message.topic).
|
||||||
|
|
||||||
t_format(_) ->
|
t_format(_) ->
|
||||||
io:format("~s", [emqx_packet:format(#mqtt_packet{header = #mqtt_packet_header{type = ?CONNACK, retain = true, dup = 0}, variable = undefined})]),
|
io:format("~ts", [emqx_packet:format(#mqtt_packet{header = #mqtt_packet_header{type = ?CONNACK, retain = true, dup = 0}, variable = undefined})]),
|
||||||
io:format("~s", [emqx_packet:format(#mqtt_packet{header = #mqtt_packet_header{type = ?CONNACK}, variable = 1, payload = <<"payload">>})]),
|
io:format("~ts", [emqx_packet:format(#mqtt_packet{header = #mqtt_packet_header{type = ?CONNACK}, variable = 1, payload = <<"payload">>})]),
|
||||||
io:format("~s", [emqx_packet:format(?CONNECT_PACKET(#mqtt_packet_connect{will_flag = true,
|
io:format("~ts", [emqx_packet:format(?CONNECT_PACKET(#mqtt_packet_connect{will_flag = true,
|
||||||
will_retain = true,
|
will_retain = true,
|
||||||
will_qos = ?QOS_2,
|
will_qos = ?QOS_2,
|
||||||
will_topic = <<"topic">>,
|
will_topic = <<"topic">>,
|
||||||
will_payload = <<"payload">>}))]),
|
will_payload = <<"payload">>}))]),
|
||||||
io:format("~s", [emqx_packet:format(?CONNECT_PACKET(#mqtt_packet_connect{password = password}))]),
|
io:format("~ts", [emqx_packet:format(?CONNECT_PACKET(#mqtt_packet_connect{password = password}))]),
|
||||||
io:format("~s", [emqx_packet:format(?CONNACK_PACKET(?CONNACK_SERVER))]),
|
io:format("~ts", [emqx_packet:format(?CONNACK_PACKET(?CONNACK_SERVER))]),
|
||||||
io:format("~s", [emqx_packet:format(?PUBLISH_PACKET(?QOS_1, 1))]),
|
io:format("~ts", [emqx_packet:format(?PUBLISH_PACKET(?QOS_1, 1))]),
|
||||||
io:format("~s", [emqx_packet:format(?PUBLISH_PACKET(?QOS_2, <<"topic">>, 10, <<"payload">>))]),
|
io:format("~ts", [emqx_packet:format(?PUBLISH_PACKET(?QOS_2, <<"topic">>, 10, <<"payload">>))]),
|
||||||
io:format("~s", [emqx_packet:format(?PUBACK_PACKET(?PUBACK, 98))]),
|
io:format("~ts", [emqx_packet:format(?PUBACK_PACKET(?PUBACK, 98))]),
|
||||||
io:format("~s", [emqx_packet:format(?PUBREL_PACKET(99))]),
|
io:format("~ts", [emqx_packet:format(?PUBREL_PACKET(99))]),
|
||||||
io:format("~s", [emqx_packet:format(?SUBSCRIBE_PACKET(15, [{<<"topic">>, ?QOS_0}, {<<"topic1">>, ?QOS_1}]))]),
|
io:format("~ts", [emqx_packet:format(?SUBSCRIBE_PACKET(15, [{<<"topic">>, ?QOS_0}, {<<"topic1">>, ?QOS_1}]))]),
|
||||||
io:format("~s", [emqx_packet:format(?SUBACK_PACKET(40, [?QOS_0, ?QOS_1]))]),
|
io:format("~ts", [emqx_packet:format(?SUBACK_PACKET(40, [?QOS_0, ?QOS_1]))]),
|
||||||
io:format("~s", [emqx_packet:format(?UNSUBSCRIBE_PACKET(89, [<<"t">>, <<"t2">>]))]),
|
io:format("~ts", [emqx_packet:format(?UNSUBSCRIBE_PACKET(89, [<<"t">>, <<"t2">>]))]),
|
||||||
io:format("~s", [emqx_packet:format(?UNSUBACK_PACKET(90))]),
|
io:format("~ts", [emqx_packet:format(?UNSUBACK_PACKET(90))]),
|
||||||
io:format("~s", [emqx_packet:format(?DISCONNECT_PACKET(128))]).
|
io:format("~ts", [emqx_packet:format(?DISCONNECT_PACKET(128))]).
|
||||||
|
|
||||||
t_parse_empty_publish(_) ->
|
t_parse_empty_publish(_) ->
|
||||||
%% 52: 0011(type=PUBLISH) 0100 (QoS=2)
|
%% 52: 0011(type=PUBLISH) 0100 (QoS=2)
|
||||||
|
|
|
@ -31,14 +31,14 @@ init_per_suite(Config) ->
|
||||||
DataPath = proplists:get_value(data_dir, Config),
|
DataPath = proplists:get_value(data_dir, Config),
|
||||||
AppPath = filename:join([DataPath, "emqx_mini_plugin"]),
|
AppPath = filename:join([DataPath, "emqx_mini_plugin"]),
|
||||||
HoconPath = filename:join([DataPath, "emqx_hocon_plugin"]),
|
HoconPath = filename:join([DataPath, "emqx_hocon_plugin"]),
|
||||||
Cmd = lists:flatten(io_lib:format("cd ~s && make", [AppPath])),
|
Cmd = lists:flatten(io_lib:format("cd ~ts && make", [AppPath])),
|
||||||
CmdPath = lists:flatten(io_lib:format("cd ~s && make", [HoconPath])),
|
CmdPath = lists:flatten(io_lib:format("cd ~ts && make", [HoconPath])),
|
||||||
|
|
||||||
ct:pal("Executing ~s~n", [Cmd]),
|
ct:pal("Executing ~ts~n", [Cmd]),
|
||||||
ct:pal("~n ~s~n", [os:cmd(Cmd)]),
|
ct:pal("~n ~ts~n", [os:cmd(Cmd)]),
|
||||||
|
|
||||||
ct:pal("Executing ~s~n", [CmdPath]),
|
ct:pal("Executing ~ts~n", [CmdPath]),
|
||||||
ct:pal("~n ~s~n", [os:cmd(CmdPath)]),
|
ct:pal("~n ~ts~n", [os:cmd(CmdPath)]),
|
||||||
|
|
||||||
emqx_ct_helpers:boot_modules([]),
|
emqx_ct_helpers:boot_modules([]),
|
||||||
emqx_ct_helpers:start_apps([]),
|
emqx_ct_helpers:start_apps([]),
|
||||||
|
|
|
@ -65,7 +65,7 @@ handle_msg(ReqMsg, RequestHandler, Parent) ->
|
||||||
props = RspProps,
|
props = RspProps,
|
||||||
payload = RspPayload
|
payload = RspPayload
|
||||||
},
|
},
|
||||||
emqx_logger:debug("~p sending response msg to topic ~s with~n"
|
emqx_logger:debug("~p sending response msg to topic ~ts with~n"
|
||||||
"corr-data=~p~npayload=~p",
|
"corr-data=~p~npayload=~p",
|
||||||
[?MODULE, RspTopic, CorrData, RspPayload]),
|
[?MODULE, RspTopic, CorrData, RspPayload]),
|
||||||
ok = send_response(RspMsg);
|
ok = send_response(RspMsg);
|
||||||
|
|
|
@ -214,5 +214,5 @@ bench(Case, Fun, Args) ->
|
||||||
[fun(_) -> apply(Fun, Args) end,
|
[fun(_) -> apply(Fun, Args) end,
|
||||||
lists:seq(1, ?N)
|
lists:seq(1, ?N)
|
||||||
]),
|
]),
|
||||||
ct:pal("Time consumed by ~s: ~.3f(us)~nCall ~s per second: ~w",
|
ct:pal("Time consumed by ~ts: ~.3f(us)~nCall ~ts per second: ~w",
|
||||||
[Case, Time/?N, Case, (?N * 1000000) div Time]).
|
[Case, Time/?N, Case, (?N * 1000000) div Time]).
|
||||||
|
|
|
@ -1991,13 +1991,13 @@ convert_certs(Config) ->
|
||||||
serialize_error({not_found, {authenticator, ID}}) ->
|
serialize_error({not_found, {authenticator, ID}}) ->
|
||||||
{404, #{code => <<"NOT_FOUND">>,
|
{404, #{code => <<"NOT_FOUND">>,
|
||||||
message => list_to_binary(
|
message => list_to_binary(
|
||||||
io_lib:format("Authenticator '~s' does not exist", [ID])
|
io_lib:format("Authenticator '~ts' does not exist", [ID])
|
||||||
)}};
|
)}};
|
||||||
|
|
||||||
serialize_error({not_found, {listener, ID}}) ->
|
serialize_error({not_found, {listener, ID}}) ->
|
||||||
{404, #{code => <<"NOT_FOUND">>,
|
{404, #{code => <<"NOT_FOUND">>,
|
||||||
message => list_to_binary(
|
message => list_to_binary(
|
||||||
io_lib:format("Listener '~s' does not exist", [ID])
|
io_lib:format("Listener '~ts' does not exist", [ID])
|
||||||
)}};
|
)}};
|
||||||
|
|
||||||
serialize_error({not_found, {chain, ?GLOBAL}}) ->
|
serialize_error({not_found, {chain, ?GLOBAL}}) ->
|
||||||
|
@ -2007,13 +2007,13 @@ serialize_error({not_found, {chain, ?GLOBAL}}) ->
|
||||||
serialize_error({not_found, {chain, Name}}) ->
|
serialize_error({not_found, {chain, Name}}) ->
|
||||||
{400, #{code => <<"BAD_REQUEST">>,
|
{400, #{code => <<"BAD_REQUEST">>,
|
||||||
message => list_to_binary(
|
message => list_to_binary(
|
||||||
io_lib:format("No authentication has been create for listener '~s'", [Name])
|
io_lib:format("No authentication has been create for listener '~ts'", [Name])
|
||||||
)}};
|
)}};
|
||||||
|
|
||||||
serialize_error({already_exists, {authenticator, ID}}) ->
|
serialize_error({already_exists, {authenticator, ID}}) ->
|
||||||
{409, #{code => <<"ALREADY_EXISTS">>,
|
{409, #{code => <<"ALREADY_EXISTS">>,
|
||||||
message => list_to_binary(
|
message => list_to_binary(
|
||||||
io_lib:format("Authenticator '~s' already exist", [ID])
|
io_lib:format("Authenticator '~ts' already exist", [ID])
|
||||||
)}};
|
)}};
|
||||||
|
|
||||||
serialize_error(no_available_provider) ->
|
serialize_error(no_available_provider) ->
|
||||||
|
|
|
@ -202,13 +202,13 @@ init_source(#{type := file,
|
||||||
{ok, Terms} ->
|
{ok, Terms} ->
|
||||||
[emqx_authz_rule:compile(Term) || Term <- Terms];
|
[emqx_authz_rule:compile(Term) || Term <- Terms];
|
||||||
{error, eacces} ->
|
{error, eacces} ->
|
||||||
?LOG(alert, "Insufficient permissions to read the ~s file", [Path]),
|
?LOG(alert, "Insufficient permissions to read the ~ts file", [Path]),
|
||||||
error(eaccess);
|
error(eaccess);
|
||||||
{error, enoent} ->
|
{error, enoent} ->
|
||||||
?LOG(alert, "The ~s file does not exist", [Path]),
|
?LOG(alert, "The ~ts file does not exist", [Path]),
|
||||||
error(enoent);
|
error(enoent);
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
?LOG(alert, "Failed to read ~s: ~p", [Path, Reason]),
|
?LOG(alert, "Failed to read ~ts: ~p", [Path, Reason]),
|
||||||
error(Reason)
|
error(Reason)
|
||||||
end,
|
end,
|
||||||
Source#{annotations => #{rules => Rules}};
|
Source#{annotations => #{rules => Rules}};
|
||||||
|
@ -315,7 +315,7 @@ find_action_in_hooks() ->
|
||||||
Action.
|
Action.
|
||||||
|
|
||||||
gen_id(Type) ->
|
gen_id(Type) ->
|
||||||
iolist_to_binary([io_lib:format("~s_~s",[?APP, Type])]).
|
iolist_to_binary([io_lib:format("~ts_~ts",[?APP, Type])]).
|
||||||
|
|
||||||
create_resource(#{type := DB,
|
create_resource(#{type := DB,
|
||||||
annotations := #{id := ResourceID}} = Source) ->
|
annotations := #{id := ResourceID}} = Source) ->
|
||||||
|
|
|
@ -177,7 +177,7 @@ query() ->
|
||||||
connector_fields(DB) ->
|
connector_fields(DB) ->
|
||||||
connector_fields(DB, config).
|
connector_fields(DB, config).
|
||||||
connector_fields(DB, Fields) ->
|
connector_fields(DB, Fields) ->
|
||||||
Mod0 = io_lib:format("~s_~s",[emqx_connector, DB]),
|
Mod0 = io_lib:format("~ts_~ts",[emqx_connector, DB]),
|
||||||
Mod = try
|
Mod = try
|
||||||
list_to_existing_atom(Mod0)
|
list_to_existing_atom(Mod0)
|
||||||
catch
|
catch
|
||||||
|
|
|
@ -69,13 +69,13 @@ start_listeners() ->
|
||||||
[begin
|
[begin
|
||||||
Minirest = maps:put(protocol, Protocol, BaseMinirest),
|
Minirest = maps:put(protocol, Protocol, BaseMinirest),
|
||||||
{ok, _} = minirest:start(Name, RanchOptions, Minirest),
|
{ok, _} = minirest:start(Name, RanchOptions, Minirest),
|
||||||
?ULOG("Start listener ~s on ~p successfully.~n", [Name, Port])
|
?ULOG("Start listener ~ts on ~p successfully.~n", [Name, Port])
|
||||||
end || {Name, Protocol, Port, RanchOptions} <- listeners()].
|
end || {Name, Protocol, Port, RanchOptions} <- listeners()].
|
||||||
|
|
||||||
stop_listeners() ->
|
stop_listeners() ->
|
||||||
[begin
|
[begin
|
||||||
ok = minirest:stop(Name),
|
ok = minirest:stop(Name),
|
||||||
?ULOG("Stop listener ~s on ~p successfully.~n", [Name, Port])
|
?ULOG("Stop listener ~ts on ~p successfully.~n", [Name, Port])
|
||||||
end || {Name, _, Port, _} <- listeners()].
|
end || {Name, _, Port, _} <- listeners()].
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
|
|
@ -75,7 +75,7 @@ translate_req(Request, #{module := Module, path := Path, method := Method}) ->
|
||||||
catch throw:Error ->
|
catch throw:Error ->
|
||||||
{_, [{validation_error, ValidErr}]} = Error,
|
{_, [{validation_error, ValidErr}]} = Error,
|
||||||
#{path := Key, reason := Reason} = ValidErr,
|
#{path := Key, reason := Reason} = ValidErr,
|
||||||
{400, 'BAD_REQUEST', iolist_to_binary(io_lib:format("~s : ~p", [Key, Reason]))}
|
{400, 'BAD_REQUEST', iolist_to_binary(io_lib:format("~ts : ~p", [Key, Reason]))}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
namespace() -> "public".
|
namespace() -> "public".
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
cli(["server", "list"]) ->
|
cli(["server", "list"]) ->
|
||||||
if_enabled(fun() ->
|
if_enabled(fun() ->
|
||||||
ServerNames = emqx_exhook:list(),
|
ServerNames = emqx_exhook:list(),
|
||||||
[emqx_ctl:print("Server(~s)~n", [format(Name)]) || Name <- ServerNames]
|
[emqx_ctl:print("Server(~ts)~n", [format(Name)]) || Name <- ServerNames]
|
||||||
end);
|
end);
|
||||||
|
|
||||||
cli(["server", "enable", Name]) ->
|
cli(["server", "enable", Name]) ->
|
||||||
|
@ -78,7 +78,7 @@ format(Name) ->
|
||||||
case emqx_exhook_mngr:server(Name) of
|
case emqx_exhook_mngr:server(Name) of
|
||||||
undefined ->
|
undefined ->
|
||||||
lists:flatten(
|
lists:flatten(
|
||||||
io_lib:format("name=~s, hooks=#{}, active=false", [Name]));
|
io_lib:format("name=~ts, hooks=#{}, active=false", [Name]));
|
||||||
Server ->
|
Server ->
|
||||||
emqx_exhook_server:format(Server)
|
emqx_exhook_server:format(Server)
|
||||||
end.
|
end.
|
||||||
|
|
|
@ -185,7 +185,7 @@ handle_info({timeout, _Ref, {reload, Name}}, State) ->
|
||||||
{error, not_found} ->
|
{error, not_found} ->
|
||||||
{noreply, NState};
|
{noreply, NState};
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
?LOG(warning, "Failed to reload exhook callback server \"~s\", "
|
?LOG(warning, "Failed to reload exhook callback server \"~ts\", "
|
||||||
"Reason: ~0p", [Name, Reason]),
|
"Reason: ~0p", [Name, Reason]),
|
||||||
{noreply, ensure_reload_timer(NState)}
|
{noreply, ensure_reload_timer(NState)}
|
||||||
end;
|
end;
|
||||||
|
@ -231,7 +231,7 @@ do_load_server(Name, State0 = #state{
|
||||||
{ok, ServerState} ->
|
{ok, ServerState} ->
|
||||||
save(Name, ServerState),
|
save(Name, ServerState),
|
||||||
?LOG(info, "Load exhook callback server "
|
?LOG(info, "Load exhook callback server "
|
||||||
"\"~s\" successfully!", [Name]),
|
"\"~ts\" successfully!", [Name]),
|
||||||
{ok, State#state{
|
{ok, State#state{
|
||||||
running = maps:put(Name, Options, Running),
|
running = maps:put(Name, Options, Running),
|
||||||
waiting = maps:remove(Name, Waiting),
|
waiting = maps:remove(Name, Waiting),
|
||||||
|
|
|
@ -91,7 +91,7 @@ load(Name, Opts0, ReqOpts) ->
|
||||||
{ok, HookSpecs} ->
|
{ok, HookSpecs} ->
|
||||||
%% Reigster metrics
|
%% Reigster metrics
|
||||||
Prefix = lists:flatten(
|
Prefix = lists:flatten(
|
||||||
io_lib:format("exhook.~s.", [Name])),
|
io_lib:format("exhook.~ts.", [Name])),
|
||||||
ensure_metrics(Prefix, HookSpecs),
|
ensure_metrics(Prefix, HookSpecs),
|
||||||
%% Ensure hooks
|
%% Ensure hooks
|
||||||
ensure_hooks(HookSpecs),
|
ensure_hooks(HookSpecs),
|
||||||
|
@ -129,7 +129,7 @@ channel_opts(Opts = #{url := URL}) ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
format_http_uri(Scheme, Host, Port) ->
|
format_http_uri(Scheme, Host, Port) ->
|
||||||
lists:flatten(io_lib:format("~s://~s:~w", [Scheme, Host, Port])).
|
lists:flatten(io_lib:format("~ts://~ts:~w", [Scheme, Host, Port])).
|
||||||
|
|
||||||
filter(Ls) ->
|
filter(Ls) ->
|
||||||
[ E || E <- Ls, E /= undefined].
|
[ E || E <- Ls, E /= undefined].
|
||||||
|
@ -194,7 +194,7 @@ ensure_hooks(HookSpecs) ->
|
||||||
lists:foreach(fun(Hookpoint) ->
|
lists:foreach(fun(Hookpoint) ->
|
||||||
case lists:keyfind(Hookpoint, 1, ?ENABLED_HOOKS) of
|
case lists:keyfind(Hookpoint, 1, ?ENABLED_HOOKS) of
|
||||||
false ->
|
false ->
|
||||||
?LOG(error, "Unknown name ~s to hook, skip it!", [Hookpoint]);
|
?LOG(error, "Unknown name ~ts to hook, skip it!", [Hookpoint]);
|
||||||
{Hookpoint, {M, F, A}} ->
|
{Hookpoint, {M, F, A}} ->
|
||||||
emqx_hooks:put(Hookpoint, {M, F, A}),
|
emqx_hooks:put(Hookpoint, {M, F, A}),
|
||||||
ets:update_counter(?CNTER, Hookpoint, {2, 1}, {Hookpoint, 0})
|
ets:update_counter(?CNTER, Hookpoint, {2, 1}, {Hookpoint, 0})
|
||||||
|
@ -217,7 +217,7 @@ may_unload_hooks(HookSpecs) ->
|
||||||
|
|
||||||
format(#server{name = Name, hookspec = Hooks}) ->
|
format(#server{name = Name, hookspec = Hooks}) ->
|
||||||
lists:flatten(
|
lists:flatten(
|
||||||
io_lib:format("name=~s, hooks=~0p, active=true", [Name, Hooks])).
|
io_lib:format("name=~ts, hooks=~0p, active=true", [Name, Hooks])).
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% APIs
|
%% APIs
|
||||||
|
|
|
@ -663,7 +663,7 @@ handle_incoming(Packet, State = #state{
|
||||||
}) ->
|
}) ->
|
||||||
Ctx = ChannMod:info(ctx, Channel),
|
Ctx = ChannMod:info(ctx, Channel),
|
||||||
ok = inc_incoming_stats(Ctx, FrameMod, Packet),
|
ok = inc_incoming_stats(Ctx, FrameMod, Packet),
|
||||||
?LOG(debug, "RECV ~s", [FrameMod:format(Packet)]),
|
?LOG(debug, "RECV ~ts", [FrameMod:format(Packet)]),
|
||||||
with_channel(handle_in, [Packet], State).
|
with_channel(handle_in, [Packet], State).
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
@ -715,12 +715,12 @@ serialize_and_inc_stats_fun(#state{
|
||||||
Ctx = ChannMod:info(ctx, Channel),
|
Ctx = ChannMod:info(ctx, Channel),
|
||||||
fun(Packet) ->
|
fun(Packet) ->
|
||||||
case FrameMod:serialize_pkt(Packet, Serialize) of
|
case FrameMod:serialize_pkt(Packet, Serialize) of
|
||||||
<<>> -> ?LOG(warning, "~s is discarded due to the frame is too large!",
|
<<>> -> ?LOG(warning, "~ts is discarded due to the frame is too large!",
|
||||||
[FrameMod:format(Packet)]),
|
[FrameMod:format(Packet)]),
|
||||||
ok = emqx_gateway_ctx:metrics_inc(Ctx, 'delivery.dropped.too_large'),
|
ok = emqx_gateway_ctx:metrics_inc(Ctx, 'delivery.dropped.too_large'),
|
||||||
ok = emqx_gateway_ctx:metrics_inc(Ctx, 'delivery.dropped'),
|
ok = emqx_gateway_ctx:metrics_inc(Ctx, 'delivery.dropped'),
|
||||||
<<>>;
|
<<>>;
|
||||||
Data -> ?LOG(debug, "SEND ~s", [FrameMod:format(Packet)]),
|
Data -> ?LOG(debug, "SEND ~ts", [FrameMod:format(Packet)]),
|
||||||
ok = inc_outgoing_stats(Ctx, FrameMod, Packet),
|
ok = inc_outgoing_stats(Ctx, FrameMod, Packet),
|
||||||
Data
|
Data
|
||||||
end
|
end
|
||||||
|
|
|
@ -331,7 +331,7 @@ auth_connect(_Input, Channel = #channel{ctx = Ctx,
|
||||||
{ok, NClientInfo} ->
|
{ok, NClientInfo} ->
|
||||||
{ok, Channel#channel{clientinfo = NClientInfo}};
|
{ok, Channel#channel{clientinfo = NClientInfo}};
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
?LOG(warning, "Client ~s (Username: '~s') login failed for ~0p",
|
?LOG(warning, "Client ~ts (Username: '~ts') login failed for ~0p",
|
||||||
[ClientId, Username, Reason]),
|
[ClientId, Username, Reason]),
|
||||||
{error, Reason}
|
{error, Reason}
|
||||||
end.
|
end.
|
||||||
|
@ -473,7 +473,7 @@ process_connection({open, Req}, Result, Channel, Iter) ->
|
||||||
{ok, _Input, NChannel} ->
|
{ok, _Input, NChannel} ->
|
||||||
process_connect(ensure_connected(NChannel), Req, Result, Iter);
|
process_connect(ensure_connected(NChannel), Req, Result, Iter);
|
||||||
{error, ReasonCode, NChannel} ->
|
{error, ReasonCode, NChannel} ->
|
||||||
ErrMsg = io_lib:format("Login Failed: ~s", [ReasonCode]),
|
ErrMsg = io_lib:format("Login Failed: ~ts", [ReasonCode]),
|
||||||
Payload = erlang:list_to_binary(lists:flatten(ErrMsg)),
|
Payload = erlang:list_to_binary(lists:flatten(ErrMsg)),
|
||||||
iter(Iter,
|
iter(Iter,
|
||||||
reply({error, bad_request}, Payload, Req, Result),
|
reply({error, bad_request}, Payload, Req, Result),
|
||||||
|
|
|
@ -67,7 +67,7 @@ on_gateway_update(Config, Gateway, GwState = #{ctx := Ctx}) ->
|
||||||
on_gateway_load(Gateway#{config => Config}, Ctx)
|
on_gateway_load(Gateway#{config => Config}, Ctx)
|
||||||
catch
|
catch
|
||||||
Class : Reason : Stk ->
|
Class : Reason : Stk ->
|
||||||
logger:error("Failed to update ~s; "
|
logger:error("Failed to update ~ts; "
|
||||||
"reason: {~0p, ~0p} stacktrace: ~0p",
|
"reason: {~0p, ~0p} stacktrace: ~0p",
|
||||||
[GwName, Class, Reason, Stk]),
|
[GwName, Class, Reason, Stk]),
|
||||||
{error, {Class, Reason}}
|
{error, {Class, Reason}}
|
||||||
|
@ -89,11 +89,11 @@ start_listener(GwName, Ctx, {Type, LisName, ListenOn, SocketOpts, Cfg}) ->
|
||||||
ListenOnStr = emqx_gateway_utils:format_listenon(ListenOn),
|
ListenOnStr = emqx_gateway_utils:format_listenon(ListenOn),
|
||||||
case start_listener(GwName, Ctx, Type, LisName, ListenOn, SocketOpts, Cfg) of
|
case start_listener(GwName, Ctx, Type, LisName, ListenOn, SocketOpts, Cfg) of
|
||||||
{ok, Pid} ->
|
{ok, Pid} ->
|
||||||
?ULOG("Gateway ~s:~s:~s on ~s started.~n",
|
?ULOG("Gateway ~ts:~ts:~ts on ~ts started.~n",
|
||||||
[GwName, Type, LisName, ListenOnStr]),
|
[GwName, Type, LisName, ListenOnStr]),
|
||||||
Pid;
|
Pid;
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
?ELOG("Failed to start gateway ~s:~s:~s on ~s: ~0p~n",
|
?ELOG("Failed to start gateway ~ts:~ts:~ts on ~ts: ~0p~n",
|
||||||
[GwName, Type, LisName, ListenOnStr, Reason]),
|
[GwName, Type, LisName, ListenOnStr, Reason]),
|
||||||
throw({badconf, Reason})
|
throw({badconf, Reason})
|
||||||
end.
|
end.
|
||||||
|
@ -118,10 +118,10 @@ stop_listener(GwName, {Type, LisName, ListenOn, SocketOpts, Cfg}) ->
|
||||||
StopRet = stop_listener(GwName, Type, LisName, ListenOn, SocketOpts, Cfg),
|
StopRet = stop_listener(GwName, Type, LisName, ListenOn, SocketOpts, Cfg),
|
||||||
ListenOnStr = emqx_gateway_utils:format_listenon(ListenOn),
|
ListenOnStr = emqx_gateway_utils:format_listenon(ListenOn),
|
||||||
case StopRet of
|
case StopRet of
|
||||||
ok -> ?ULOG("Gateway ~s:~s:~s on ~s stopped.~n",
|
ok -> ?ULOG("Gateway ~ts:~ts:~ts on ~ts stopped.~n",
|
||||||
[GwName, Type, LisName, ListenOnStr]);
|
[GwName, Type, LisName, ListenOnStr]);
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
?ELOG("Failed to stop gateway ~s:~s:~s on ~s: ~0p~n",
|
?ELOG("Failed to stop gateway ~ts:~ts:~ts on ~ts: ~0p~n",
|
||||||
[GwName, Type, LisName, ListenOnStr, Reason])
|
[GwName, Type, LisName, ListenOnStr, Reason])
|
||||||
end,
|
end,
|
||||||
StopRet.
|
StopRet.
|
||||||
|
|
|
@ -109,7 +109,7 @@ clients_insta(get, #{ bindings := #{name := Name0,
|
||||||
[ClientInfo] ->
|
[ClientInfo] ->
|
||||||
{200, ClientInfo};
|
{200, ClientInfo};
|
||||||
[ClientInfo | _More] ->
|
[ClientInfo | _More] ->
|
||||||
?LOG(warning, "More than one client info was returned on ~s",
|
?LOG(warning, "More than one client info was returned on ~ts",
|
||||||
[ClientId]),
|
[ClientId]),
|
||||||
{200, ClientInfo};
|
{200, ClientInfo};
|
||||||
[] ->
|
[] ->
|
||||||
|
|
|
@ -51,10 +51,10 @@ gateway_type_searching() ->
|
||||||
reg(Mod) ->
|
reg(Mod) ->
|
||||||
try
|
try
|
||||||
Mod:reg(),
|
Mod:reg(),
|
||||||
?LOG(info, "Register ~s gateway application successfully!", [Mod])
|
?LOG(info, "Register ~ts gateway application successfully!", [Mod])
|
||||||
catch
|
catch
|
||||||
Class : Reason : Stk ->
|
Class : Reason : Stk ->
|
||||||
?LOG(error, "Failed to register ~s gateway application: {~p, ~p}\n"
|
?LOG(error, "Failed to register ~ts gateway application: {~p, ~p}\n"
|
||||||
"Stacktrace: ~0p",
|
"Stacktrace: ~0p",
|
||||||
[Mod, Class, Reason, Stk])
|
[Mod, Class, Reason, Stk])
|
||||||
end.
|
end.
|
||||||
|
@ -67,14 +67,14 @@ load_gateway_by_default([]) ->
|
||||||
load_gateway_by_default([{Type, Confs}|More]) ->
|
load_gateway_by_default([{Type, Confs}|More]) ->
|
||||||
case emqx_gateway_registry:lookup(Type) of
|
case emqx_gateway_registry:lookup(Type) of
|
||||||
undefined ->
|
undefined ->
|
||||||
?LOG(error, "Skip to load ~s gateway, because it is not registered",
|
?LOG(error, "Skip to load ~ts gateway, because it is not registered",
|
||||||
[Type]);
|
[Type]);
|
||||||
_ ->
|
_ ->
|
||||||
case emqx_gateway:load(Type, Confs) of
|
case emqx_gateway:load(Type, Confs) of
|
||||||
{ok, _} ->
|
{ok, _} ->
|
||||||
?LOG(debug, "Load ~s gateway successfully!", [Type]);
|
?LOG(debug, "Load ~ts gateway successfully!", [Type]);
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
?LOG(error, "Failed to load ~s gateway: ~0p", [Type, Reason])
|
?LOG(error, "Failed to load ~ts gateway: ~0p", [Type, Reason])
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
load_gateway_by_default(More).
|
load_gateway_by_default(More).
|
||||||
|
|
|
@ -53,7 +53,7 @@ gateway(["list"]) ->
|
||||||
lists:foreach(fun(#{name := Name} = Gateway) ->
|
lists:foreach(fun(#{name := Name} = Gateway) ->
|
||||||
%% TODO: More infos: listeners?, connected?
|
%% TODO: More infos: listeners?, connected?
|
||||||
Status = maps:get(status, Gateway, stopped),
|
Status = maps:get(status, Gateway, stopped),
|
||||||
print("Gateway(name=~s, status=~s)~n", [Name, Status])
|
print("Gateway(name=~ts, status=~ts)~n", [Name, Status])
|
||||||
end, emqx_gateway:list());
|
end, emqx_gateway:list());
|
||||||
|
|
||||||
gateway(["lookup", Name]) ->
|
gateway(["lookup", Name]) ->
|
||||||
|
@ -123,7 +123,7 @@ gateway(_) ->
|
||||||
'gateway-registry'(["list"]) ->
|
'gateway-registry'(["list"]) ->
|
||||||
lists:foreach(
|
lists:foreach(
|
||||||
fun({Name, #{cbkmod := CbMod}}) ->
|
fun({Name, #{cbkmod := CbMod}}) ->
|
||||||
print("Registered Name: ~s, Callback Module: ~s~n", [Name, CbMod])
|
print("Registered Name: ~ts, Callback Module: ~ts~n", [Name, CbMod])
|
||||||
end,
|
end,
|
||||||
emqx_gateway_registry:list());
|
emqx_gateway_registry:list());
|
||||||
|
|
||||||
|
@ -229,10 +229,10 @@ print_record({client, {_, Infos, Stats}}) ->
|
||||||
connected_at => ConnectedAt
|
connected_at => ConnectedAt
|
||||||
},
|
},
|
||||||
|
|
||||||
print("Client(~s, username=~s, peername=~s, "
|
print("Client(~ts, username=~ts, peername=~ts, "
|
||||||
"clean_start=~s, keepalive=~w, "
|
"clean_start=~ts, keepalive=~w, "
|
||||||
"subscriptions=~w, delivered_msgs=~w, "
|
"subscriptions=~w, delivered_msgs=~w, "
|
||||||
"connected=~s, created_at=~w, connected_at=~w)~n",
|
"connected=~ts, created_at=~w, connected_at=~w)~n",
|
||||||
[format(K, maps:get(K, Info)) || K <- InfoKeys]).
|
[format(K, maps:get(K, Info)) || K <- InfoKeys]).
|
||||||
|
|
||||||
print(S) -> emqx_ctl:print(S).
|
print(S) -> emqx_ctl:print(S).
|
||||||
|
@ -243,7 +243,7 @@ format(_, undefined) ->
|
||||||
|
|
||||||
format(peername, {IPAddr, Port}) ->
|
format(peername, {IPAddr, Port}) ->
|
||||||
IPStr = emqx_mgmt_util:ntoa(IPAddr),
|
IPStr = emqx_mgmt_util:ntoa(IPAddr),
|
||||||
io_lib:format("~s:~p", [IPStr, Port]);
|
io_lib:format("~ts:~p", [IPStr, Port]);
|
||||||
|
|
||||||
format(_, Val) ->
|
format(_, Val) ->
|
||||||
Val.
|
Val.
|
||||||
|
|
|
@ -103,7 +103,7 @@ init([Gateway, Ctx, _GwDscrptr]) ->
|
||||||
},
|
},
|
||||||
case maps:get(enable, Config, true) of
|
case maps:get(enable, Config, true) of
|
||||||
false ->
|
false ->
|
||||||
?LOG(info, "Skipp to start ~s gateway due to disabled", [GwName]),
|
?LOG(info, "Skipp to start ~ts gateway due to disabled", [GwName]),
|
||||||
{ok, State};
|
{ok, State};
|
||||||
true ->
|
true ->
|
||||||
case cb_gateway_load(State) of
|
case cb_gateway_load(State) of
|
||||||
|
@ -266,13 +266,13 @@ do_create_authn_chain(ChainName, AuthConf) ->
|
||||||
case emqx_authentication:create_authenticator(ChainName, AuthConf) of
|
case emqx_authentication:create_authenticator(ChainName, AuthConf) of
|
||||||
{ok, _} -> ok;
|
{ok, _} -> ok;
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
?LOG(error, "Failed to create authenticator chain ~s, "
|
?LOG(error, "Failed to create authenticator chain ~ts, "
|
||||||
"reason: ~p, config: ~p",
|
"reason: ~p, config: ~p",
|
||||||
[ChainName, Reason, AuthConf]),
|
[ChainName, Reason, AuthConf]),
|
||||||
throw({badauth, Reason})
|
throw({badauth, Reason})
|
||||||
end;
|
end;
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
?LOG(error, "Falied to create authn chain ~s, reason ~p",
|
?LOG(error, "Falied to create authn chain ~ts, reason ~p",
|
||||||
[ChainName, Reason]),
|
[ChainName, Reason]),
|
||||||
throw({badauth, Reason})
|
throw({badauth, Reason})
|
||||||
end.
|
end.
|
||||||
|
@ -293,7 +293,7 @@ do_deinit_authn(Names) ->
|
||||||
ok -> ok;
|
ok -> ok;
|
||||||
{error, {not_found, _}} -> ok;
|
{error, {not_found, _}} -> ok;
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
?LOG(error, "Failed to clean authentication chain: ~s, "
|
?LOG(error, "Failed to clean authentication chain: ~ts, "
|
||||||
"reason: ~p", [ChainName, Reason])
|
"reason: ~p", [ChainName, Reason])
|
||||||
end
|
end
|
||||||
end, Names).
|
end, Names).
|
||||||
|
@ -388,7 +388,7 @@ cb_gateway_load(State = #state{name = GwName,
|
||||||
end
|
end
|
||||||
catch
|
catch
|
||||||
Class : Reason1 : Stk ->
|
Class : Reason1 : Stk ->
|
||||||
?LOG(error, "Failed to load ~s gateway (~0p, ~0p) "
|
?LOG(error, "Failed to load ~ts gateway (~0p, ~0p) "
|
||||||
"crashed: {~p, ~p}, stacktrace: ~0p",
|
"crashed: {~p, ~p}, stacktrace: ~0p",
|
||||||
[GwName, Gateway, Ctx,
|
[GwName, Gateway, Ctx,
|
||||||
Class, Reason1, Stk]),
|
Class, Reason1, Stk]),
|
||||||
|
@ -413,7 +413,7 @@ cb_gateway_update(Config,
|
||||||
end
|
end
|
||||||
catch
|
catch
|
||||||
Class : Reason1 : Stk ->
|
Class : Reason1 : Stk ->
|
||||||
?LOG(error, "Failed to update ~s gateway to config: ~0p crashed: "
|
?LOG(error, "Failed to update ~ts gateway to config: ~0p crashed: "
|
||||||
"{~p, ~p}, stacktrace: ~0p",
|
"{~p, ~p}, stacktrace: ~0p",
|
||||||
[GwName, Config, Class, Reason1, Stk]),
|
[GwName, Config, Class, Reason1, Stk]),
|
||||||
{error, {Class, Reason1, Stk}}
|
{error, {Class, Reason1, Stk}}
|
||||||
|
|
|
@ -112,9 +112,9 @@ apply(F, A2) when is_function(F),
|
||||||
format_listenon(Port) when is_integer(Port) ->
|
format_listenon(Port) when is_integer(Port) ->
|
||||||
io_lib:format("0.0.0.0:~w", [Port]);
|
io_lib:format("0.0.0.0:~w", [Port]);
|
||||||
format_listenon({Addr, Port}) when is_list(Addr) ->
|
format_listenon({Addr, Port}) when is_list(Addr) ->
|
||||||
io_lib:format("~s:~w", [Addr, Port]);
|
io_lib:format("~ts:~w", [Addr, Port]);
|
||||||
format_listenon({Addr, Port}) when is_tuple(Addr) ->
|
format_listenon({Addr, Port}) when is_tuple(Addr) ->
|
||||||
io_lib:format("~s:~w", [inet:ntoa(Addr), Port]).
|
io_lib:format("~ts:~w", [inet:ntoa(Addr), Port]).
|
||||||
|
|
||||||
parse_listenon(Port) when is_integer(Port) ->
|
parse_listenon(Port) when is_integer(Port) ->
|
||||||
Port;
|
Port;
|
||||||
|
|
|
@ -291,17 +291,17 @@ handle_call({auth, ClientInfo0, Password}, _From,
|
||||||
SessFun
|
SessFun
|
||||||
) of
|
) of
|
||||||
{ok, _Session} ->
|
{ok, _Session} ->
|
||||||
?LOG(debug, "Client ~s (Username: '~s') authorized successfully!",
|
?LOG(debug, "Client ~ts (Username: '~ts') authorized successfully!",
|
||||||
[ClientId, Username]),
|
[ClientId, Username]),
|
||||||
{reply, ok, [{event, connected}],
|
{reply, ok, [{event, connected}],
|
||||||
ensure_connected(Channel1#channel{clientinfo = NClientInfo})};
|
ensure_connected(Channel1#channel{clientinfo = NClientInfo})};
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
?LOG(warning, "Client ~s (Username: '~s') open session failed for ~0p",
|
?LOG(warning, "Client ~ts (Username: '~ts') open session failed for ~0p",
|
||||||
[ClientId, Username, Reason]),
|
[ClientId, Username, Reason]),
|
||||||
{reply, {error, ?RESP_PERMISSION_DENY, Reason}, Channel}
|
{reply, {error, ?RESP_PERMISSION_DENY, Reason}, Channel}
|
||||||
end;
|
end;
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
?LOG(warning, "Client ~s (Username: '~s') login failed for ~0p",
|
?LOG(warning, "Client ~ts (Username: '~ts') login failed for ~0p",
|
||||||
[ClientId, Username, Reason]),
|
[ClientId, Username, Reason]),
|
||||||
{reply, {error, ?RESP_PERMISSION_DENY, Reason}, Channel}
|
{reply, {error, ?RESP_PERMISSION_DENY, Reason}, Channel}
|
||||||
end;
|
end;
|
||||||
|
|
|
@ -60,7 +60,7 @@ start_grpc_server(GwName, Options = #{bind := ListenOn}) ->
|
||||||
[{ssl_options, SslOpts}]
|
[{ssl_options, SslOpts}]
|
||||||
end,
|
end,
|
||||||
_ = grpc:start_server(GwName, ListenOn, Services, SvrOptions),
|
_ = grpc:start_server(GwName, ListenOn, Services, SvrOptions),
|
||||||
?ULOG("Start ~s gRPC server on ~p successfully.~n", [GwName, ListenOn]).
|
?ULOG("Start ~ts gRPC server on ~p successfully.~n", [GwName, ListenOn]).
|
||||||
|
|
||||||
start_grpc_client_channel(_GwType, undefined) ->
|
start_grpc_client_channel(_GwType, undefined) ->
|
||||||
undefined;
|
undefined;
|
||||||
|
@ -71,7 +71,7 @@ start_grpc_client_channel(GwName, Options = #{address := UriStr}) ->
|
||||||
Port = maps:get(port, UriMap),
|
Port = maps:get(port, UriMap),
|
||||||
SvrAddr = lists:flatten(
|
SvrAddr = lists:flatten(
|
||||||
io_lib:format(
|
io_lib:format(
|
||||||
"~s://~s:~w", [Scheme, Host, Port])
|
"~ts://~ts:~w", [Scheme, Host, Port])
|
||||||
),
|
),
|
||||||
ClientOpts = case Scheme of
|
ClientOpts = case Scheme of
|
||||||
"https" ->
|
"https" ->
|
||||||
|
@ -118,7 +118,7 @@ on_gateway_update(Config, Gateway, GwState = #{ctx := Ctx}) ->
|
||||||
on_gateway_load(Gateway#{config => Config}, Ctx)
|
on_gateway_load(Gateway#{config => Config}, Ctx)
|
||||||
catch
|
catch
|
||||||
Class : Reason : Stk ->
|
Class : Reason : Stk ->
|
||||||
logger:error("Failed to update ~s; "
|
logger:error("Failed to update ~ts; "
|
||||||
"reason: {~0p, ~0p} stacktrace: ~0p",
|
"reason: {~0p, ~0p} stacktrace: ~0p",
|
||||||
[GwName, Class, Reason, Stk]),
|
[GwName, Class, Reason, Stk]),
|
||||||
{error, {Class, Reason}}
|
{error, {Class, Reason}}
|
||||||
|
@ -143,11 +143,11 @@ start_listener(GwName, Ctx, {Type, LisName, ListenOn, SocketOpts, Cfg}) ->
|
||||||
ListenOnStr = emqx_gateway_utils:format_listenon(ListenOn),
|
ListenOnStr = emqx_gateway_utils:format_listenon(ListenOn),
|
||||||
case start_listener(GwName, Ctx, Type, LisName, ListenOn, SocketOpts, Cfg) of
|
case start_listener(GwName, Ctx, Type, LisName, ListenOn, SocketOpts, Cfg) of
|
||||||
{ok, Pid} ->
|
{ok, Pid} ->
|
||||||
?ULOG("Gateway ~s:~s:~s on ~s started.~n",
|
?ULOG("Gateway ~ts:~ts:~ts on ~ts started.~n",
|
||||||
[GwName, Type, LisName, ListenOnStr]),
|
[GwName, Type, LisName, ListenOnStr]),
|
||||||
Pid;
|
Pid;
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
?ELOG("Failed to start gateway ~s:~s:~s on ~s: ~0p~n",
|
?ELOG("Failed to start gateway ~ts:~ts:~ts on ~ts: ~0p~n",
|
||||||
[GwName, Type, LisName, ListenOnStr, Reason]),
|
[GwName, Type, LisName, ListenOnStr, Reason]),
|
||||||
throw({badconf, Reason})
|
throw({badconf, Reason})
|
||||||
end.
|
end.
|
||||||
|
@ -198,10 +198,10 @@ stop_listener(GwName, {Type, LisName, ListenOn, SocketOpts, Cfg}) ->
|
||||||
StopRet = stop_listener(GwName, Type, LisName, ListenOn, SocketOpts, Cfg),
|
StopRet = stop_listener(GwName, Type, LisName, ListenOn, SocketOpts, Cfg),
|
||||||
ListenOnStr = emqx_gateway_utils:format_listenon(ListenOn),
|
ListenOnStr = emqx_gateway_utils:format_listenon(ListenOn),
|
||||||
case StopRet of
|
case StopRet of
|
||||||
ok -> ?ULOG("Gateway ~s:~s:~s on ~s stopped.~n",
|
ok -> ?ULOG("Gateway ~ts:~ts:~ts on ~ts stopped.~n",
|
||||||
[GwName, Type, LisName, ListenOnStr]);
|
[GwName, Type, LisName, ListenOnStr]);
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
?ELOG("Failed to stop gateway ~s:~s:~s on ~s: ~0p~n",
|
?ELOG("Failed to stop gateway ~ts:~ts:~ts on ~ts: ~0p~n",
|
||||||
[GwName, Type, LisName, ListenOnStr, Reason])
|
[GwName, Type, LisName, ListenOnStr, Reason])
|
||||||
end,
|
end,
|
||||||
StopRet.
|
StopRet.
|
||||||
|
|
|
@ -249,7 +249,7 @@ do_connect(Req, Result, Channel, Iter) ->
|
||||||
iter(Iter, maps:merge(Result, NewResult), NChannel)
|
iter(Iter, maps:merge(Result, NewResult), NChannel)
|
||||||
end;
|
end;
|
||||||
{error, ReasonCode, NChannel} ->
|
{error, ReasonCode, NChannel} ->
|
||||||
ErrMsg = io_lib:format("Login Failed: ~s", [ReasonCode]),
|
ErrMsg = io_lib:format("Login Failed: ~ts", [ReasonCode]),
|
||||||
Payload = erlang:list_to_binary(lists:flatten(ErrMsg)),
|
Payload = erlang:list_to_binary(lists:flatten(ErrMsg)),
|
||||||
iter(Iter,
|
iter(Iter,
|
||||||
reply({error, bad_request}, Payload, Req, Result),
|
reply({error, bad_request}, Payload, Req, Result),
|
||||||
|
@ -320,7 +320,7 @@ auth_connect(_Input, Channel = #channel{ctx = Ctx,
|
||||||
{ok, Channel#channel{clientinfo = NClientInfo,
|
{ok, Channel#channel{clientinfo = NClientInfo,
|
||||||
with_context = with_context(Ctx, ClientInfo)}};
|
with_context = with_context(Ctx, ClientInfo)}};
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
?LOG(warning, "Client ~s (Username: '~s') login failed for ~0p",
|
?LOG(warning, "Client ~ts (Username: '~ts') login failed for ~0p",
|
||||||
[ClientId, Username, Reason]),
|
[ClientId, Username, Reason]),
|
||||||
{error, Reason}
|
{error, Reason}
|
||||||
end.
|
end.
|
||||||
|
|
|
@ -68,7 +68,7 @@ on_gateway_update(NewGateway, OldGateway, GwState = #{ctx := Ctx}) ->
|
||||||
on_gateway_load(NewGateway, Ctx)
|
on_gateway_load(NewGateway, Ctx)
|
||||||
catch
|
catch
|
||||||
Class : Reason : Stk ->
|
Class : Reason : Stk ->
|
||||||
logger:error("Failed to update ~s; "
|
logger:error("Failed to update ~ts; "
|
||||||
"reason: {~0p, ~0p} stacktrace: ~0p",
|
"reason: {~0p, ~0p} stacktrace: ~0p",
|
||||||
[GwName, Class, Reason, Stk]),
|
[GwName, Class, Reason, Stk]),
|
||||||
{error, {Class, Reason}}
|
{error, {Class, Reason}}
|
||||||
|
@ -90,11 +90,11 @@ start_listener(GwName, Ctx, {Type, LisName, ListenOn, SocketOpts, Cfg}) ->
|
||||||
ListenOnStr = emqx_gateway_utils:format_listenon(ListenOn),
|
ListenOnStr = emqx_gateway_utils:format_listenon(ListenOn),
|
||||||
case start_listener(GwName, Ctx, Type, LisName, ListenOn, SocketOpts, Cfg) of
|
case start_listener(GwName, Ctx, Type, LisName, ListenOn, SocketOpts, Cfg) of
|
||||||
{ok, Pid} ->
|
{ok, Pid} ->
|
||||||
?ULOG("Gateway ~s:~s:~s on ~s started.~n",
|
?ULOG("Gateway ~ts:~ts:~ts on ~ts started.~n",
|
||||||
[GwName, Type, LisName, ListenOnStr]),
|
[GwName, Type, LisName, ListenOnStr]),
|
||||||
Pid;
|
Pid;
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
?ELOG("Failed to start gateway ~s:~s:~s on ~s: ~0p~n",
|
?ELOG("Failed to start gateway ~ts:~ts:~ts on ~ts: ~0p~n",
|
||||||
[GwName, Type, LisName, ListenOnStr, Reason]),
|
[GwName, Type, LisName, ListenOnStr, Reason]),
|
||||||
throw({badconf, Reason})
|
throw({badconf, Reason})
|
||||||
end.
|
end.
|
||||||
|
@ -130,10 +130,10 @@ stop_listener(GwName, {Type, LisName, ListenOn, SocketOpts, Cfg}) ->
|
||||||
StopRet = stop_listener(GwName, Type, LisName, ListenOn, SocketOpts, Cfg),
|
StopRet = stop_listener(GwName, Type, LisName, ListenOn, SocketOpts, Cfg),
|
||||||
ListenOnStr = emqx_gateway_utils:format_listenon(ListenOn),
|
ListenOnStr = emqx_gateway_utils:format_listenon(ListenOn),
|
||||||
case StopRet of
|
case StopRet of
|
||||||
ok -> ?ULOG("Gateway ~s:~s:~s on ~s stopped.~n",
|
ok -> ?ULOG("Gateway ~ts:~ts:~ts on ~ts stopped.~n",
|
||||||
[GwName, Type, LisName, ListenOnStr]);
|
[GwName, Type, LisName, ListenOnStr]);
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
?ELOG("Failed to stop gateway ~s:~s:~s on ~s: ~0p~n",
|
?ELOG("Failed to stop gateway ~ts:~ts:~ts on ~ts: ~0p~n",
|
||||||
[GwName, Type, LisName, ListenOnStr, Reason])
|
[GwName, Type, LisName, ListenOnStr, Reason])
|
||||||
end,
|
end,
|
||||||
StopRet.
|
StopRet.
|
||||||
|
|
|
@ -287,7 +287,7 @@ auth_connect(_Packet, Channel = #channel{ctx = Ctx,
|
||||||
{ok, NClientInfo} ->
|
{ok, NClientInfo} ->
|
||||||
{ok, Channel#channel{clientinfo = NClientInfo}};
|
{ok, Channel#channel{clientinfo = NClientInfo}};
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
?LOG(warning, "Client ~s (Username: '~s') login failed for ~0p",
|
?LOG(warning, "Client ~ts (Username: '~ts') login failed for ~0p",
|
||||||
[ClientId, Username, Reason]),
|
[ClientId, Username, Reason]),
|
||||||
%% FIXME: ReasonCode?
|
%% FIXME: ReasonCode?
|
||||||
{error, Reason}
|
{error, Reason}
|
||||||
|
@ -860,7 +860,7 @@ run_client_subs_hook({TopicId, TopicName, QoS},
|
||||||
case run_hooks(Ctx, 'client.subscribe',
|
case run_hooks(Ctx, 'client.subscribe',
|
||||||
[ClientInfo, #{}], TopicFilters) of
|
[ClientInfo, #{}], TopicFilters) of
|
||||||
[] ->
|
[] ->
|
||||||
?LOG(warning, "Skip to subscribe ~s, "
|
?LOG(warning, "Skip to subscribe ~ts, "
|
||||||
"due to 'client.subscribe' denied!", [TopicName]),
|
"due to 'client.subscribe' denied!", [TopicName]),
|
||||||
{error, ?SN_EXCEED_LIMITATION};
|
{error, ?SN_EXCEED_LIMITATION};
|
||||||
[{NTopicName, NSubOpts}|_] ->
|
[{NTopicName, NSubOpts}|_] ->
|
||||||
|
@ -879,7 +879,7 @@ do_subscribe({TopicId, TopicName, SubOpts},
|
||||||
{ok, {TopicId, NTopicName, NSubOpts},
|
{ok, {TopicId, NTopicName, NSubOpts},
|
||||||
Channel#channel{session = NSession}};
|
Channel#channel{session = NSession}};
|
||||||
{error, ?RC_QUOTA_EXCEEDED} ->
|
{error, ?RC_QUOTA_EXCEEDED} ->
|
||||||
?LOG(warning, "Cannot subscribe ~s due to ~s.",
|
?LOG(warning, "Cannot subscribe ~ts due to ~ts.",
|
||||||
[TopicName, emqx_reason_codes:text(?RC_QUOTA_EXCEEDED)]),
|
[TopicName, emqx_reason_codes:text(?RC_QUOTA_EXCEEDED)]),
|
||||||
{error, ?SN_EXCEED_LIMITATION}
|
{error, ?SN_EXCEED_LIMITATION}
|
||||||
end.
|
end.
|
||||||
|
|
|
@ -292,10 +292,10 @@ message_type(Type) ->
|
||||||
io_lib:format("Unknown Type ~p", [Type]).
|
io_lib:format("Unknown Type ~p", [Type]).
|
||||||
|
|
||||||
format(?SN_PUBLISH_MSG(Flags, TopicId, MsgId, Data)) ->
|
format(?SN_PUBLISH_MSG(Flags, TopicId, MsgId, Data)) ->
|
||||||
io_lib:format("mqtt_sn_message SN_PUBLISH, ~s, TopicId=~w, MsgId=~w, Payload=~w",
|
io_lib:format("mqtt_sn_message SN_PUBLISH, ~ts, TopicId=~w, MsgId=~w, Payload=~w",
|
||||||
[format_flag(Flags), TopicId, MsgId, Data]);
|
[format_flag(Flags), TopicId, MsgId, Data]);
|
||||||
format(?SN_PUBACK_MSG(Flags, MsgId, ReturnCode)) ->
|
format(?SN_PUBACK_MSG(Flags, MsgId, ReturnCode)) ->
|
||||||
io_lib:format("mqtt_sn_message SN_PUBACK, ~s, MsgId=~w, ReturnCode=~w",
|
io_lib:format("mqtt_sn_message SN_PUBACK, ~ts, MsgId=~w, ReturnCode=~w",
|
||||||
[format_flag(Flags), MsgId, ReturnCode]);
|
[format_flag(Flags), MsgId, ReturnCode]);
|
||||||
format(?SN_PUBREC_MSG(?SN_PUBCOMP, MsgId)) ->
|
format(?SN_PUBREC_MSG(?SN_PUBCOMP, MsgId)) ->
|
||||||
io_lib:format("mqtt_sn_message SN_PUBCOMP, MsgId=~w", [MsgId]);
|
io_lib:format("mqtt_sn_message SN_PUBCOMP, MsgId=~w", [MsgId]);
|
||||||
|
@ -304,13 +304,13 @@ format(?SN_PUBREC_MSG(?SN_PUBREC, MsgId)) ->
|
||||||
format(?SN_PUBREC_MSG(?SN_PUBREL, MsgId)) ->
|
format(?SN_PUBREC_MSG(?SN_PUBREL, MsgId)) ->
|
||||||
io_lib:format("mqtt_sn_message SN_PUBREL, MsgId=~w", [MsgId]);
|
io_lib:format("mqtt_sn_message SN_PUBREL, MsgId=~w", [MsgId]);
|
||||||
format(?SN_SUBSCRIBE_MSG(Flags, Msgid, Topic)) ->
|
format(?SN_SUBSCRIBE_MSG(Flags, Msgid, Topic)) ->
|
||||||
io_lib:format("mqtt_sn_message SN_SUBSCRIBE, ~s, MsgId=~w, TopicId=~w",
|
io_lib:format("mqtt_sn_message SN_SUBSCRIBE, ~ts, MsgId=~w, TopicId=~w",
|
||||||
[format_flag(Flags), Msgid, Topic]);
|
[format_flag(Flags), Msgid, Topic]);
|
||||||
format(?SN_SUBACK_MSG(Flags, TopicId, MsgId, ReturnCode)) ->
|
format(?SN_SUBACK_MSG(Flags, TopicId, MsgId, ReturnCode)) ->
|
||||||
io_lib:format("mqtt_sn_message SN_SUBACK, ~s, MsgId=~w, TopicId=~w, ReturnCode=~w",
|
io_lib:format("mqtt_sn_message SN_SUBACK, ~ts, MsgId=~w, TopicId=~w, ReturnCode=~w",
|
||||||
[format_flag(Flags), MsgId, TopicId, ReturnCode]);
|
[format_flag(Flags), MsgId, TopicId, ReturnCode]);
|
||||||
format(?SN_UNSUBSCRIBE_MSG(Flags, Msgid, Topic)) ->
|
format(?SN_UNSUBSCRIBE_MSG(Flags, Msgid, Topic)) ->
|
||||||
io_lib:format("mqtt_sn_message SN_UNSUBSCRIBE, ~s, MsgId=~w, TopicId=~w",
|
io_lib:format("mqtt_sn_message SN_UNSUBSCRIBE, ~ts, MsgId=~w, TopicId=~w",
|
||||||
[format_flag(Flags), Msgid, Topic]);
|
[format_flag(Flags), Msgid, Topic]);
|
||||||
format(?SN_UNSUBACK_MSG(MsgId)) ->
|
format(?SN_UNSUBACK_MSG(MsgId)) ->
|
||||||
io_lib:format("mqtt_sn_message SN_UNSUBACK, MsgId=~w", [MsgId]);
|
io_lib:format("mqtt_sn_message SN_UNSUBACK, MsgId=~w", [MsgId]);
|
||||||
|
@ -321,7 +321,7 @@ format(?SN_REGACK_MSG(TopicId, MsgId, ReturnCode)) ->
|
||||||
io_lib:format("mqtt_sn_message SN_REGACK, TopicId=~w, MsgId=~w, ReturnCode=~w",
|
io_lib:format("mqtt_sn_message SN_REGACK, TopicId=~w, MsgId=~w, ReturnCode=~w",
|
||||||
[TopicId, MsgId, ReturnCode]);
|
[TopicId, MsgId, ReturnCode]);
|
||||||
format(#mqtt_sn_message{type = Type, variable = Var}) ->
|
format(#mqtt_sn_message{type = Type, variable = Var}) ->
|
||||||
io_lib:format("mqtt_sn_message type=~s, Var=~w", [emqx_sn_frame:message_type(Type), Var]).
|
io_lib:format("mqtt_sn_message type=~ts, Var=~w", [emqx_sn_frame:message_type(Type), Var]).
|
||||||
|
|
||||||
format_flag(#mqtt_sn_flags{dup = Dup, qos = QoS, retain = Retain, will = Will, clean_start = CleanStart, topic_id_type = TopicType}) ->
|
format_flag(#mqtt_sn_flags{dup = Dup, qos = QoS, retain = Retain, will = Will, clean_start = CleanStart, topic_id_type = TopicType}) ->
|
||||||
io_lib:format("mqtt_sn_flags{dup=~p, qos=~p, retain=~p, will=~p, clean_session=~p, topic_id_type=~p}",
|
io_lib:format("mqtt_sn_flags{dup=~p, qos=~p, retain=~p, will=~p, clean_session=~p, topic_id_type=~p}",
|
||||||
|
|
|
@ -86,7 +86,7 @@ on_gateway_update(Config, Gateway, GwState = #{ctx := Ctx}) ->
|
||||||
on_gateway_load(Gateway#{config => Config}, Ctx)
|
on_gateway_load(Gateway#{config => Config}, Ctx)
|
||||||
catch
|
catch
|
||||||
Class : Reason : Stk ->
|
Class : Reason : Stk ->
|
||||||
logger:error("Failed to update ~s; "
|
logger:error("Failed to update ~ts; "
|
||||||
"reason: {~0p, ~0p} stacktrace: ~0p",
|
"reason: {~0p, ~0p} stacktrace: ~0p",
|
||||||
[GwName, Class, Reason, Stk]),
|
[GwName, Class, Reason, Stk]),
|
||||||
{error, {Class, Reason}}
|
{error, {Class, Reason}}
|
||||||
|
@ -108,11 +108,11 @@ start_listener(GwName, Ctx, {Type, LisName, ListenOn, SocketOpts, Cfg}) ->
|
||||||
ListenOnStr = emqx_gateway_utils:format_listenon(ListenOn),
|
ListenOnStr = emqx_gateway_utils:format_listenon(ListenOn),
|
||||||
case start_listener(GwName, Ctx, Type, LisName, ListenOn, SocketOpts, Cfg) of
|
case start_listener(GwName, Ctx, Type, LisName, ListenOn, SocketOpts, Cfg) of
|
||||||
{ok, Pid} ->
|
{ok, Pid} ->
|
||||||
?ULOG("Gateway ~s:~s:~s on ~s started.~n",
|
?ULOG("Gateway ~ts:~ts:~ts on ~ts started.~n",
|
||||||
[GwName, Type, LisName, ListenOnStr]),
|
[GwName, Type, LisName, ListenOnStr]),
|
||||||
Pid;
|
Pid;
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
?ELOG("Failed to start gateway ~s:~s:~s on ~s: ~0p~n",
|
?ELOG("Failed to start gateway ~ts:~ts:~ts on ~ts: ~0p~n",
|
||||||
[GwName, Type, LisName, ListenOnStr, Reason]),
|
[GwName, Type, LisName, ListenOnStr, Reason]),
|
||||||
throw({badconf, Reason})
|
throw({badconf, Reason})
|
||||||
end.
|
end.
|
||||||
|
@ -142,10 +142,10 @@ stop_listener(GwName, {Type, LisName, ListenOn, SocketOpts, Cfg}) ->
|
||||||
StopRet = stop_listener(GwName, Type, LisName, ListenOn, SocketOpts, Cfg),
|
StopRet = stop_listener(GwName, Type, LisName, ListenOn, SocketOpts, Cfg),
|
||||||
ListenOnStr = emqx_gateway_utils:format_listenon(ListenOn),
|
ListenOnStr = emqx_gateway_utils:format_listenon(ListenOn),
|
||||||
case StopRet of
|
case StopRet of
|
||||||
ok -> ?ULOG("Gateway ~s:~s:~s on ~s stopped.~n",
|
ok -> ?ULOG("Gateway ~ts:~ts:~ts on ~ts stopped.~n",
|
||||||
[GwName, Type, LisName, ListenOnStr]);
|
[GwName, Type, LisName, ListenOnStr]);
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
?ELOG("Failed to stop gateway ~s:~s:~s on ~s: ~0p~n",
|
?ELOG("Failed to stop gateway ~ts:~ts:~ts on ~ts: ~0p~n",
|
||||||
[GwName, Type, LisName, ListenOnStr, Reason])
|
[GwName, Type, LisName, ListenOnStr, Reason])
|
||||||
end,
|
end,
|
||||||
StopRet.
|
StopRet.
|
||||||
|
|
|
@ -280,7 +280,7 @@ auth_connect(_Packet, Channel = #channel{ctx = Ctx,
|
||||||
{ok, NClientInfo} ->
|
{ok, NClientInfo} ->
|
||||||
{ok, Channel#channel{clientinfo = NClientInfo}};
|
{ok, Channel#channel{clientinfo = NClientInfo}};
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
?LOG(warning, "Client ~s (Username: '~s') login failed for ~0p",
|
?LOG(warning, "Client ~ts (Username: '~ts') login failed for ~0p",
|
||||||
[ClientId, Username, Reason]),
|
[ClientId, Username, Reason]),
|
||||||
{error, Reason}
|
{error, Reason}
|
||||||
end.
|
end.
|
||||||
|
@ -352,7 +352,7 @@ handle_in(Packet = ?PACKET(?CMD_CONNECT), Channel) ->
|
||||||
{ok, _NPacket, NChannel} ->
|
{ok, _NPacket, NChannel} ->
|
||||||
process_connect(ensure_connected(NChannel));
|
process_connect(ensure_connected(NChannel));
|
||||||
{error, ReasonCode, NChannel} ->
|
{error, ReasonCode, NChannel} ->
|
||||||
ErrMsg = io_lib:format("Login Failed: ~s", [ReasonCode]),
|
ErrMsg = io_lib:format("Login Failed: ~ts", [ReasonCode]),
|
||||||
handle_out(connerr, {[], undefined, ErrMsg}, NChannel)
|
handle_out(connerr, {[], undefined, ErrMsg}, NChannel)
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -403,7 +403,7 @@ handle_in(?PACKET(?CMD_SUBSCRIBE, Headers),
|
||||||
handle_out(receipt, receipt_id(Headers), NChannel1)
|
handle_out(receipt, receipt_id(Headers), NChannel1)
|
||||||
end;
|
end;
|
||||||
{error, ErrMsg, NChannel} ->
|
{error, ErrMsg, NChannel} ->
|
||||||
?LOG(error, "Failed to subscribe topic ~s, reason: ~s",
|
?LOG(error, "Failed to subscribe topic ~ts, reason: ~ts",
|
||||||
[Topic, ErrMsg]),
|
[Topic, ErrMsg]),
|
||||||
handle_out(error, {receipt_id(Headers), ErrMsg}, NChannel)
|
handle_out(error, {receipt_id(Headers), ErrMsg}, NChannel)
|
||||||
end;
|
end;
|
||||||
|
@ -485,7 +485,7 @@ handle_in(?PACKET(?CMD_COMMIT, Headers), Channel) ->
|
||||||
maybe_outgoing_receipt(receipt_id(Headers), Outgoings, Chann1);
|
maybe_outgoing_receipt(receipt_id(Headers), Outgoings, Chann1);
|
||||||
{error, Reason, Chann1} ->
|
{error, Reason, Chann1} ->
|
||||||
%% FIXME: atomic for transaction ??
|
%% FIXME: atomic for transaction ??
|
||||||
ErrMsg = io_lib:format("Execute transaction ~s falied: ~0p",
|
ErrMsg = io_lib:format("Execute transaction ~ts falied: ~0p",
|
||||||
[TxId, Reason]
|
[TxId, Reason]
|
||||||
),
|
),
|
||||||
handle_out(error, {receipt_id(Headers), ErrMsg}, Chann1)
|
handle_out(error, {receipt_id(Headers), ErrMsg}, Chann1)
|
||||||
|
@ -653,7 +653,7 @@ handle_call({subscribe, Topic, SubOpts}, _From,
|
||||||
NChannel1 = NChannel#channel{subscriptions = NSubs},
|
NChannel1 = NChannel#channel{subscriptions = NSubs},
|
||||||
reply(ok, NChannel1);
|
reply(ok, NChannel1);
|
||||||
{error, ErrMsg, NChannel} ->
|
{error, ErrMsg, NChannel} ->
|
||||||
?LOG(error, "Failed to subscribe topic ~s, reason: ~s",
|
?LOG(error, "Failed to subscribe topic ~ts, reason: ~ts",
|
||||||
[Topic, ErrMsg]),
|
[Topic, ErrMsg]),
|
||||||
reply({error, ErrMsg}, NChannel)
|
reply({error, ErrMsg}, NChannel)
|
||||||
end
|
end
|
||||||
|
@ -829,7 +829,7 @@ handle_deliver(Delivers,
|
||||||
[Frame|Acc];
|
[Frame|Acc];
|
||||||
false ->
|
false ->
|
||||||
?LOG(error, "Dropped message ~0p due to not found "
|
?LOG(error, "Dropped message ~0p due to not found "
|
||||||
"subscription id for ~s",
|
"subscription id for ~ts",
|
||||||
[Message, emqx_message:topic(Message)]),
|
[Message, emqx_message:topic(Message)]),
|
||||||
metrics_inc('delivery.dropped', Channel),
|
metrics_inc('delivery.dropped', Channel),
|
||||||
metrics_inc('delivery.dropped.no_subid', Channel),
|
metrics_inc('delivery.dropped.no_subid', Channel),
|
||||||
|
|
|
@ -71,7 +71,7 @@ on_gateway_update(Config, Gateway, GwState = #{ctx := Ctx}) ->
|
||||||
on_gateway_load(Gateway#{config => Config}, Ctx)
|
on_gateway_load(Gateway#{config => Config}, Ctx)
|
||||||
catch
|
catch
|
||||||
Class : Reason : Stk ->
|
Class : Reason : Stk ->
|
||||||
logger:error("Failed to update ~s; "
|
logger:error("Failed to update ~ts; "
|
||||||
"reason: {~0p, ~0p} stacktrace: ~0p",
|
"reason: {~0p, ~0p} stacktrace: ~0p",
|
||||||
[GwName, Class, Reason, Stk]),
|
[GwName, Class, Reason, Stk]),
|
||||||
{error, {Class, Reason}}
|
{error, {Class, Reason}}
|
||||||
|
@ -93,11 +93,11 @@ start_listener(GwName, Ctx, {Type, LisName, ListenOn, SocketOpts, Cfg}) ->
|
||||||
ListenOnStr = emqx_gateway_utils:format_listenon(ListenOn),
|
ListenOnStr = emqx_gateway_utils:format_listenon(ListenOn),
|
||||||
case start_listener(GwName, Ctx, Type, LisName, ListenOn, SocketOpts, Cfg) of
|
case start_listener(GwName, Ctx, Type, LisName, ListenOn, SocketOpts, Cfg) of
|
||||||
{ok, Pid} ->
|
{ok, Pid} ->
|
||||||
?ULOG("Gateway ~s:~s:~s on ~s started.~n",
|
?ULOG("Gateway ~ts:~ts:~ts on ~ts started.~n",
|
||||||
[GwName, Type, LisName, ListenOnStr]),
|
[GwName, Type, LisName, ListenOnStr]),
|
||||||
Pid;
|
Pid;
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
?ELOG("Failed to start gateway ~s:~s:~s on ~s: ~0p~n",
|
?ELOG("Failed to start gateway ~ts:~ts:~ts on ~ts: ~0p~n",
|
||||||
[GwName, Type, LisName, ListenOnStr, Reason]),
|
[GwName, Type, LisName, ListenOnStr, Reason]),
|
||||||
throw({badconf, Reason})
|
throw({badconf, Reason})
|
||||||
end.
|
end.
|
||||||
|
@ -127,10 +127,10 @@ stop_listener(GwName, {Type, LisName, ListenOn, SocketOpts, Cfg}) ->
|
||||||
StopRet = stop_listener(GwName, Type, LisName, ListenOn, SocketOpts, Cfg),
|
StopRet = stop_listener(GwName, Type, LisName, ListenOn, SocketOpts, Cfg),
|
||||||
ListenOnStr = emqx_gateway_utils:format_listenon(ListenOn),
|
ListenOnStr = emqx_gateway_utils:format_listenon(ListenOn),
|
||||||
case StopRet of
|
case StopRet of
|
||||||
ok -> ?ULOG("Gateway ~s:~s:~s on ~s stopped.~n",
|
ok -> ?ULOG("Gateway ~ts:~ts:~ts on ~ts stopped.~n",
|
||||||
[GwName, Type, LisName, ListenOnStr]);
|
[GwName, Type, LisName, ListenOnStr]);
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
?ELOG("Failed to stop gateway ~s:~s:~s on ~s: ~0p~n",
|
?ELOG("Failed to stop gateway ~ts:~ts:~ts on ~ts: ~0p~n",
|
||||||
[GwName, Type, LisName, ListenOnStr, Reason])
|
[GwName, Type, LisName, ListenOnStr, Reason])
|
||||||
end,
|
end,
|
||||||
StopRet.
|
StopRet.
|
||||||
|
|
|
@ -74,7 +74,7 @@ t_connection(_Config) ->
|
||||||
|
|
||||||
%% heartbeat
|
%% heartbeat
|
||||||
HeartURI = ?MQTT_PREFIX ++ "/connection?clientid=client1&token=" ++ Token,
|
HeartURI = ?MQTT_PREFIX ++ "/connection?clientid=client1&token=" ++ Token,
|
||||||
?LOGT("send heartbeat request:~s~n", [HeartURI]),
|
?LOGT("send heartbeat request:~ts~n", [HeartURI]),
|
||||||
{ok, changed, _} = er_coap_client:request(put, HeartURI),
|
{ok, changed, _} = er_coap_client:request(put, HeartURI),
|
||||||
|
|
||||||
disconnection(Channel, Token),
|
disconnection(Channel, Token),
|
||||||
|
@ -140,7 +140,7 @@ t_subscribe(_Config) ->
|
||||||
URI = ?PS_PREFIX ++ TopicStr ++ "?clientid=client1&token=" ++ Token,
|
URI = ?PS_PREFIX ++ TopicStr ++ "?clientid=client1&token=" ++ Token,
|
||||||
Req = make_req(get, Payload, [{observe, 0}]),
|
Req = make_req(get, Payload, [{observe, 0}]),
|
||||||
{ok, content, _} = do_request(Channel, URI, Req),
|
{ok, content, _} = do_request(Channel, URI, Req),
|
||||||
?LOGT("observer topic:~s~n", [Topic]),
|
?LOGT("observer topic:~ts~n", [Topic]),
|
||||||
|
|
||||||
timer:sleep(100),
|
timer:sleep(100),
|
||||||
[SubPid] = emqx:subscribers(Topic),
|
[SubPid] = emqx:subscribers(Topic),
|
||||||
|
@ -172,7 +172,7 @@ t_un_subscribe(_Config) ->
|
||||||
|
|
||||||
Req = make_req(get, Payload, [{observe, 0}]),
|
Req = make_req(get, Payload, [{observe, 0}]),
|
||||||
{ok, content, _} = do_request(Channel, URI, Req),
|
{ok, content, _} = do_request(Channel, URI, Req),
|
||||||
?LOGT("observer topic:~s~n", [Topic]),
|
?LOGT("observer topic:~ts~n", [Topic]),
|
||||||
|
|
||||||
timer:sleep(100),
|
timer:sleep(100),
|
||||||
[SubPid] = emqx:subscribers(Topic),
|
[SubPid] = emqx:subscribers(Topic),
|
||||||
|
@ -180,7 +180,7 @@ t_un_subscribe(_Config) ->
|
||||||
|
|
||||||
UnReq = make_req(get, Payload, [{observe, 1}]),
|
UnReq = make_req(get, Payload, [{observe, 1}]),
|
||||||
{ok, nocontent, _} = do_request(Channel, URI, UnReq),
|
{ok, nocontent, _} = do_request(Channel, URI, UnReq),
|
||||||
?LOGT("un observer topic:~s~n", [Topic]),
|
?LOGT("un observer topic:~ts~n", [Topic]),
|
||||||
timer:sleep(100),
|
timer:sleep(100),
|
||||||
?assertEqual([], emqx:subscribers(Topic))
|
?assertEqual([], emqx:subscribers(Topic))
|
||||||
end,
|
end,
|
||||||
|
@ -197,7 +197,7 @@ t_observe_wildcard(_Config) ->
|
||||||
URI = ?PS_PREFIX ++ TopicStr ++ "?clientid=client1&token=" ++ Token,
|
URI = ?PS_PREFIX ++ TopicStr ++ "?clientid=client1&token=" ++ Token,
|
||||||
Req = make_req(get, Payload, [{observe, 0}]),
|
Req = make_req(get, Payload, [{observe, 0}]),
|
||||||
{ok, content, _} = do_request(Channel, URI, Req),
|
{ok, content, _} = do_request(Channel, URI, Req),
|
||||||
?LOGT("observer topic:~s~n", [Topic]),
|
?LOGT("observer topic:~ts~n", [Topic]),
|
||||||
|
|
||||||
timer:sleep(100),
|
timer:sleep(100),
|
||||||
[SubPid] = emqx:subscribers(Topic),
|
[SubPid] = emqx:subscribers(Topic),
|
||||||
|
@ -244,7 +244,7 @@ do_request(Channel, URI, #coap_message{options = Opts} = Req) ->
|
||||||
{_, _, Path, Query} = er_coap_client:resolve_uri(URI),
|
{_, _, Path, Query} = er_coap_client:resolve_uri(URI),
|
||||||
Opts2 = [{uri_path, Path}, {uri_query, Query} | Opts],
|
Opts2 = [{uri_path, Path}, {uri_query, Query} | Opts],
|
||||||
Req2 = Req#coap_message{options = Opts2},
|
Req2 = Req#coap_message{options = Opts2},
|
||||||
?LOGT("send request:~s~nReq:~p~n", [URI, Req2]),
|
?LOGT("send request:~ts~nReq:~p~n", [URI, Req2]),
|
||||||
|
|
||||||
{ok, _} = er_coap_channel:send(Channel, Req2),
|
{ok, _} = er_coap_channel:send(Channel, Req2),
|
||||||
with_response(Channel).
|
with_response(Channel).
|
||||||
|
|
|
@ -119,7 +119,7 @@ test_send_coap_request(UdpSock, Method, Content, Options, MsgId) ->
|
||||||
?LOGT("test udp socket send to ~p:~p, data=~p", [IpAddr, Port, RequestBinary]),
|
?LOGT("test udp socket send to ~p:~p, data=~p", [IpAddr, Port, RequestBinary]),
|
||||||
ok = gen_udp:send(UdpSock, IpAddr, Port, RequestBinary);
|
ok = gen_udp:send(UdpSock, IpAddr, Port, RequestBinary);
|
||||||
{SchemeDiff, ChIdDiff, _, _} ->
|
{SchemeDiff, ChIdDiff, _, _} ->
|
||||||
error(lists:flatten(io_lib:format("scheme ~s or ChId ~s does not match with socket", [SchemeDiff, ChIdDiff])))
|
error(lists:flatten(io_lib:format("scheme ~ts or ChId ~ts does not match with socket", [SchemeDiff, ChIdDiff])))
|
||||||
end.
|
end.
|
||||||
|
|
||||||
test_recv_coap_response(UdpSock) ->
|
test_recv_coap_response(UdpSock) ->
|
||||||
|
|
|
@ -190,7 +190,7 @@ case01_register(Config) ->
|
||||||
|
|
||||||
test_send_coap_request( UdpSock,
|
test_send_coap_request( UdpSock,
|
||||||
post,
|
post,
|
||||||
sprintf("coap://127.0.0.1:~b/rd?ep=~s<=345&lwm2m=1", [?PORT, Epn]),
|
sprintf("coap://127.0.0.1:~b/rd?ep=~ts<=345&lwm2m=1", [?PORT, Epn]),
|
||||||
#coap_content{content_format = <<"text/plain">>, payload = <<"</1>, </2>, </3>, </4>, </5>">>},
|
#coap_content{content_format = <<"text/plain">>, payload = <<"</1>, </2>, </3>, </4>, </5>">>},
|
||||||
[],
|
[],
|
||||||
MsgId),
|
MsgId),
|
||||||
|
@ -216,7 +216,7 @@ case01_register(Config) ->
|
||||||
MsgId3 = 52,
|
MsgId3 = 52,
|
||||||
test_send_coap_request( UdpSock,
|
test_send_coap_request( UdpSock,
|
||||||
delete,
|
delete,
|
||||||
sprintf("coap://127.0.0.1:~b~s", [?PORT, join_path(Location, <<>>)]),
|
sprintf("coap://127.0.0.1:~b~ts", [?PORT, join_path(Location, <<>>)]),
|
||||||
#coap_content{payload = <<>>},
|
#coap_content{payload = <<>>},
|
||||||
[],
|
[],
|
||||||
MsgId3),
|
MsgId3),
|
||||||
|
@ -235,7 +235,7 @@ case01_register_additional_opts(Config) ->
|
||||||
MsgId = 12,
|
MsgId = 12,
|
||||||
SubTopic = list_to_binary("lwm2m/"++Epn++"/dn/#"),
|
SubTopic = list_to_binary("lwm2m/"++Epn++"/dn/#"),
|
||||||
|
|
||||||
AddOpts = "ep=~s<=345&lwm2m=1&apn=psmA.eDRX0.ctnb&cust_opt=shawn&im=123&ct=1.4&mt=mdm9620&mv=1.2",
|
AddOpts = "ep=~ts<=345&lwm2m=1&apn=psmA.eDRX0.ctnb&cust_opt=shawn&im=123&ct=1.4&mt=mdm9620&mv=1.2",
|
||||||
test_send_coap_request( UdpSock,
|
test_send_coap_request( UdpSock,
|
||||||
post,
|
post,
|
||||||
sprintf("coap://127.0.0.1:~b/rd?" ++ AddOpts, [?PORT, Epn]),
|
sprintf("coap://127.0.0.1:~b/rd?" ++ AddOpts, [?PORT, Epn]),
|
||||||
|
@ -264,7 +264,7 @@ case01_register_additional_opts(Config) ->
|
||||||
MsgId3 = 52,
|
MsgId3 = 52,
|
||||||
test_send_coap_request( UdpSock,
|
test_send_coap_request( UdpSock,
|
||||||
delete,
|
delete,
|
||||||
sprintf("coap://127.0.0.1:~b~s", [?PORT, join_path(Location, <<>>)]),
|
sprintf("coap://127.0.0.1:~b~ts", [?PORT, join_path(Location, <<>>)]),
|
||||||
#coap_content{payload = <<>>},
|
#coap_content{payload = <<>>},
|
||||||
[],
|
[],
|
||||||
MsgId3),
|
MsgId3),
|
||||||
|
@ -283,7 +283,7 @@ case01_register_incorrect_opts(Config) ->
|
||||||
MsgId = 12,
|
MsgId = 12,
|
||||||
|
|
||||||
|
|
||||||
AddOpts = "ep=~s<=345&lwm2m=1&incorrect_opt",
|
AddOpts = "ep=~ts<=345&lwm2m=1&incorrect_opt",
|
||||||
test_send_coap_request( UdpSock,
|
test_send_coap_request( UdpSock,
|
||||||
post,
|
post,
|
||||||
sprintf("coap://127.0.0.1:~b/rd?" ++ AddOpts, [?PORT, Epn]),
|
sprintf("coap://127.0.0.1:~b/rd?" ++ AddOpts, [?PORT, Epn]),
|
||||||
|
@ -310,7 +310,7 @@ case01_register_report(Config) ->
|
||||||
|
|
||||||
test_send_coap_request( UdpSock,
|
test_send_coap_request( UdpSock,
|
||||||
post,
|
post,
|
||||||
sprintf("coap://127.0.0.1:~b/rd?ep=~s<=345&lwm2m=1", [?PORT, Epn]),
|
sprintf("coap://127.0.0.1:~b/rd?ep=~ts<=345&lwm2m=1", [?PORT, Epn]),
|
||||||
#coap_content{content_format = <<"text/plain">>, payload = <<"</1>, </2>, </3>, </4>, </5>">>},
|
#coap_content{content_format = <<"text/plain">>, payload = <<"</1>, </2>, </3>, </4>, </5>">>},
|
||||||
[],
|
[],
|
||||||
MsgId),
|
MsgId),
|
||||||
|
@ -345,7 +345,7 @@ case01_register_report(Config) ->
|
||||||
MsgId3 = 52,
|
MsgId3 = 52,
|
||||||
test_send_coap_request( UdpSock,
|
test_send_coap_request( UdpSock,
|
||||||
delete,
|
delete,
|
||||||
sprintf("coap://127.0.0.1:~b~s", [?PORT, join_path(Location, <<>>)]),
|
sprintf("coap://127.0.0.1:~b~ts", [?PORT, join_path(Location, <<>>)]),
|
||||||
#coap_content{payload = <<>>},
|
#coap_content{payload = <<>>},
|
||||||
[],
|
[],
|
||||||
MsgId3),
|
MsgId3),
|
||||||
|
@ -369,7 +369,7 @@ case02_update_deregister(Config) ->
|
||||||
|
|
||||||
test_send_coap_request( UdpSock,
|
test_send_coap_request( UdpSock,
|
||||||
post,
|
post,
|
||||||
sprintf("coap://127.0.0.1:~b/rd?ep=~s<=345&lwm2m=1", [?PORT, Epn]),
|
sprintf("coap://127.0.0.1:~b/rd?ep=~ts<=345&lwm2m=1", [?PORT, Epn]),
|
||||||
#coap_content{content_format = <<"text/plain">>, payload = <<"</1>, </2>, </3>, </4>, </5>">>},
|
#coap_content{content_format = <<"text/plain">>, payload = <<"</1>, </2>, </3>, </4>, </5>">>},
|
||||||
[],
|
[],
|
||||||
MsgId),
|
MsgId),
|
||||||
|
@ -398,7 +398,7 @@ case02_update_deregister(Config) ->
|
||||||
MsgId2 = 27,
|
MsgId2 = 27,
|
||||||
test_send_coap_request( UdpSock,
|
test_send_coap_request( UdpSock,
|
||||||
post,
|
post,
|
||||||
sprintf("coap://127.0.0.1:~b~s?lt=789", [?PORT, join_path(Location, <<>>)]),
|
sprintf("coap://127.0.0.1:~b~ts?lt=789", [?PORT, join_path(Location, <<>>)]),
|
||||||
#coap_content{content_format = <<"text/plain">>, payload = <<"</1>, </2>, </3>, </4>, </5>, </6>">>},
|
#coap_content{content_format = <<"text/plain">>, payload = <<"</1>, </2>, </3>, </4>, </5>, </6>">>},
|
||||||
[],
|
[],
|
||||||
MsgId2),
|
MsgId2),
|
||||||
|
@ -424,7 +424,7 @@ case02_update_deregister(Config) ->
|
||||||
MsgId3 = 52,
|
MsgId3 = 52,
|
||||||
test_send_coap_request( UdpSock,
|
test_send_coap_request( UdpSock,
|
||||||
delete,
|
delete,
|
||||||
sprintf("coap://127.0.0.1:~b~s", [?PORT, join_path(Location, <<>>)]),
|
sprintf("coap://127.0.0.1:~b~ts", [?PORT, join_path(Location, <<>>)]),
|
||||||
#coap_content{payload = <<>>},
|
#coap_content{payload = <<>>},
|
||||||
[],
|
[],
|
||||||
MsgId3),
|
MsgId3),
|
||||||
|
@ -445,7 +445,7 @@ case03_register_wrong_version(Config) ->
|
||||||
SubTopic = list_to_binary("lwm2m/"++Epn++"/dn/#"),
|
SubTopic = list_to_binary("lwm2m/"++Epn++"/dn/#"),
|
||||||
test_send_coap_request( UdpSock,
|
test_send_coap_request( UdpSock,
|
||||||
post,
|
post,
|
||||||
sprintf("coap://127.0.0.1:~b/rd?ep=~s<=345&lwm2m=8.3", [?PORT, Epn]),
|
sprintf("coap://127.0.0.1:~b/rd?ep=~ts<=345&lwm2m=8.3", [?PORT, Epn]),
|
||||||
#coap_content{content_format = <<"text/plain">>, payload = <<"</1>, </2>, </3>, </4>, </5>">>},
|
#coap_content{content_format = <<"text/plain">>, payload = <<"</1>, </2>, </3>, </4>, </5>">>},
|
||||||
[],
|
[],
|
||||||
MsgId),
|
MsgId),
|
||||||
|
@ -466,7 +466,7 @@ case04_register_and_lifetime_timeout(Config) ->
|
||||||
|
|
||||||
test_send_coap_request( UdpSock,
|
test_send_coap_request( UdpSock,
|
||||||
post,
|
post,
|
||||||
sprintf("coap://127.0.0.1:~b/rd?ep=~s<=2&lwm2m=1", [?PORT, Epn]),
|
sprintf("coap://127.0.0.1:~b/rd?ep=~ts<=2&lwm2m=1", [?PORT, Epn]),
|
||||||
#coap_content{content_format = <<"text/plain">>, payload = <<"</1>, </2>, </3>, </4>, </5>">>},
|
#coap_content{content_format = <<"text/plain">>, payload = <<"</1>, </2>, </3>, </4>, </5>">>},
|
||||||
[],
|
[],
|
||||||
MsgId),
|
MsgId),
|
||||||
|
@ -509,7 +509,7 @@ case05_register_wrong_epn(Config) ->
|
||||||
|
|
||||||
%% test_send_coap_request( UdpSock,
|
%% test_send_coap_request( UdpSock,
|
||||||
%% post,
|
%% post,
|
||||||
%% sprintf("coap://127.0.0.1:~b/rd?ep=~s&lwm2m=1", [?PORT, Epn]),
|
%% sprintf("coap://127.0.0.1:~b/rd?ep=~ts&lwm2m=1", [?PORT, Epn]),
|
||||||
%% #coap_content{content_format = <<"text/plain">>, payload = <<"</1>, </2>, </3>, </4>, </5>">>},
|
%% #coap_content{content_format = <<"text/plain">>, payload = <<"</1>, </2>, </3>, </4>, </5>">>},
|
||||||
%% [],
|
%% [],
|
||||||
%% MsgId),
|
%% MsgId),
|
||||||
|
@ -532,7 +532,7 @@ case07_register_alternate_path_01(Config) ->
|
||||||
|
|
||||||
test_send_coap_request( UdpSock,
|
test_send_coap_request( UdpSock,
|
||||||
post,
|
post,
|
||||||
sprintf("coap://127.0.0.1:~b/rd?ep=~s<=345&lwm2m=1", [?PORT, Epn]),
|
sprintf("coap://127.0.0.1:~b/rd?ep=~ts<=345&lwm2m=1", [?PORT, Epn]),
|
||||||
#coap_content{content_format = <<"text/plain">>,
|
#coap_content{content_format = <<"text/plain">>,
|
||||||
payload = <<"</>;rt=\"oma.lwm2m\";ct=11543,</lwm2m/1/0>,</lwm2m/2/0>,</lwm2m/3/0>">>},
|
payload = <<"</>;rt=\"oma.lwm2m\";ct=11543,</lwm2m/1/0>,</lwm2m/2/0>,</lwm2m/3/0>">>},
|
||||||
[],
|
[],
|
||||||
|
@ -554,7 +554,7 @@ case07_register_alternate_path_02(Config) ->
|
||||||
|
|
||||||
test_send_coap_request( UdpSock,
|
test_send_coap_request( UdpSock,
|
||||||
post,
|
post,
|
||||||
sprintf("coap://127.0.0.1:~b/rd?ep=~s<=345&lwm2m=1", [?PORT, Epn]),
|
sprintf("coap://127.0.0.1:~b/rd?ep=~ts<=345&lwm2m=1", [?PORT, Epn]),
|
||||||
#coap_content{content_format = <<"text/plain">>,
|
#coap_content{content_format = <<"text/plain">>,
|
||||||
payload = <<"</lwm2m>;rt=\"oma.lwm2m\";ct=11543,</lwm2m/1/0>,</lwm2m/2/0>,</lwm2m/3/0>">>},
|
payload = <<"</lwm2m>;rt=\"oma.lwm2m\";ct=11543,</lwm2m/1/0>,</lwm2m/2/0>,</lwm2m/3/0>">>},
|
||||||
[],
|
[],
|
||||||
|
@ -576,7 +576,7 @@ case08_reregister(Config) ->
|
||||||
|
|
||||||
test_send_coap_request( UdpSock,
|
test_send_coap_request( UdpSock,
|
||||||
post,
|
post,
|
||||||
sprintf("coap://127.0.0.1:~b/rd?ep=~s<=345&lwm2m=1", [?PORT, Epn]),
|
sprintf("coap://127.0.0.1:~b/rd?ep=~ts<=345&lwm2m=1", [?PORT, Epn]),
|
||||||
#coap_content{content_format = <<"text/plain">>,
|
#coap_content{content_format = <<"text/plain">>,
|
||||||
payload = <<"</lwm2m>;rt=\"oma.lwm2m\";ct=11543,</lwm2m/1/0>,</lwm2m/2/0>,</lwm2m/3/0>">>},
|
payload = <<"</lwm2m>;rt=\"oma.lwm2m\";ct=11543,</lwm2m/1/0>,</lwm2m/2/0>,</lwm2m/3/0>">>},
|
||||||
[],
|
[],
|
||||||
|
@ -602,7 +602,7 @@ case08_reregister(Config) ->
|
||||||
%% the same lwm2mc client registers to server again
|
%% the same lwm2mc client registers to server again
|
||||||
test_send_coap_request( UdpSock,
|
test_send_coap_request( UdpSock,
|
||||||
post,
|
post,
|
||||||
sprintf("coap://127.0.0.1:~b/rd?ep=~s<=345&lwm2m=1", [?PORT, Epn]),
|
sprintf("coap://127.0.0.1:~b/rd?ep=~ts<=345&lwm2m=1", [?PORT, Epn]),
|
||||||
#coap_content{content_format = <<"text/plain">>,
|
#coap_content{content_format = <<"text/plain">>,
|
||||||
payload = <<"</lwm2m>;rt=\"oma.lwm2m\";ct=11543,</lwm2m/1/0>,</lwm2m/2/0>,</lwm2m/3/0>">>},
|
payload = <<"</lwm2m>;rt=\"oma.lwm2m\";ct=11543,</lwm2m/1/0>,</lwm2m/2/0>,</lwm2m/3/0>">>},
|
||||||
[],
|
[],
|
||||||
|
@ -621,7 +621,7 @@ case10_read(Config) ->
|
||||||
%% step 1, device register ...
|
%% step 1, device register ...
|
||||||
test_send_coap_request( UdpSock,
|
test_send_coap_request( UdpSock,
|
||||||
post,
|
post,
|
||||||
sprintf("coap://127.0.0.1:~b/rd?ep=~s<=345&lwm2m=1", [?PORT, Epn]),
|
sprintf("coap://127.0.0.1:~b/rd?ep=~ts<=345&lwm2m=1", [?PORT, Epn]),
|
||||||
#coap_content{content_format = <<"text/plain">>,
|
#coap_content{content_format = <<"text/plain">>,
|
||||||
payload = <<"</lwm2m>;rt=\"oma.lwm2m\";ct=11543,</lwm2m/1/0>,</lwm2m/2/0>,</lwm2m/3/0>">>},
|
payload = <<"</lwm2m>;rt=\"oma.lwm2m\";ct=11543,</lwm2m/1/0>,</lwm2m/2/0>,</lwm2m/3/0>">>},
|
||||||
[],
|
[],
|
||||||
|
@ -1605,7 +1605,7 @@ case60_observe(Config) ->
|
||||||
|
|
||||||
%% test_send_coap_request( UdpSock,
|
%% test_send_coap_request( UdpSock,
|
||||||
%% post,
|
%% post,
|
||||||
%% sprintf("coap://127.0.0.1:~b/rd?ep=~s<=345&lwm2m=1"++RegOptionWangYi, [?PORT, Epn]),
|
%% sprintf("coap://127.0.0.1:~b/rd?ep=~ts<=345&lwm2m=1"++RegOptionWangYi, [?PORT, Epn]),
|
||||||
%% #coap_content{content_format = <<"text/plain">>, payload = <<"</1>, </2>, </3>, </4>, </5>">>},
|
%% #coap_content{content_format = <<"text/plain">>, payload = <<"</1>, </2>, </3>, </4>, </5>">>},
|
||||||
%% [],
|
%% [],
|
||||||
%% MsgId1),
|
%% MsgId1),
|
||||||
|
@ -1671,7 +1671,7 @@ case60_observe(Config) ->
|
||||||
|
|
||||||
%% test_send_coap_request( UdpSock,
|
%% test_send_coap_request( UdpSock,
|
||||||
%% post,
|
%% post,
|
||||||
%% sprintf("coap://127.0.0.1:~b/rd?ep=~s<=345&lwm2m=1"++RegOptionWangYi, [?PORT, Epn]),
|
%% sprintf("coap://127.0.0.1:~b/rd?ep=~ts<=345&lwm2m=1"++RegOptionWangYi, [?PORT, Epn]),
|
||||||
%% #coap_content{content_format = <<"text/plain">>, payload = <<"</1>, </2>, </3>, </4>, </5>">>},
|
%% #coap_content{content_format = <<"text/plain">>, payload = <<"</1>, </2>, </3>, </4>, </5>">>},
|
||||||
%% [],
|
%% [],
|
||||||
%% MsgId1),
|
%% MsgId1),
|
||||||
|
@ -1717,10 +1717,10 @@ case60_observe(Config) ->
|
||||||
%% ?assertEqual(ReadResult, test_recv_mqtt_response(RespTopic)).
|
%% ?assertEqual(ReadResult, test_recv_mqtt_response(RespTopic)).
|
||||||
|
|
||||||
case90_psm_mode(Config) ->
|
case90_psm_mode(Config) ->
|
||||||
server_cache_mode(Config, "ep=~s<=345&lwm2m=1&apn=psmA.eDRX0.ctnb").
|
server_cache_mode(Config, "ep=~ts<=345&lwm2m=1&apn=psmA.eDRX0.ctnb").
|
||||||
|
|
||||||
case90_queue_mode(Config) ->
|
case90_queue_mode(Config) ->
|
||||||
server_cache_mode(Config, "ep=~s<=345&lwm2m=1&b=UQ").
|
server_cache_mode(Config, "ep=~ts<=345&lwm2m=1&b=UQ").
|
||||||
|
|
||||||
server_cache_mode(Config, RegOption) ->
|
server_cache_mode(Config, RegOption) ->
|
||||||
#{lwm2m := LwM2M} = Gateway = emqx:get_config([gateway]),
|
#{lwm2m := LwM2M} = Gateway = emqx:get_config([gateway]),
|
||||||
|
@ -1817,7 +1817,7 @@ device_update_1(UdpSock, Location) ->
|
||||||
MsgId2 = 27,
|
MsgId2 = 27,
|
||||||
test_send_coap_request( UdpSock,
|
test_send_coap_request( UdpSock,
|
||||||
post,
|
post,
|
||||||
sprintf("coap://127.0.0.1:~b~s?lt=789", [?PORT, join_path(Location, <<>>)]),
|
sprintf("coap://127.0.0.1:~b~ts?lt=789", [?PORT, join_path(Location, <<>>)]),
|
||||||
#coap_content{payload = <<>>},
|
#coap_content{payload = <<>>},
|
||||||
[],
|
[],
|
||||||
MsgId2),
|
MsgId2),
|
||||||
|
@ -1845,7 +1845,7 @@ test_send_coap_request(UdpSock, Method, Uri, Content, Options, MsgId) ->
|
||||||
?LOGT("test udp socket send to ~p:~p, data=~p", [IpAddr, Port, RequestBinary]),
|
?LOGT("test udp socket send to ~p:~p, data=~p", [IpAddr, Port, RequestBinary]),
|
||||||
ok = gen_udp:send(UdpSock, IpAddr, Port, RequestBinary);
|
ok = gen_udp:send(UdpSock, IpAddr, Port, RequestBinary);
|
||||||
{SchemeDiff, ChIdDiff, _, _} ->
|
{SchemeDiff, ChIdDiff, _, _} ->
|
||||||
error(lists:flatten(io_lib:format("scheme ~s or ChId ~s does not match with socket", [SchemeDiff, ChIdDiff])))
|
error(lists:flatten(io_lib:format("scheme ~ts or ChId ~ts does not match with socket", [SchemeDiff, ChIdDiff])))
|
||||||
end.
|
end.
|
||||||
|
|
||||||
test_recv_coap_response(UdpSock) ->
|
test_recv_coap_response(UdpSock) ->
|
||||||
|
@ -1916,7 +1916,7 @@ test_send_coap_notif(UdpSock, Host, Port, Content, ObSeq, Request) ->
|
||||||
std_register(UdpSock, Epn, ObjectList, MsgId1, RespTopic) ->
|
std_register(UdpSock, Epn, ObjectList, MsgId1, RespTopic) ->
|
||||||
test_send_coap_request( UdpSock,
|
test_send_coap_request( UdpSock,
|
||||||
post,
|
post,
|
||||||
sprintf("coap://127.0.0.1:~b/rd?ep=~s<=345&lwm2m=1", [?PORT, Epn]),
|
sprintf("coap://127.0.0.1:~b/rd?ep=~ts<=345&lwm2m=1", [?PORT, Epn]),
|
||||||
#coap_content{content_format = <<"text/plain">>, payload = ObjectList},
|
#coap_content{content_format = <<"text/plain">>, payload = ObjectList},
|
||||||
[],
|
[],
|
||||||
MsgId1),
|
MsgId1),
|
||||||
|
|
|
@ -108,7 +108,7 @@ t_lookup_cmd_read(Config) ->
|
||||||
%% step 1, device register ...
|
%% step 1, device register ...
|
||||||
test_send_coap_request( UdpSock,
|
test_send_coap_request( UdpSock,
|
||||||
post,
|
post,
|
||||||
sprintf("coap://127.0.0.1:~b/rd?ep=~s<=600&lwm2m=1", [?PORT, Epn]),
|
sprintf("coap://127.0.0.1:~b/rd?ep=~ts<=600&lwm2m=1", [?PORT, Epn]),
|
||||||
#coap_content{content_format = <<"text/plain">>,
|
#coap_content{content_format = <<"text/plain">>,
|
||||||
payload = <<"</lwm2m>;rt=\"oma.lwm2m\";ct=11543,</lwm2m/1/0>,</lwm2m/2/0>,</lwm2m/3/0>">>},
|
payload = <<"</lwm2m>;rt=\"oma.lwm2m\";ct=11543,</lwm2m/1/0>,</lwm2m/2/0>,</lwm2m/3/0>">>},
|
||||||
[],
|
[],
|
||||||
|
@ -192,9 +192,9 @@ t_lookup_cmd_discover(Config) ->
|
||||||
send_request(ClientId, Path, Action) ->
|
send_request(ClientId, Path, Action) ->
|
||||||
ApiPath = emqx_mgmt_api_test_util:api_path(["gateway/lwm2m", ClientId, "lookup_cmd"]),
|
ApiPath = emqx_mgmt_api_test_util:api_path(["gateway/lwm2m", ClientId, "lookup_cmd"]),
|
||||||
Auth = emqx_mgmt_api_test_util:auth_header_(),
|
Auth = emqx_mgmt_api_test_util:auth_header_(),
|
||||||
Query = io_lib:format("path=~s&action=~s", [Path, Action]),
|
Query = io_lib:format("path=~ts&action=~ts", [Path, Action]),
|
||||||
{ok, Response} = emqx_mgmt_api_test_util:request_api(get, ApiPath, Query, Auth),
|
{ok, Response} = emqx_mgmt_api_test_util:request_api(get, ApiPath, Query, Auth),
|
||||||
?LOGT("rest api response:~s~n", [Response]),
|
?LOGT("rest api response:~ts~n", [Response]),
|
||||||
Response.
|
Response.
|
||||||
|
|
||||||
no_received_request(ClientId, Path, Action) ->
|
no_received_request(ClientId, Path, Action) ->
|
||||||
|
|
|
@ -37,7 +37,7 @@ post_boot() ->
|
||||||
print_vsn() -> ok.
|
print_vsn() -> ok.
|
||||||
-else. % TEST
|
-else. % TEST
|
||||||
print_vsn() ->
|
print_vsn() ->
|
||||||
?ULOG("~s ~s is running now!~n", [emqx_app:get_description(), emqx_app:get_release()]).
|
?ULOG("~ts ~ts is running now!~n", [emqx_app:get_description(), emqx_app:get_release()]).
|
||||||
-endif. % TEST
|
-endif. % TEST
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@ running_status(get, _Params) ->
|
||||||
false -> not_running;
|
false -> not_running;
|
||||||
{value, _Val} -> running
|
{value, _Val} -> running
|
||||||
end,
|
end,
|
||||||
Status = io_lib:format("Node ~s is ~s~nemqx is ~s", [node(), InternalStatus, AppStatus]),
|
Status = io_lib:format("Node ~ts is ~ts~nemqx is ~ts", [node(), InternalStatus, AppStatus]),
|
||||||
Body = list_to_binary(Status),
|
Body = list_to_binary(Status),
|
||||||
{200, #{<<"content-type">> => <<"text/plain">>}, Body}.
|
{200, #{<<"content-type">> => <<"text/plain">>}, Body}.
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
|
|
||||||
-include("emqx_mgmt.hrl").
|
-include("emqx_mgmt.hrl").
|
||||||
|
|
||||||
-define(PRINT_CMD(Cmd, Descr), io:format("~-48s# ~s~n", [Cmd, Descr])).
|
-define(PRINT_CMD(Cmd, Descr), io:format("~-48s# ~ts~n", [Cmd, Descr])).
|
||||||
|
|
||||||
-export([load/0]).
|
-export([load/0]).
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ is_cmd(Fun) ->
|
||||||
|
|
||||||
status([]) ->
|
status([]) ->
|
||||||
{InternalStatus, _ProvidedStatus} = init:get_status(),
|
{InternalStatus, _ProvidedStatus} = init:get_status(),
|
||||||
emqx_ctl:print("Node ~p ~s is ~p~n", [node(), emqx_app:get_release(), InternalStatus]);
|
emqx_ctl:print("Node ~p ~ts is ~p~n", [node(), emqx_app:get_release(), InternalStatus]);
|
||||||
status(_) ->
|
status(_) ->
|
||||||
emqx_ctl:usage("status", "Show broker status").
|
emqx_ctl:usage("status", "Show broker status").
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ status(_) ->
|
||||||
|
|
||||||
broker([]) ->
|
broker([]) ->
|
||||||
Funs = [sysdescr, version, datetime],
|
Funs = [sysdescr, version, datetime],
|
||||||
[emqx_ctl:print("~-10s: ~s~n", [Fun, emqx_sys:Fun()]) || Fun <- Funs],
|
[emqx_ctl:print("~-10s: ~ts~n", [Fun, emqx_sys:Fun()]) || Fun <- Funs],
|
||||||
emqx_ctl:print("~-10s: ~p~n", [uptime, emqx_sys:uptime()]);
|
emqx_ctl:print("~-10s: ~p~n", [uptime, emqx_sys:uptime()]);
|
||||||
|
|
||||||
broker(["stats"]) ->
|
broker(["stats"]) ->
|
||||||
|
@ -227,9 +227,9 @@ plugins(["list"]) ->
|
||||||
plugins(["load", Name]) ->
|
plugins(["load", Name]) ->
|
||||||
case emqx_plugins:load(list_to_atom(Name)) of
|
case emqx_plugins:load(list_to_atom(Name)) of
|
||||||
ok ->
|
ok ->
|
||||||
emqx_ctl:print("Plugin ~s loaded successfully.~n", [Name]);
|
emqx_ctl:print("Plugin ~ts loaded successfully.~n", [Name]);
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
emqx_ctl:print("Load plugin ~s error: ~p.~n", [Name, Reason])
|
emqx_ctl:print("Load plugin ~ts error: ~p.~n", [Name, Reason])
|
||||||
end;
|
end;
|
||||||
|
|
||||||
plugins(["unload", "emqx_management"])->
|
plugins(["unload", "emqx_management"])->
|
||||||
|
@ -238,9 +238,9 @@ plugins(["unload", "emqx_management"])->
|
||||||
plugins(["unload", Name]) ->
|
plugins(["unload", Name]) ->
|
||||||
case emqx_plugins:unload(list_to_atom(Name)) of
|
case emqx_plugins:unload(list_to_atom(Name)) of
|
||||||
ok ->
|
ok ->
|
||||||
emqx_ctl:print("Plugin ~s unloaded successfully.~n", [Name]);
|
emqx_ctl:print("Plugin ~ts unloaded successfully.~n", [Name]);
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
emqx_ctl:print("Unload plugin ~s error: ~p.~n", [Name, Reason])
|
emqx_ctl:print("Unload plugin ~ts error: ~p.~n", [Name, Reason])
|
||||||
end;
|
end;
|
||||||
|
|
||||||
plugins(["reload", Name]) ->
|
plugins(["reload", Name]) ->
|
||||||
|
@ -248,13 +248,13 @@ plugins(["reload", Name]) ->
|
||||||
PluginName ->
|
PluginName ->
|
||||||
case emqx_mgmt:reload_plugin(node(), PluginName) of
|
case emqx_mgmt:reload_plugin(node(), PluginName) of
|
||||||
ok ->
|
ok ->
|
||||||
emqx_ctl:print("Plugin ~s reloaded successfully.~n", [Name]);
|
emqx_ctl:print("Plugin ~ts reloaded successfully.~n", [Name]);
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
emqx_ctl:print("Reload plugin ~s error: ~p.~n", [Name, Reason])
|
emqx_ctl:print("Reload plugin ~ts error: ~p.~n", [Name, Reason])
|
||||||
end
|
end
|
||||||
catch
|
catch
|
||||||
error:badarg ->
|
error:badarg ->
|
||||||
emqx_ctl:print("Reload plugin ~s error: The plugin doesn't exist.~n", [Name])
|
emqx_ctl:print("Reload plugin ~ts error: The plugin doesn't exist.~n", [Name])
|
||||||
end;
|
end;
|
||||||
|
|
||||||
plugins(_) ->
|
plugins(_) ->
|
||||||
|
@ -274,7 +274,7 @@ vm(["all"]) ->
|
||||||
[vm([Name]) || Name <- ["load", "memory", "process", "io", "ports"]];
|
[vm([Name]) || Name <- ["load", "memory", "process", "io", "ports"]];
|
||||||
|
|
||||||
vm(["load"]) ->
|
vm(["load"]) ->
|
||||||
[emqx_ctl:print("cpu/~-20s: ~s~n", [L, V]) || {L, V} <- emqx_vm:loads()];
|
[emqx_ctl:print("cpu/~-20s: ~ts~n", [L, V]) || {L, V} <- emqx_vm:loads()];
|
||||||
|
|
||||||
vm(["memory"]) ->
|
vm(["memory"]) ->
|
||||||
[emqx_ctl:print("memory/~-17s: ~w~n", [Cat, Val]) || {Cat, Val} <- erlang:memory()];
|
[emqx_ctl:print("memory/~-17s: ~w~n", [Cat, Val]) || {Cat, Val} <- erlang:memory()];
|
||||||
|
@ -311,42 +311,42 @@ mnesia(_) ->
|
||||||
|
|
||||||
log(["set-level", Level]) ->
|
log(["set-level", Level]) ->
|
||||||
case emqx_logger:set_log_level(list_to_atom(Level)) of
|
case emqx_logger:set_log_level(list_to_atom(Level)) of
|
||||||
ok -> emqx_ctl:print("~s~n", [Level]);
|
ok -> emqx_ctl:print("~ts~n", [Level]);
|
||||||
Error -> emqx_ctl:print("[error] set overall log level failed: ~p~n", [Error])
|
Error -> emqx_ctl:print("[error] set overall log level failed: ~p~n", [Error])
|
||||||
end;
|
end;
|
||||||
|
|
||||||
log(["primary-level"]) ->
|
log(["primary-level"]) ->
|
||||||
Level = emqx_logger:get_primary_log_level(),
|
Level = emqx_logger:get_primary_log_level(),
|
||||||
emqx_ctl:print("~s~n", [Level]);
|
emqx_ctl:print("~ts~n", [Level]);
|
||||||
|
|
||||||
log(["primary-level", Level]) ->
|
log(["primary-level", Level]) ->
|
||||||
_ = emqx_logger:set_primary_log_level(list_to_atom(Level)),
|
_ = emqx_logger:set_primary_log_level(list_to_atom(Level)),
|
||||||
emqx_ctl:print("~s~n", [emqx_logger:get_primary_log_level()]);
|
emqx_ctl:print("~ts~n", [emqx_logger:get_primary_log_level()]);
|
||||||
|
|
||||||
log(["handlers", "list"]) ->
|
log(["handlers", "list"]) ->
|
||||||
_ = [emqx_ctl:print("LogHandler(id=~s, level=~s, destination=~s, status=~s)~n", [Id, Level, Dst, Status])
|
_ = [emqx_ctl:print("LogHandler(id=~ts, level=~ts, destination=~ts, status=~ts)~n", [Id, Level, Dst, Status])
|
||||||
|| #{id := Id, level := Level, dst := Dst, status := Status} <- emqx_logger:get_log_handlers()],
|
|| #{id := Id, level := Level, dst := Dst, status := Status} <- emqx_logger:get_log_handlers()],
|
||||||
ok;
|
ok;
|
||||||
|
|
||||||
log(["handlers", "start", HandlerId]) ->
|
log(["handlers", "start", HandlerId]) ->
|
||||||
case emqx_logger:start_log_handler(list_to_atom(HandlerId)) of
|
case emqx_logger:start_log_handler(list_to_atom(HandlerId)) of
|
||||||
ok -> emqx_ctl:print("log handler ~s started~n", [HandlerId]);
|
ok -> emqx_ctl:print("log handler ~ts started~n", [HandlerId]);
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
emqx_ctl:print("[error] failed to start log handler ~s: ~p~n", [HandlerId, Reason])
|
emqx_ctl:print("[error] failed to start log handler ~ts: ~p~n", [HandlerId, Reason])
|
||||||
end;
|
end;
|
||||||
|
|
||||||
log(["handlers", "stop", HandlerId]) ->
|
log(["handlers", "stop", HandlerId]) ->
|
||||||
case emqx_logger:stop_log_handler(list_to_atom(HandlerId)) of
|
case emqx_logger:stop_log_handler(list_to_atom(HandlerId)) of
|
||||||
ok -> emqx_ctl:print("log handler ~s stopped~n", [HandlerId]);
|
ok -> emqx_ctl:print("log handler ~ts stopped~n", [HandlerId]);
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
emqx_ctl:print("[error] failed to stop log handler ~s: ~p~n", [HandlerId, Reason])
|
emqx_ctl:print("[error] failed to stop log handler ~ts: ~p~n", [HandlerId, Reason])
|
||||||
end;
|
end;
|
||||||
|
|
||||||
log(["handlers", "set-level", HandlerId, Level]) ->
|
log(["handlers", "set-level", HandlerId, Level]) ->
|
||||||
case emqx_logger:set_log_handler_level(list_to_atom(HandlerId), list_to_atom(Level)) of
|
case emqx_logger:set_log_handler_level(list_to_atom(HandlerId), list_to_atom(Level)) of
|
||||||
ok ->
|
ok ->
|
||||||
#{level := NewLevel} = emqx_logger:get_log_handler(list_to_atom(HandlerId)),
|
#{level := NewLevel} = emqx_logger:get_log_handler(list_to_atom(HandlerId)),
|
||||||
emqx_ctl:print("~s~n", [NewLevel]);
|
emqx_ctl:print("~ts~n", [NewLevel]);
|
||||||
{error, Error} ->
|
{error, Error} ->
|
||||||
emqx_ctl:print("[error] ~p~n", [Error])
|
emqx_ctl:print("[error] ~p~n", [Error])
|
||||||
end;
|
end;
|
||||||
|
@ -365,7 +365,7 @@ log(_) ->
|
||||||
|
|
||||||
trace(["list"]) ->
|
trace(["list"]) ->
|
||||||
lists:foreach(fun({{Who, Name}, {Level, LogFile}}) ->
|
lists:foreach(fun({{Who, Name}, {Level, LogFile}}) ->
|
||||||
emqx_ctl:print("Trace(~s=~s, level=~s, destination=~p)~n", [Who, Name, Level, LogFile])
|
emqx_ctl:print("Trace(~ts=~ts, level=~ts, destination=~p)~n", [Who, Name, Level, LogFile])
|
||||||
end, emqx_tracer:lookup_traces());
|
end, emqx_tracer:lookup_traces());
|
||||||
|
|
||||||
trace(["stop", "client", ClientId]) ->
|
trace(["stop", "client", ClientId]) ->
|
||||||
|
@ -396,17 +396,17 @@ trace(_) ->
|
||||||
trace_on(Who, Name, Level, LogFile) ->
|
trace_on(Who, Name, Level, LogFile) ->
|
||||||
case emqx_tracer:start_trace({Who, iolist_to_binary(Name)}, Level, LogFile) of
|
case emqx_tracer:start_trace({Who, iolist_to_binary(Name)}, Level, LogFile) of
|
||||||
ok ->
|
ok ->
|
||||||
emqx_ctl:print("trace ~s ~s successfully~n", [Who, Name]);
|
emqx_ctl:print("trace ~ts ~ts successfully~n", [Who, Name]);
|
||||||
{error, Error} ->
|
{error, Error} ->
|
||||||
emqx_ctl:print("[error] trace ~s ~s: ~p~n", [Who, Name, Error])
|
emqx_ctl:print("[error] trace ~ts ~ts: ~p~n", [Who, Name, Error])
|
||||||
end.
|
end.
|
||||||
|
|
||||||
trace_off(Who, Name) ->
|
trace_off(Who, Name) ->
|
||||||
case emqx_tracer:stop_trace({Who, iolist_to_binary(Name)}) of
|
case emqx_tracer:stop_trace({Who, iolist_to_binary(Name)}) of
|
||||||
ok ->
|
ok ->
|
||||||
emqx_ctl:print("stop tracing ~s ~s successfully~n", [Who, Name]);
|
emqx_ctl:print("stop tracing ~ts ~ts successfully~n", [Who, Name]);
|
||||||
{error, Error} ->
|
{error, Error} ->
|
||||||
emqx_ctl:print("[error] stop tracing ~s ~s: ~p~n", [Who, Name, Error])
|
emqx_ctl:print("[error] stop tracing ~ts ~ts: ~p~n", [Who, Name, Error])
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
@ -432,32 +432,32 @@ listeners([]) ->
|
||||||
{proxy_protocol, ProxyProtocol},
|
{proxy_protocol, ProxyProtocol},
|
||||||
{running, Running}
|
{running, Running}
|
||||||
] ++ CurrentConns ++ MaxConn,
|
] ++ CurrentConns ++ MaxConn,
|
||||||
emqx_ctl:print("~s~n", [ID]),
|
emqx_ctl:print("~ts~n", [ID]),
|
||||||
lists:foreach(fun indent_print/1, Info)
|
lists:foreach(fun indent_print/1, Info)
|
||||||
end, emqx_listeners:list());
|
end, emqx_listeners:list());
|
||||||
|
|
||||||
listeners(["stop", ListenerId]) ->
|
listeners(["stop", ListenerId]) ->
|
||||||
case emqx_listeners:stop_listener(list_to_atom(ListenerId)) of
|
case emqx_listeners:stop_listener(list_to_atom(ListenerId)) of
|
||||||
ok ->
|
ok ->
|
||||||
emqx_ctl:print("Stop ~s listener successfully.~n", [ListenerId]);
|
emqx_ctl:print("Stop ~ts listener successfully.~n", [ListenerId]);
|
||||||
{error, Error} ->
|
{error, Error} ->
|
||||||
emqx_ctl:print("Failed to stop ~s listener: ~0p~n", [ListenerId, Error])
|
emqx_ctl:print("Failed to stop ~ts listener: ~0p~n", [ListenerId, Error])
|
||||||
end;
|
end;
|
||||||
|
|
||||||
listeners(["start", ListenerId]) ->
|
listeners(["start", ListenerId]) ->
|
||||||
case emqx_listeners:start_listener(list_to_atom(ListenerId)) of
|
case emqx_listeners:start_listener(list_to_atom(ListenerId)) of
|
||||||
ok ->
|
ok ->
|
||||||
emqx_ctl:print("Started ~s listener successfully.~n", [ListenerId]);
|
emqx_ctl:print("Started ~ts listener successfully.~n", [ListenerId]);
|
||||||
{error, Error} ->
|
{error, Error} ->
|
||||||
emqx_ctl:print("Failed to start ~s listener: ~0p~n", [ListenerId, Error])
|
emqx_ctl:print("Failed to start ~ts listener: ~0p~n", [ListenerId, Error])
|
||||||
end;
|
end;
|
||||||
|
|
||||||
listeners(["restart", ListenerId]) ->
|
listeners(["restart", ListenerId]) ->
|
||||||
case emqx_listeners:restart_listener(list_to_atom(ListenerId)) of
|
case emqx_listeners:restart_listener(list_to_atom(ListenerId)) of
|
||||||
ok ->
|
ok ->
|
||||||
emqx_ctl:print("Restarted ~s listener successfully.~n", [ListenerId]);
|
emqx_ctl:print("Restarted ~ts listener successfully.~n", [ListenerId]);
|
||||||
{error, Error} ->
|
{error, Error} ->
|
||||||
emqx_ctl:print("Failed to restart ~s listener: ~0p~n", [ListenerId, Error])
|
emqx_ctl:print("Failed to restart ~ts listener: ~0p~n", [ListenerId, Error])
|
||||||
end;
|
end;
|
||||||
|
|
||||||
listeners(_) ->
|
listeners(_) ->
|
||||||
|
@ -473,9 +473,9 @@ listeners(_) ->
|
||||||
authz(["cache-clean", "node", Node]) ->
|
authz(["cache-clean", "node", Node]) ->
|
||||||
case emqx_mgmt:clean_authz_cache_all(erlang:list_to_existing_atom(Node)) of
|
case emqx_mgmt:clean_authz_cache_all(erlang:list_to_existing_atom(Node)) of
|
||||||
ok ->
|
ok ->
|
||||||
emqx_ctl:print("Authorization cache drain started on node ~s.~n", [Node]);
|
emqx_ctl:print("Authorization cache drain started on node ~ts.~n", [Node]);
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
emqx_ctl:print("Authorization drain failed on node ~s: ~0p.~n", [Node, Reason])
|
emqx_ctl:print("Authorization drain failed on node ~ts: ~0p.~n", [Node, Reason])
|
||||||
end;
|
end;
|
||||||
|
|
||||||
authz(["cache-clean", "all"]) ->
|
authz(["cache-clean", "all"]) ->
|
||||||
|
@ -549,10 +549,10 @@ print({client, {ClientId, ChanPid}}) ->
|
||||||
false -> []
|
false -> []
|
||||||
end,
|
end,
|
||||||
Info1 = Info#{expiry_interval => maps:get(expiry_interval, Info) div 1000},
|
Info1 = Info#{expiry_interval => maps:get(expiry_interval, Info) div 1000},
|
||||||
emqx_ctl:print("Client(~s, username=~s, peername=~s, "
|
emqx_ctl:print("Client(~ts, username=~ts, peername=~ts, "
|
||||||
"clean_start=~s, keepalive=~w, session_expiry_interval=~w, "
|
"clean_start=~ts, keepalive=~w, session_expiry_interval=~w, "
|
||||||
"subscriptions=~w, inflight=~w, awaiting_rel=~w, delivered_msgs=~w, enqueued_msgs=~w, dropped_msgs=~w, "
|
"subscriptions=~w, inflight=~w, awaiting_rel=~w, delivered_msgs=~w, enqueued_msgs=~w, dropped_msgs=~w, "
|
||||||
"connected=~s, created_at=~w, connected_at=~w" ++
|
"connected=~ts, created_at=~w, connected_at=~w" ++
|
||||||
case maps:is_key(disconnected_at, Info1) of
|
case maps:is_key(disconnected_at, Info1) of
|
||||||
true -> ", disconnected_at=~w)~n";
|
true -> ", disconnected_at=~w)~n";
|
||||||
false -> ")~n"
|
false -> ")~n"
|
||||||
|
@ -560,23 +560,23 @@ print({client, {ClientId, ChanPid}}) ->
|
||||||
[format(K, maps:get(K, Info1)) || K <- InfoKeys]);
|
[format(K, maps:get(K, Info1)) || K <- InfoKeys]);
|
||||||
|
|
||||||
print({emqx_route, #route{topic = Topic, dest = {_, Node}}}) ->
|
print({emqx_route, #route{topic = Topic, dest = {_, Node}}}) ->
|
||||||
emqx_ctl:print("~s -> ~s~n", [Topic, Node]);
|
emqx_ctl:print("~ts -> ~ts~n", [Topic, Node]);
|
||||||
print({emqx_route, #route{topic = Topic, dest = Node}}) ->
|
print({emqx_route, #route{topic = Topic, dest = Node}}) ->
|
||||||
emqx_ctl:print("~s -> ~s~n", [Topic, Node]);
|
emqx_ctl:print("~ts -> ~ts~n", [Topic, Node]);
|
||||||
|
|
||||||
print(#plugin{name = Name, descr = Descr, active = Active}) ->
|
print(#plugin{name = Name, descr = Descr, active = Active}) ->
|
||||||
emqx_ctl:print("Plugin(~s, description=~s, active=~s)~n",
|
emqx_ctl:print("Plugin(~ts, description=~ts, active=~ts)~n",
|
||||||
[Name, Descr, Active]);
|
[Name, Descr, Active]);
|
||||||
|
|
||||||
print({emqx_suboption, {{Pid, Topic}, Options}}) when is_pid(Pid) ->
|
print({emqx_suboption, {{Pid, Topic}, Options}}) when is_pid(Pid) ->
|
||||||
emqx_ctl:print("~s -> ~s~n", [maps:get(subid, Options), Topic]).
|
emqx_ctl:print("~ts -> ~ts~n", [maps:get(subid, Options), Topic]).
|
||||||
|
|
||||||
format(_, undefined) ->
|
format(_, undefined) ->
|
||||||
undefined;
|
undefined;
|
||||||
|
|
||||||
format(peername, {IPAddr, Port}) ->
|
format(peername, {IPAddr, Port}) ->
|
||||||
IPStr = emqx_mgmt_util:ntoa(IPAddr),
|
IPStr = emqx_mgmt_util:ntoa(IPAddr),
|
||||||
io_lib:format("~s:~p", [IPStr, Port]);
|
io_lib:format("~ts:~p", [IPStr, Port]);
|
||||||
|
|
||||||
format(_, Val) ->
|
format(_, Val) ->
|
||||||
Val.
|
Val.
|
||||||
|
@ -584,13 +584,13 @@ format(_, Val) ->
|
||||||
bin(S) -> iolist_to_binary(S).
|
bin(S) -> iolist_to_binary(S).
|
||||||
|
|
||||||
indent_print({Key, {string, Val}}) ->
|
indent_print({Key, {string, Val}}) ->
|
||||||
emqx_ctl:print(" ~-16s: ~s~n", [Key, Val]);
|
emqx_ctl:print(" ~-16s: ~ts~n", [Key, Val]);
|
||||||
indent_print({Key, Val}) ->
|
indent_print({Key, Val}) ->
|
||||||
emqx_ctl:print(" ~-16s: ~w~n", [Key, Val]).
|
emqx_ctl:print(" ~-16s: ~w~n", [Key, Val]).
|
||||||
|
|
||||||
format_listen_on(Port) when is_integer(Port) ->
|
format_listen_on(Port) when is_integer(Port) ->
|
||||||
io_lib:format("0.0.0.0:~w", [Port]);
|
io_lib:format("0.0.0.0:~w", [Port]);
|
||||||
format_listen_on({Addr, Port}) when is_list(Addr) ->
|
format_listen_on({Addr, Port}) when is_list(Addr) ->
|
||||||
io_lib:format("~s:~w", [Addr, Port]);
|
io_lib:format("~ts:~w", [Addr, Port]);
|
||||||
format_listen_on({Addr, Port}) when is_tuple(Addr) ->
|
format_listen_on({Addr, Port}) when is_tuple(Addr) ->
|
||||||
io_lib:format("~s:~w", [inet:ntoa(Addr), Port]).
|
io_lib:format("~ts:~w", [inet:ntoa(Addr), Port]).
|
||||||
|
|
|
@ -80,7 +80,7 @@ kmg(Byte) when Byte > ?KB ->
|
||||||
kmg(Byte) ->
|
kmg(Byte) ->
|
||||||
Byte.
|
Byte.
|
||||||
kmg(F, S) ->
|
kmg(F, S) ->
|
||||||
iolist_to_binary(io_lib:format("~.2f~s", [F, S])).
|
iolist_to_binary(io_lib:format("~.2f~ts", [F, S])).
|
||||||
|
|
||||||
ntoa({0,0,0,0,0,16#ffff,AB,CD}) ->
|
ntoa({0,0,0,0,0,16#ffff,AB,CD}) ->
|
||||||
inet_parse:ntoa({AB bsr 8, AB rem 256, CD bsr 8, CD rem 256});
|
inet_parse:ntoa({AB bsr 8, AB rem 256, CD bsr 8, CD rem 256});
|
||||||
|
|
|
@ -136,7 +136,7 @@ data(get, _Request) ->
|
||||||
% TelemetryData = get_telemetry_data(),
|
% TelemetryData = get_telemetry_data(),
|
||||||
% case emqx_json:safe_encode(TelemetryData, [pretty]) of
|
% case emqx_json:safe_encode(TelemetryData, [pretty]) of
|
||||||
% {ok, Bin} ->
|
% {ok, Bin} ->
|
||||||
% emqx_ctl:print("~s~n", [Bin]);
|
% emqx_ctl:print("~ts~n", [Bin]);
|
||||||
% {error, _Reason} ->
|
% {error, _Reason} ->
|
||||||
% emqx_ctl:print("Failed to get telemetry data")
|
% emqx_ctl:print("Failed to get telemetry data")
|
||||||
% end;
|
% end;
|
||||||
|
|
|
@ -101,7 +101,7 @@ do_save_file(FileName, Content, Dir) ->
|
||||||
ok ->
|
ok ->
|
||||||
ensure_str(FullFilename);
|
ensure_str(FullFilename);
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
logger:error("failed_to_save_ssl_file ~s: ~0p", [FullFilename, Reason]),
|
logger:error("failed_to_save_ssl_file ~ts: ~0p", [FullFilename, Reason]),
|
||||||
error({"failed_to_save_ssl_file", FullFilename, Reason})
|
error({"failed_to_save_ssl_file", FullFilename, Reason})
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
|
@ -172,7 +172,7 @@ do_create(InstId, ResourceType, Config) ->
|
||||||
_ = do_health_check(InstId),
|
_ = do_health_check(InstId),
|
||||||
{ok, force_lookup(InstId)};
|
{ok, force_lookup(InstId)};
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
logger:error("start ~s resource ~s failed: ~p", [ResourceType, InstId, Reason]),
|
logger:error("start ~ts resource ~ts failed: ~p", [ResourceType, InstId, Reason]),
|
||||||
{error, Reason}
|
{error, Reason}
|
||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
|
|
|
@ -56,7 +56,7 @@ len(string) -> fun string:length/1;
|
||||||
len(_Type) -> fun(Val) -> Val end.
|
len(_Type) -> fun(Val) -> Val end.
|
||||||
|
|
||||||
err_limit({Type, {Op, Expected}, {got, Got}}) ->
|
err_limit({Type, {Op, Expected}, {got, Got}}) ->
|
||||||
io_lib:format("Expect the ~s value ~s ~p but got: ~p", [Type, Op, Expected, Got]).
|
io_lib:format("Expect the ~ts value ~ts ~p but got: ~p", [Type, Op, Expected, Got]).
|
||||||
|
|
||||||
return(true, _) -> ok;
|
return(true, _) -> ok;
|
||||||
return(false, Error) ->
|
return(false, Error) ->
|
||||||
|
|
|
@ -288,7 +288,7 @@ store_retained(Context, #message{topic = Topic, payload = Payload} = Msg) ->
|
||||||
Mod = get_backend_module(),
|
Mod = get_backend_module(),
|
||||||
Mod:store_retained(Context, Msg);
|
Mod:store_retained(Context, Msg);
|
||||||
_ ->
|
_ ->
|
||||||
?ERROR("Cannot retain message(topic=~s, payload_size=~p) for payload is too big!",
|
?ERROR("Cannot retain message(topic=~ts, payload_size=~p) for payload is too big!",
|
||||||
[Topic, iolist_size(Payload)])
|
[Topic, iolist_size(Payload)])
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
@ -441,17 +441,17 @@ get_backend_module() ->
|
||||||
true ->
|
true ->
|
||||||
Backend
|
Backend
|
||||||
end,
|
end,
|
||||||
erlang:list_to_existing_atom(io_lib:format("~s_~s", [?APP, ModName])).
|
erlang:list_to_existing_atom(io_lib:format("~ts_~ts", [?APP, ModName])).
|
||||||
|
|
||||||
create_resource(Context, #{type := built_in_database} = Cfg) ->
|
create_resource(Context, #{type := built_in_database} = Cfg) ->
|
||||||
emqx_retainer_mnesia:create_resource(Cfg),
|
emqx_retainer_mnesia:create_resource(Cfg),
|
||||||
Context;
|
Context;
|
||||||
|
|
||||||
create_resource(Context, #{type := DB} = Config) ->
|
create_resource(Context, #{type := DB} = Config) ->
|
||||||
ResourceID = erlang:iolist_to_binary([io_lib:format("~s_~s", [?APP, DB])]),
|
ResourceID = erlang:iolist_to_binary([io_lib:format("~ts_~ts", [?APP, DB])]),
|
||||||
case emqx_resource:create(
|
case emqx_resource:create(
|
||||||
ResourceID,
|
ResourceID,
|
||||||
list_to_existing_atom(io_lib:format("~s_~s", [emqx_connector, DB])),
|
list_to_existing_atom(io_lib:format("~ts_~ts", [emqx_connector, DB])),
|
||||||
Config) of
|
Config) of
|
||||||
{ok, already_created} ->
|
{ok, already_created} ->
|
||||||
Context#{resource_id => ResourceID};
|
Context#{resource_id => ResourceID};
|
||||||
|
|
|
@ -89,7 +89,7 @@ store_retained(_, Msg =#message{topic = Topic}) ->
|
||||||
write);
|
write);
|
||||||
[] ->
|
[] ->
|
||||||
?LOG(error,
|
?LOG(error,
|
||||||
"Cannot retain message(topic=~s) for table is full!",
|
"Cannot retain message(topic=~ts) for table is full!",
|
||||||
[Topic]),
|
[Topic]),
|
||||||
ok
|
ok
|
||||||
end
|
end
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
, rule_test/2
|
, rule_test/2
|
||||||
]).
|
]).
|
||||||
|
|
||||||
-define(ERR_NO_RULE(ID), list_to_binary(io_lib:format("Rule ~s Not Found", [(ID)]))).
|
-define(ERR_NO_RULE(ID), list_to_binary(io_lib:format("Rule ~ts Not Found", [(ID)]))).
|
||||||
-define(ERR_BADARGS(REASON),
|
-define(ERR_BADARGS(REASON),
|
||||||
begin
|
begin
|
||||||
R0 = err_msg(REASON),
|
R0 = err_msg(REASON),
|
||||||
|
|
|
@ -914,9 +914,9 @@ map_path(Key) ->
|
||||||
function_literal(Fun, []) when is_atom(Fun) ->
|
function_literal(Fun, []) when is_atom(Fun) ->
|
||||||
atom_to_list(Fun) ++ "()";
|
atom_to_list(Fun) ++ "()";
|
||||||
function_literal(Fun, [FArg | Args]) when is_atom(Fun), is_list(Args) ->
|
function_literal(Fun, [FArg | Args]) when is_atom(Fun), is_list(Args) ->
|
||||||
WithFirstArg = io_lib:format("~s(~0p", [atom_to_list(Fun), FArg]),
|
WithFirstArg = io_lib:format("~ts(~0p", [atom_to_list(Fun), FArg]),
|
||||||
lists:foldl(fun(Arg, Literal) ->
|
lists:foldl(fun(Arg, Literal) ->
|
||||||
io_lib:format("~s, ~0p", [Literal, Arg])
|
io_lib:format("~ts, ~0p", [Literal, Arg])
|
||||||
end, WithFirstArg, Args) ++ ")";
|
end, WithFirstArg, Args) ++ ")";
|
||||||
function_literal(Fun, Args) ->
|
function_literal(Fun, Args) ->
|
||||||
{invalid_func, {Fun, Args}}.
|
{invalid_func, {Fun, Args}}.
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
|
|
||||||
-spec console(map(), map(), map()) -> any().
|
-spec console(map(), map(), map()) -> any().
|
||||||
console(Selected, #{metadata := #{rule_id := RuleId}} = Envs, _Args) ->
|
console(Selected, #{metadata := #{rule_id := RuleId}} = Envs, _Args) ->
|
||||||
?ULOG("[rule output] ~s~n"
|
?ULOG("[rule output] ~ts~n"
|
||||||
"\tOutput Data: ~p~n"
|
"\tOutput Data: ~p~n"
|
||||||
"\tEnvs: ~p~n", [RuleId, Selected, Envs]).
|
"\tEnvs: ~p~n", [RuleId, Selected, Envs]).
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
-type collection() :: {alias(), [term()]}.
|
-type collection() :: {alias(), [term()]}.
|
||||||
|
|
||||||
-define(ephemeral_alias(TYPE, NAME),
|
-define(ephemeral_alias(TYPE, NAME),
|
||||||
iolist_to_binary(io_lib:format("_v_~s_~p_~p", [TYPE, NAME, erlang:system_time()]))).
|
iolist_to_binary(io_lib:format("_v_~ts_~p_~p", [TYPE, NAME, erlang:system_time()]))).
|
||||||
|
|
||||||
-define(ActionMaxRetry, 3).
|
-define(ActionMaxRetry, 3).
|
||||||
|
|
||||||
|
|
|
@ -423,9 +423,9 @@ t_concat(_) ->
|
||||||
?assertEqual(<<>>, apply_func(concat, [<<"">>, <<"">>])).
|
?assertEqual(<<>>, apply_func(concat, [<<"">>, <<"">>])).
|
||||||
|
|
||||||
t_sprintf(_) ->
|
t_sprintf(_) ->
|
||||||
?assertEqual(<<"Hello Shawn!">>, apply_func(sprintf, [<<"Hello ~s!">>, <<"Shawn">>])),
|
?assertEqual(<<"Hello Shawn!">>, apply_func(sprintf, [<<"Hello ~ts!">>, <<"Shawn">>])),
|
||||||
?assertEqual(<<"Name: ABC, Count: 2">>, apply_func(sprintf, [<<"Name: ~s, Count: ~p">>, <<"ABC">>, 2])),
|
?assertEqual(<<"Name: ABC, Count: 2">>, apply_func(sprintf, [<<"Name: ~ts, Count: ~p">>, <<"ABC">>, 2])),
|
||||||
?assertEqual(<<"Name: ABC, Count: 2, Status: {ok,running}">>, apply_func(sprintf, [<<"Name: ~s, Count: ~p, Status: ~p">>, <<"ABC">>, 2, {ok, running}])).
|
?assertEqual(<<"Name: ABC, Count: 2, Status: {ok,running}">>, apply_func(sprintf, [<<"Name: ~ts, Count: ~p, Status: ~p">>, <<"ABC">>, 2, {ok, running}])).
|
||||||
|
|
||||||
t_pad(_) ->
|
t_pad(_) ->
|
||||||
?assertEqual(<<"abc ">>, apply_func(pad, [<<"abc">>, 5])),
|
?assertEqual(<<"abc ">>, apply_func(pad, [<<"abc">>, 5])),
|
||||||
|
|
Loading…
Reference in New Issue