Get rid of excessive (io)list_to_binary/1 calls

This commit is contained in:
Evgeniy Khramtsov 2016-11-24 15:06:06 +03:00
parent b14843d098
commit 49f1275e20
26 changed files with 163 additions and 193 deletions

View File

@ -342,7 +342,7 @@ acl_rule_verify({node_glob, {UR, SR}}) when is_binary(UR), is_binary(SR) ->
acl_rule_verify(_Spec) ->
false.
invalid_syntax(Msg, Data) ->
throw({invalid_syntax, iolist_to_binary(io_lib:format(Msg, Data))}).
throw({invalid_syntax, (str:format(Msg, Data))}).
acl_rules_verify([{acl, Name} | Rest], true) when is_atom(Name) ->
acl_rules_verify(Rest, true);

View File

@ -532,10 +532,10 @@ key_split([{Arg, Value} | Rest], Results, Order, Required, Duplicates) ->
end.
report_error(Format, Args) ->
throw({invalid_syntax, iolist_to_binary(io_lib:format(Format, Args))}).
throw({invalid_syntax, (str:format(Format, Args))}).
parse_error(Format, Args) ->
{error, iolist_to_binary(io_lib:format(Format, Args))}.
{error, (str:format(Format, Args))}.
opt_type(api_permissions) ->
fun parse_api_permissions/1;

View File

@ -302,8 +302,8 @@ set_loglevel(LogLevel) ->
%%%
stop_kindly(DelaySeconds, AnnouncementTextString) ->
Subject = list_to_binary(io_lib:format("Server stop in ~p seconds!", [DelaySeconds])),
WaitingDesc = list_to_binary(io_lib:format("Waiting ~p seconds", [DelaySeconds])),
Subject = (str:format("Server stop in ~p seconds!", [DelaySeconds])),
WaitingDesc = (str:format("Waiting ~p seconds", [DelaySeconds])),
AnnouncementText = list_to_binary(AnnouncementTextString),
Steps = [
{"Stopping ejabberd port listeners",
@ -337,8 +337,7 @@ stop_kindly(DelaySeconds, AnnouncementTextString) ->
ok.
send_service_message_all_mucs(Subject, AnnouncementText) ->
Message = list_to_binary(
io_lib:format("~s~n~s", [Subject, AnnouncementText])),
Message = str:format("~s~n~s", [Subject, AnnouncementText]),
lists:foreach(
fun(ServerHost) ->
MUCHost = gen_mod:get_module_opt_host(

View File

@ -807,7 +807,7 @@ encode_body(#body{attrs = Attrs, els = Els}, Type) ->
true -> {AmK, <<"true">>};
false -> {AmK, <<"false">>};
I when is_integer(I), I >= 0 ->
{AmK, iolist_to_binary(integer_to_list(I))};
{AmK, integer_to_binary(I)};
_ -> {AmK, V}
end;
({K, V}) -> {K, V}

View File

@ -103,7 +103,7 @@ create_captcha(SID, From, To, Lang, Limiter, Args) ->
BodyString1 = translate:translate(Lang,
<<"Your messages to ~s are being blocked. "
"To unblock them, visit ~s">>),
BodyString = iolist_to_binary(io_lib:format(BodyString1,
BodyString = (str:format(BodyString1,
[JID, get_url(Id)])),
Body = xmpp:mk_text(BodyString, Lang),
OOB = #oob_x{url = get_url(Id)},

View File

@ -550,12 +550,12 @@ make_xhtml_output(State, Status, Headers, XHTML) ->
of
{value, _} ->
[{<<"Content-Length">>,
iolist_to_binary(integer_to_list(byte_size(Data)))}
integer_to_binary(byte_size(Data))}
| Headers];
_ ->
[{<<"Content-Type">>, <<"text/html; charset=utf-8">>},
{<<"Content-Length">>,
iolist_to_binary(integer_to_list(byte_size(Data)))}
integer_to_binary(byte_size(Data))}
| Headers]
end,
HeadersOut = case {State#state.request_version,
@ -577,7 +577,7 @@ make_xhtml_output(State, Status, Headers, XHTML) ->
end,
HeadersOut),
SL = [Version,
iolist_to_binary(integer_to_list(Status)), <<" ">>,
integer_to_binary(Status), <<" ">>,
code_to_phrase(Status), <<"\r\n">>],
Data2 = case State#state.request_method of
'HEAD' -> <<"">>;

View File

@ -972,21 +972,17 @@ prepare_outpacket_response(#http_bind{id = Sid,
[{<<"xmlns">>, ?NS_HTTP_BIND},
{<<"sid">>, Sid},
{<<"wait">>,
iolist_to_binary(integer_to_list(Wait))},
integer_to_binary(Wait)},
{<<"requests">>,
iolist_to_binary(integer_to_list(Hold
+
1))},
integer_to_binary(Hold + 1)},
{<<"inactivity">>,
iolist_to_binary(integer_to_list(trunc(MaxInactivity
/
1000)))},
integer_to_binary(
trunc(MaxInactivity / 1000))},
{<<"maxpause">>,
iolist_to_binary(integer_to_list(MaxPause))},
integer_to_binary(MaxPause)},
{<<"polling">>,
iolist_to_binary(integer_to_list(trunc((?MIN_POLLING)
/
1000000)))},
integer_to_binary(
trunc((?MIN_POLLING) / 1000000))},
{<<"ver">>, ?BOSH_VERSION},
{<<"from">>, From},
{<<"secure">>, <<"true">>}]

View File

@ -196,7 +196,7 @@ format_scram_password({StoredKey, ServerKey, Salt, IterationCount}) ->
StoredKeyB64 = base64:encode(StoredKey),
ServerKeyB64 = base64:encode(ServerKey),
SaltB64 = base64:encode(Salt),
IterationCountBin = list_to_binary(integer_to_list(IterationCount)),
IterationCountBin = (integer_to_binary(IterationCount)),
<<"scram:", StoredKeyB64/binary, ",", ServerKeyB64/binary, ",", SaltB64/binary, ",", IterationCountBin/binary>>.
parse_scram_password(PassData) ->
@ -206,7 +206,7 @@ parse_scram_password(PassData) ->
storedkey = StoredKeyB64,
serverkey = ServerKeyB64,
salt = SaltB64,
iterationcount = list_to_integer(binary_to_list(IterationCountBin))
iterationcount = (binary_to_integer(IterationCountBin))
}.
-spec get_vcard(binary(), binary()) -> [xmlel()].
@ -554,9 +554,8 @@ stop(Fmt, Args) ->
make_filename_template() ->
{{Year, Month, Day}, {Hour, Minute, Second}} = calendar:local_time(),
list_to_binary(
io_lib:format("~4..0w~2..0w~2..0w-~2..0w~2..0w~2..0w",
[Year, Month, Day, Hour, Minute, Second])).
str:format("~4..0w~2..0w~2..0w-~2..0w~2..0w~2..0w",
[Year, Month, Day, Hour, Minute, Second]).
make_main_basefilename(Dir, FnT) ->
Filename2 = <<FnT/binary, ".xml">>,

View File

@ -428,7 +428,7 @@ map_key(Obj, _, _) ->
<<"b_", B/binary>> ->
B;
<<"i_", B/binary>> ->
list_to_integer(binary_to_list(B));
(binary_to_integer(B));
B ->
erlang:binary_to_term(B)
end].
@ -483,7 +483,7 @@ encode_index_key(Idx, Key) ->
encode_key(Bin) when is_binary(Bin) ->
<<"b_", Bin/binary>>;
encode_key(Int) when is_integer(Int) ->
<<"i_", (list_to_binary(integer_to_list(Int)))/binary>>;
<<"i_", ((integer_to_binary(Int)))/binary>>;
encode_key(Term) ->
erlang:term_to_binary(Term).
@ -519,7 +519,7 @@ log_error(_, _, _) ->
ok.
make_invalid_object(Val) ->
list_to_binary(io_lib:fwrite("Invalid object: ~p", [Val])).
(str:format("Invalid object: ~p", [Val])).
get_random_pid() ->
PoolPid = ejabberd_riak_sup:get_random_pid(),

View File

@ -180,10 +180,9 @@ process_large_heap(Pid, Info) ->
Host = (?MYNAME),
JIDs = get_admin_jids(),
DetailedInfo = detailed_info(Pid),
Body = iolist_to_binary(
io_lib:format("(~w) The process ~w is consuming too "
"much memory:~n~p~n~s",
[node(), Pid, Info, DetailedInfo])),
Body = str:format("(~w) The process ~w is consuming too "
"much memory:~n~p~n~s",
[node(), Pid, Info, DetailedInfo]),
From = jid:make(<<"">>, Host, <<"watchdog">>),
Hint = [#hint{type = 'no-permanent-store'}],
lists:foreach(

View File

@ -763,8 +763,8 @@ process_admin(Host,
[?XAE(<<"form">>,
[{<<"action">>, <<"">>}, {<<"method">>, <<"post">>}]++direction(ltr),
[?TEXTAREA(<<"acls">>,
(iolist_to_binary(integer_to_list(lists:max([16,
NumLines])))),
(integer_to_binary(lists:max([16,
NumLines]))),
<<"80">>, <<(iolist_to_binary(ACLsP))/binary, ".">>),
?BR,
?INPUTT(<<"submit">>, <<"submit">>, <<"Submit">>)])],
@ -865,8 +865,8 @@ process_admin(Host,
[?XAE(<<"form">>,
[{<<"action">>, <<"">>}, {<<"method">>, <<"post">>}]++direction(ltr),
[?TEXTAREA(<<"access">>,
(iolist_to_binary(integer_to_list(lists:max([16,
NumLines])))),
(integer_to_binary(lists:max([16,
NumLines]))),
<<"80">>, <<(iolist_to_binary(AccessP))/binary, ".">>),
?BR,
?INPUTT(<<"submit">>, <<"submit">>, <<"Submit">>)])],
@ -926,7 +926,7 @@ process_admin(Host,
Rs1 -> Rs1
end,
make_xhtml([?XC(<<"h1">>,
list_to_binary(io_lib:format(
(str:format(
?T(<<"~s access rule configuration">>),
[SName])))]
++
@ -1141,7 +1141,7 @@ acl_spec_select(ID, Opt) ->
%% @spec (T::any()) -> StringLine::string()
term_to_string(T) ->
StringParagraph =
iolist_to_binary(io_lib:format("~1000000p", [T])),
(str:format("~1000000p", [T])),
ejabberd_regexp:greplace(StringParagraph, <<"\\n ">>,
<<"">>).
@ -1506,7 +1506,7 @@ list_given_users(Host, Users, Prefix, Lang, URLFunc) ->
{{Year, Month, Day},
{Hour, Minute, Second}} =
calendar:now_to_local_time(TimeStamp),
iolist_to_binary(io_lib:format("~w-~.2.0w-~.2.0w ~.2.0w:~.2.0w:~.2.0w",
(str:format("~w-~.2.0w-~.2.0w ~.2.0w:~.2.0w:~.2.0w",
[Year,
Month,
Day,
@ -1683,14 +1683,14 @@ user_info(User, Server, Query, Lang) ->
Shift rem 1000000, 0},
{{Year, Month, Day}, {Hour, Minute, Second}} =
calendar:now_to_local_time(TimeStamp),
iolist_to_binary(io_lib:format("~w-~.2.0w-~.2.0w ~.2.0w:~.2.0w:~.2.0w",
(str:format("~w-~.2.0w-~.2.0w ~.2.0w:~.2.0w:~.2.0w",
[Year, Month, Day,
Hour, Minute,
Second]))
end;
_ -> ?T(<<"Online">>)
end,
[?XC(<<"h1">>, list_to_binary(io_lib:format(?T(<<"User ~s">>),
[?XC(<<"h1">>, (str:format(?T(<<"User ~s">>),
[us_to_list(US)])))]
++
case Res of
@ -1773,9 +1773,7 @@ list_last_activity(Host, Lang, Integral, Period) ->
[?XAE(<<"li">>,
[{<<"style">>,
<<"width:",
(iolist_to_binary(integer_to_list(trunc(90 * V
/
Max))))/binary,
(integer_to_binary(trunc(90 * V / Max)))/binary,
"%;">>}],
[{xmlcdata, pretty_string_int(V)}])
|| V <- Hist ++ Tail])]
@ -1850,7 +1848,7 @@ get_node(global, Node, [], Query, Lang) ->
Base = get_base_path(global, Node),
MenuItems2 = make_menu_items(global, Node, Base, Lang),
[?XC(<<"h1">>,
list_to_binary(io_lib:format(?T(<<"Node ~p">>), [Node])))]
(str:format(?T(<<"Node ~p">>), [Node])))]
++
case Res of
ok -> [?XREST(<<"Submitted">>)];
@ -1875,7 +1873,7 @@ get_node(global, Node, [], Query, Lang) ->
get_node(Host, Node, [], _Query, Lang) ->
Base = get_base_path(Host, Node),
MenuItems2 = make_menu_items(Host, Node, Base, Lang),
[?XC(<<"h1">>, list_to_binary(io_lib:format(?T(<<"Node ~p">>), [Node]))),
[?XC(<<"h1">>, (str:format(?T(<<"Node ~p">>), [Node]))),
?XE(<<"ul">>,
([?LI([?ACT(<<Base/binary, "modules/">>,
<<"Modules">>)])]
@ -1934,7 +1932,7 @@ get_node(global, Node, [<<"db">>], Query, Lang) ->
end,
STables),
[?XC(<<"h1">>,
list_to_binary(io_lib:format(?T(<<"Database Tables at ~p">>),
(str:format(?T(<<"Database Tables at ~p">>),
[Node]))
)]
++
@ -1970,9 +1968,9 @@ get_node(global, Node, [<<"backup">>], Query, Lang) ->
ok -> [?XREST(<<"Submitted">>)];
{error, Error} ->
[?XRES(<<(?T(<<"Error">>))/binary, ": ",
(list_to_binary(io_lib:format("~p", [Error])))/binary>>)]
((str:format("~p", [Error])))/binary>>)]
end,
[?XC(<<"h1">>, list_to_binary(io_lib:format(?T(<<"Backup of ~p">>), [Node])))]
[?XC(<<"h1">>, (str:format(?T(<<"Backup of ~p">>), [Node])))]
++
ResS ++
[?XCT(<<"p">>,
@ -2124,7 +2122,7 @@ get_node(global, Node, [<<"ports">>], Query, Lang) ->
{'EXIT', _Reason} -> error;
{is_added, ok} -> ok;
{is_added, {error, Reason}} ->
{error, iolist_to_binary(io_lib:format("~p", [Reason]))};
{error, (str:format("~p", [Reason]))};
_ -> nothing
end,
NewPorts = lists:sort(ejabberd_cluster:call(Node, ejabberd_config,
@ -2161,7 +2159,7 @@ get_node(Host, Node, [<<"modules">>], Query, Lang)
end,
NewModules = lists:sort(ejabberd_cluster:call(Node, gen_mod,
loaded_modules_with_opts, [Host])),
H1String = list_to_binary(io_lib:format(?T(<<"Modules at ~p">>), [Node])),
H1String = (str:format(?T(<<"Modules at ~p">>), [Node])),
(?H1GL(H1String, <<"modulesoverview">>,
<<"Modules Overview">>))
++
@ -2177,10 +2175,10 @@ get_node(Host, Node, [<<"modules">>], Query, Lang)
get_node(global, Node, [<<"stats">>], _Query, Lang) ->
UpTime = ejabberd_cluster:call(Node, erlang, statistics,
[wall_clock]),
UpTimeS = list_to_binary(io_lib:format("~.3f",
UpTimeS = (str:format("~.3f",
[element(1, UpTime) / 1000])),
CPUTime = ejabberd_cluster:call(Node, erlang, statistics, [runtime]),
CPUTimeS = list_to_binary(io_lib:format("~.3f",
CPUTimeS = (str:format("~.3f",
[element(1, CPUTime) / 1000])),
OnlineUsers = ejabberd_sm:connected_users_number(),
TransactionsCommitted = ejabberd_cluster:call(Node, mnesia,
@ -2192,7 +2190,7 @@ get_node(global, Node, [<<"stats">>], _Query, Lang) ->
TransactionsLogged = ejabberd_cluster:call(Node, mnesia, system_info,
[transaction_log_writes]),
[?XC(<<"h1">>,
list_to_binary(io_lib:format(?T(<<"Statistics of ~p">>), [Node]))),
(str:format(?T(<<"Statistics of ~p">>), [Node]))),
?XAE(<<"table">>, [],
[?XE(<<"tbody">>,
[?XE(<<"tr">>,
@ -2256,11 +2254,11 @@ get_node(global, Node, [<<"update">>], Query, Lang) ->
(BeamsLis ++ SelectButtons))
end,
FmtScript = (?XC(<<"pre">>,
list_to_binary(io_lib:format("~p", [Script])))),
(str:format("~p", [Script])))),
FmtLowLevelScript = (?XC(<<"pre">>,
list_to_binary(io_lib:format("~p", [LowLevelScript])))),
(str:format("~p", [LowLevelScript])))),
[?XC(<<"h1">>,
list_to_binary(io_lib:format(?T(<<"Update ~p">>), [Node])))]
(str:format(?T(<<"Update ~p">>), [Node])))]
++
case Res of
ok -> [?XREST(<<"Submitted">>)];
@ -2482,7 +2480,7 @@ node_ports_to_xhtml(Ports, Lang) ->
SModule, <<"15">>)]),
?XAE(<<"td">>, direction(ltr),
[?TEXTAREA(<<"opts", SSPort/binary>>,
(iolist_to_binary(integer_to_list(NumLines))),
(integer_to_binary(NumLines)),
<<"35">>, SOptsClean)]),
?XE(<<"td">>,
[?INPUTT(<<"submit">>,
@ -2625,7 +2623,7 @@ node_modules_to_xhtml(Modules, Lang) ->
[?XC(<<"td">>, SModule),
?XAE(<<"td">>, direction(ltr),
[?TEXTAREA(<<"opts", SModule/binary>>,
(iolist_to_binary(integer_to_list(NumLines))),
(integer_to_binary(NumLines)),
<<"40">>, SOpts)]),
?XE(<<"td">>,
[?INPUTT(<<"submit">>,
@ -2707,11 +2705,11 @@ node_update_parse_query(Node, Query) ->
{ok, _} -> ok;
{error, Error} ->
?ERROR_MSG("~p~n", [Error]),
{error, iolist_to_binary(io_lib:format("~p", [Error]))};
{error, (str:format("~p", [Error]))};
{badrpc, Error} ->
?ERROR_MSG("Bad RPC: ~p~n", [Error]),
{error,
<<"Bad RPC: ", (iolist_to_binary(io_lib:format("~p", [Error])))/binary>>}
<<"Bad RPC: ", ((str:format("~p", [Error])))/binary>>}
end;
_ -> nothing
end.
@ -2776,7 +2774,7 @@ pretty_print_xml(#xmlel{name = Name, attrs = Attrs,
element_to_list(X) when is_atom(X) ->
iolist_to_binary(atom_to_list(X));
element_to_list(X) when is_integer(X) ->
iolist_to_binary(integer_to_list(X)).
integer_to_binary(X).
list_to_element(Bin) ->
{ok, Tokens, _} = erl_scan:string(binary_to_list(Bin)),
@ -2784,8 +2782,8 @@ list_to_element(Bin) ->
Element.
url_func({user_diapason, From, To}) ->
<<(iolist_to_binary(integer_to_list(From)))/binary, "-",
(iolist_to_binary(integer_to_list(To)))/binary, "/">>;
<<(integer_to_binary(From))/binary, "-",
(integer_to_binary(To))/binary, "/">>;
url_func({users_queue, Prefix, User, _Server}) ->
<<Prefix/binary, "user/", User/binary, "/queue/">>;
url_func({user, Prefix, User, _Server}) ->
@ -2800,7 +2798,7 @@ cache_control_public() ->
%% Transform 1234567890 into "1,234,567,890"
pretty_string_int(Integer) when is_integer(Integer) ->
pretty_string_int(iolist_to_binary(integer_to_list(Integer)));
pretty_string_int(integer_to_binary(Integer));
pretty_string_int(String) when is_binary(String) ->
{_, Result} = lists:foldl(fun (NewNumber, {3, Result}) ->
{1, <<NewNumber, $,, Result/binary>>};

View File

@ -677,14 +677,14 @@ timestamp_to_iso({{Year, Month, Day},
%% http://xmpp.org/extensions/xep-0091.html#time
timestamp_to_legacy({{Year, Month, Day},
{Hour, Minute, Second}}) ->
iolist_to_binary(io_lib:format("~4..0B~2..0B~2..0BT~2..0B:~2..0B:~2..0B",
(str:format("~4..0B~2..0B~2..0BT~2..0B:~2..0B:~2..0B",
[Year, Month, Day, Hour, Minute, Second])).
-spec timestamp_to_iso_basic(calendar:datetime()) -> binary().
%% This is the ISO 8601 basic bormat
timestamp_to_iso_basic({{Year, Month, Day},
{Hour, Minute, Second}}) ->
iolist_to_binary(io_lib:format("~4..0B~2..0B~2..0BT~2..0B~2..0B~2..0B",
(str:format("~4..0B~2..0B~2..0BT~2..0B~2..0B~2..0B",
[Year, Month, Day, Hour, Minute, Second])).
-spec now_to_utc_string(erlang:timestamp()) -> binary().
@ -703,7 +703,7 @@ now_to_utc_string({MegaSecs, Secs, MicroSecs}, Precision) ->
Max ->
now_to_utc_string({MegaSecs, Secs + 1, 0}, Precision);
FracOfSec ->
list_to_binary(io_lib:format("~4..0B-~2..0B-~2..0BT"
(str:format("~4..0B-~2..0B-~2..0BT"
"~2..0B:~2..0B:~2..0B.~*..0BZ",
[Year, Month, Day, Hour, Minute, Second,
Precision, FracOfSec]))
@ -725,7 +725,7 @@ now_to_local_string({MegaSecs, Secs, MicroSecs}) ->
end,
{{Year, Month, Day}, {Hour, Minute, Second}} =
LocalTime,
list_to_binary(io_lib:format("~4..0B-~2..0B-~2..0BT~2..0B:~2..0B:~2..0B.~6."
(str:format("~4..0B-~2..0B-~2..0BT~2..0B:~2..0B:~2..0B.~6."
".0B~s~2..0B:~2..0B",
[Year, Month, Day, Hour, Minute, Second,
MicroSecs, Sign, H, M])).

View File

@ -680,9 +680,9 @@ get_all_vh_users(Host) ->
lists:map(fun (K) ->
L = K + M - 1,
Node = <<"@",
(iolist_to_binary(integer_to_list(K)))/binary,
(integer_to_binary(K))/binary,
"-",
(iolist_to_binary(integer_to_list(L)))/binary>>,
(integer_to_binary(L))/binary>>,
{FS, FU} = lists:nth(K, SUsers),
{LS, LU} = if L < N -> lists:nth(L, SUsers);
true -> lists:last(SUsers)
@ -707,8 +707,7 @@ get_outgoing_s2s(Host, Lang) ->
Host == FH orelse str:suffix(DotHost, FH)],
lists:map(
fun (T) ->
Name = iolist_to_binary(
io_lib:format(?T(Lang, <<"To ~s">>),[T])),
Name = str:format(?T(Lang, <<"To ~s">>),[T]),
#disco_item{jid = jid:make(Host),
node = <<"outgoing s2s/", T/binary>>,
name = Name}
@ -722,8 +721,7 @@ get_outgoing_s2s(Host, Lang, To) ->
lists:map(
fun ({F, _T}) ->
Node = <<"outgoing s2s/", To/binary, "/", F/binary>>,
Name = iolist_to_binary(
io_lib:format(?T(Lang, <<"From ~s">>), [F])),
Name = str:format(?T(Lang, <<"From ~s">>), [F]),
#disco_item{jid = jid:make(Host), node = Node, name = Name}
end,
lists:keysort(1,
@ -1082,14 +1080,13 @@ get_form(_Host,
label = ?T(Lang, <<"Message body">>)}]}};
get_form(Host, [<<"config">>, <<"acls">>], Lang) ->
ACLs = str:tokens(
iolist_to_binary(
io_lib:format("~p.",
[mnesia:dirty_select(
acl,
ets:fun2ms(
fun({acl, {Name, H}, Spec}) when H == Host ->
{acl, Name, Spec}
end))])),
str:format("~p.",
[mnesia:dirty_select(
acl,
ets:fun2ms(
fun({acl, {Name, H}, Spec}) when H == Host ->
{acl, Name, Spec}
end))]),
<<"\n">>),
{result,
#xdata{title = ?T(Lang, <<"Access Control List Configuration">>),
@ -1101,14 +1098,13 @@ get_form(Host, [<<"config">>, <<"acls">>], Lang) ->
values = ACLs}]}};
get_form(Host, [<<"config">>, <<"access">>], Lang) ->
Accs = str:tokens(
iolist_to_binary(
io_lib:format("~p.",
[mnesia:dirty_select(
access,
ets:fun2ms(
fun({access, {Name, H}, Acc}) when H == Host ->
{access, Name, Acc}
end))])),
str:format("~p.",
[mnesia:dirty_select(
access,
ets:fun2ms(
fun({access, {Name, H}, Acc}) when H == Host ->
{access, Name, Acc}
end))]),
<<"\n">>),
{result,
#xdata{title = ?T(Lang, <<"Access Configuration">>),
@ -1199,9 +1195,7 @@ get_form(_Host, ?NS_ADMINL(<<"user-stats">>), Lang) ->
required = true}]}};
get_form(Host,
?NS_ADMINL(<<"get-registered-users-num">>), Lang) ->
Num = list_to_binary(
io_lib:format("~p",
[ejabberd_auth:get_vh_registered_users_number(Host)])),
Num = integer_to_binary(ejabberd_auth:get_vh_registered_users_number(Host)),
{result, completed,
#xdata{type = form,
fields = [?HFIELD(),
@ -1211,9 +1205,7 @@ get_form(Host,
values = [Num]}]}};
get_form(Host, ?NS_ADMINL(<<"get-online-users-num">>),
Lang) ->
Num = list_to_binary(
io_lib:format("~p",
[length(ejabberd_sm:get_vh_session_list(Host))])),
Num = integer_to_binary(ejabberd_sm:get_vh_session_number(Host)),
{result, completed,
#xdata{type = form,
fields = [?HFIELD(),
@ -1641,7 +1633,7 @@ set_form(From, Host,
TimeStamp = {Shift div 1000000, Shift rem 1000000, 0},
{{Year, Month, Day}, {Hour, Minute, Second}} =
calendar:now_to_local_time(TimeStamp),
iolist_to_binary(io_lib:format("~w-~.2.0w-~.2.0w ~.2.0w:~.2.0w:~.2.0w",
(str:format("~w-~.2.0w-~.2.0w ~.2.0w:~.2.0w:~.2.0w",
[Year, Month, Day, Hour,
Minute, Second]))
end;

View File

@ -464,24 +464,23 @@ get_form(ServerHost, Host, From, Lang) ->
var = <<"username">>,
values = [Username]},
#xdata_field{type = fixed,
values = [iolist_to_binary(
io_lib:format(
translate:translate(
Lang,
<<"If you want to specify"
" different ports, "
"passwords, encodings "
"for IRC servers, "
"fill this list with "
"values in format "
"'{\"irc server\", "
"\"encoding\", port, "
"\"password\"}'. "
"By default this "
"service use \"~s\" "
"encoding, port ~p, "
"empty password.">>),
[DefaultEncoding, ?DEFAULT_IRC_PORT]))]},
values = [str:format(
translate:translate(
Lang,
<<"If you want to specify"
" different ports, "
"passwords, encodings "
"for IRC servers, "
"fill this list with "
"values in format "
"'{\"irc server\", "
"\"encoding\", port, "
"\"password\"}'. "
"By default this "
"service use \"~s\" "
"encoding, port ~p, "
"empty password.">>),
[DefaultEncoding, ?DEFAULT_IRC_PORT])]},
#xdata_field{type = fixed,
values = [translate:translate(
Lang,
@ -493,11 +492,10 @@ get_form(ServerHost, Host, From, Lang) ->
label = translate:translate(
Lang, <<"Connections parameters">>),
var = <<"connections_params">>,
values = str:tokens(list_to_binary(
io_lib:format(
"~p.",
[conn_params_to_list(
ConnectionsParams)])),
values = str:tokens(str:format(
"~p.",
[conn_params_to_list(
ConnectionsParams)]),
<<"\n">>)}],
X = #xdata{type = form,
title = <<(translate:translate(
@ -657,11 +655,10 @@ adhoc_join(From, To, #adhoc_command{lang = Lang, xdata = X} = Request) ->
RoomJID = jid:make(<<Channel/binary, "%", Server/binary>>,
To#jid.server),
Reason = translate:translate(Lang, <<"Join the IRC channel here.">>),
Body = iolist_to_binary(
io_lib:format(
translate:translate(
Lang, <<"Join the IRC channel in this Jabber ID: ~s">>),
[jid:to_string(RoomJID)])),
Body = str:format(
translate:translate(
Lang, <<"Join the IRC channel in this Jabber ID: ~s">>),
[jid:to_string(RoomJID)]),
Invite = #message{
body = xmpp:mk_text(Body, Lang),
sub_els = [#muc_user{
@ -782,43 +779,37 @@ generate_connection_params_field(Lang, Server, Encoding,
Port;
true -> ?DEFAULT_IRC_PORT
end,
PortUsed =
iolist_to_binary(integer_to_list(PortUsedInt)),
PortUsed = integer_to_binary(PortUsedInt),
PasswordUsed = case Password of
<<>> -> <<>>;
_ -> Password
end,
NumberString =
iolist_to_binary(integer_to_list(Number)),
NumberString = integer_to_binary(Number),
[#xdata_field{var = <<"password", NumberString/binary>>,
type = 'text-single',
label = iolist_to_binary(
io_lib:format(
translate:translate(Lang, <<"Password ~b">>),
[Number])),
label = str:format(
translate:translate(Lang, <<"Password ~b">>),
[Number]),
values = [PasswordUsed]},
#xdata_field{var = <<"port", NumberString/binary>>,
type = 'text-single',
label = iolist_to_binary(
io_lib:format(
translate:translate(Lang, <<"Port ~b">>),
[Number])),
label = str:format(
translate:translate(Lang, <<"Port ~b">>),
[Number]),
values = [PortUsed]},
#xdata_field{var = <<"encoding", NumberString/binary>>,
type = 'list-single',
label = list_to_binary(
io_lib:format(
translate:translate(Lang, <<"Encoding for server ~b">>),
[Number])),
label = str:format(
translate:translate(Lang, <<"Encoding for server ~b">>),
[Number]),
values = [EncodingUsed],
options = [#xdata_option{label = E, value = E}
|| E <- ?POSSIBLE_ENCODINGS]},
#xdata_field{var = <<"server", NumberString/binary>>,
type = 'text-single',
label = list_to_binary(
io_lib:format(
translate:translate(Lang, <<"Server ~b">>),
[Number])),
label = str:format(
translate:translate(Lang, <<"Server ~b">>),
[Number]),
values = [Server]}].
parse_connections_params(#xdata{fields = Fields}) ->

View File

@ -1213,5 +1213,5 @@ unixtime2string(Unixtime) ->
{0, 0, 0}}),
{{Year, Month, Day}, {Hour, Minute, Second}} =
calendar:universal_time_to_local_time(calendar:gregorian_seconds_to_datetime(Secs)),
iolist_to_binary(io_lib:format("~4..0w-~2..0w-~2..0w ~2..0w:~2..0w:~2..0w",
(str:format("~4..0w-~2..0w-~2..0w ~2..0w:~2..0w:~2..0w",
[Year, Month, Day, Hour, Minute, Second])).

View File

@ -247,18 +247,18 @@ build_filename_string(TimeStamp, OutDir, RoomJID,
{Dir, Filename, Rel} = case DirType of
subdirs ->
SYear =
iolist_to_binary(io_lib:format("~4..0w",
(str:format("~4..0w",
[Year])),
SMonth =
iolist_to_binary(io_lib:format("~2..0w",
(str:format("~2..0w",
[Month])),
SDay = iolist_to_binary(io_lib:format("~2..0w",
SDay = (str:format("~2..0w",
[Day])),
{fjoin([SYear, SMonth]), SDay,
<<"../..">>};
plain ->
Date =
iolist_to_binary(io_lib:format("~4..0w-~2..0w-~2..0w",
(str:format("~4..0w-~2..0w-~2..0w",
[Year,
Month,
Day])),
@ -727,7 +727,7 @@ fw(F, S, FileFormat) when is_atom(FileFormat) ->
fw(F, S, [], FileFormat).
fw(F, S, O, FileFormat) ->
S1 = list_to_binary(io_lib:format(binary_to_list(S) ++ "~n", O)),
S1 = (str:format(binary_to_list(S) ++ "~n", O)),
S2 = case FileFormat of
html ->
S1;

View File

@ -717,7 +717,7 @@ user_queue(User, Server, Query, Lang) ->
Hdrs = get_messages_subset(US, Server, HdrsAll),
FMsgs = format_user_queue(Hdrs),
[?XC(<<"h1">>,
list_to_binary(io_lib:format(?T(<<"~s's Offline Messages Queue">>),
(str:format(?T(<<"~s's Offline Messages Queue">>),
[us_to_list(US)])))]
++
case Res of
@ -801,7 +801,7 @@ webadmin_user(Acc, User, Server, Lang) ->
QueueLen = count_offline_messages(jid:nodeprep(User),
jid:nameprep(Server)),
FQueueLen = [?AC(<<"queue/">>,
(iolist_to_binary(integer_to_list(QueueLen))))],
(integer_to_binary(QueueLen)))],
Acc ++
[?XCT(<<"h3">>, <<"Offline Messages:">>)] ++
FQueueLen ++

View File

@ -3776,7 +3776,7 @@ err_unsupported_access_model() ->
-spec uniqid() -> mod_pubsub:itemId().
uniqid() ->
{T1, T2, T3} = p1_time_compat:timestamp(),
iolist_to_binary(io_lib:fwrite("~.16B~.16B~.16B", [T1, T2, T3])).
(str:format("~.16B~.16B~.16B", [T1, T2, T3])).
-spec itemsEls([#pubsub_item{}]) -> [ps_item()].
itemsEls(Items) ->

View File

@ -392,7 +392,7 @@ send_registration_notifications(Mod, UJID, Source) ->
[] -> ok;
JIDs when is_list(JIDs) ->
Body =
iolist_to_binary(io_lib:format("[~s] The account ~s was registered from "
(str:format("[~s] The account ~s was registered from "
"IP address ~s on node ~w using ~p.",
[get_time_string(),
jid:to_string(UJID),

View File

@ -299,7 +299,7 @@ add_record_route_and_set_uri(URI, LServer, #sip{hdrs = Hdrs} = Req) ->
case need_record_route(LServer) of
true ->
RR_URI = get_configured_record_route(LServer),
TS = list_to_binary(integer_to_list(p1_time_compat:system_time(seconds))),
TS = (integer_to_binary(p1_time_compat:system_time(seconds))),
Sign = make_sign(TS, Hdrs),
User = <<TS/binary, $-, Sign/binary>>,
NewRR_URI = RR_URI#uri{user = User},
@ -339,7 +339,7 @@ make_sign(TS, Hdrs) ->
is_signed_by_me(TS_Sign, Hdrs) ->
try
[TSBin, Sign] = str:tokens(TS_Sign, <<"-">>),
TS = list_to_integer(binary_to_list(TSBin)),
TS = (binary_to_integer(TSBin)),
NowTS = p1_time_compat:system_time(seconds),
true = (NowTS - TS) =< ?SIGN_LIFETIME,
Sign == make_sign(TSBin, Hdrs)

View File

@ -355,7 +355,7 @@ min_expires() ->
60.
to_integer(Bin, Min, Max) ->
case catch list_to_integer(binary_to_list(Bin)) of
case catch (binary_to_integer(Bin)) of
N when N >= Min, N =< Max ->
{ok, N};
_ ->

View File

@ -111,7 +111,7 @@ get_local_stat(Server, [], Name)
{'EXIT', _Reason} ->
?STATERR(500, <<"Internal Server Error">>);
Users ->
?STATVAL((iolist_to_binary(integer_to_list(length(Users)))),
?STATVAL((integer_to_binary(length(Users))),
<<"users">>)
end;
get_local_stat(Server, [], Name)
@ -122,13 +122,13 @@ get_local_stat(Server, [], Name)
{'EXIT', _Reason} ->
?STATERR(500, <<"Internal Server Error">>);
NUsers ->
?STATVAL((iolist_to_binary(integer_to_list(NUsers))),
?STATVAL((integer_to_binary(NUsers)),
<<"users">>)
end;
get_local_stat(_Server, [], Name)
when Name == <<"users/all-hosts/online">> ->
Users = ejabberd_sm:connected_users_number(),
?STATVAL((iolist_to_binary(integer_to_list(Users))), <<"users">>);
?STATVAL((integer_to_binary(Users)), <<"users">>);
get_local_stat(_Server, [], Name)
when Name == <<"users/all-hosts/total">> ->
NumUsers = lists:foldl(fun (Host, Total) ->
@ -136,7 +136,7 @@ get_local_stat(_Server, [], Name)
+ Total
end,
0, ?MYHOSTS),
?STATVAL((iolist_to_binary(integer_to_list(NumUsers))),
?STATVAL((integer_to_binary(NumUsers)),
<<"users">>);
get_local_stat(_Server, _, Name) ->
?STATERR(404, <<"Not Found">>).
@ -149,9 +149,7 @@ get_node_stat(Node, Name)
{badrpc, _Reason} ->
?STATERR(500, <<"Internal Server Error">>);
CPUTime ->
?STATVAL(list_to_binary(
io_lib:format("~.3f",
[element(1, CPUTime) / 1000])),
?STATVAL(str:format("~.3f", [element(1, CPUTime) / 1000]),
<<"seconds">>)
end;
get_node_stat(Node, Name)
@ -161,9 +159,7 @@ get_node_stat(Node, Name)
{badrpc, _Reason} ->
?STATERR(500, <<"Internal Server Error">>);
RunTime ->
?STATVAL(list_to_binary(
io_lib:format("~.3f",
[element(1, RunTime) / 1000])),
?STATVAL(str:format("~.3f", [element(1, RunTime) / 1000]),
<<"seconds">>)
end;
get_node_stat(Node, Name)
@ -174,7 +170,7 @@ get_node_stat(Node, Name)
{badrpc, _Reason} ->
?STATERR(500, <<"Internal Server Error">>);
Users ->
?STATVAL((iolist_to_binary(integer_to_list(length(Users)))),
?STATVAL((integer_to_binary(length(Users))),
<<"users">>)
end;
get_node_stat(Node, Name)
@ -185,7 +181,7 @@ get_node_stat(Node, Name)
{badrpc, _Reason} ->
?STATERR(500, <<"Internal Server Error">>);
Transactions ->
?STATVAL((iolist_to_binary(integer_to_list(Transactions))),
?STATVAL((integer_to_binary(Transactions)),
<<"transactions">>)
end;
get_node_stat(Node, Name)
@ -196,7 +192,7 @@ get_node_stat(Node, Name)
{badrpc, _Reason} ->
?STATERR(500, <<"Internal Server Error">>);
Transactions ->
?STATVAL((iolist_to_binary(integer_to_list(Transactions))),
?STATVAL((integer_to_binary(Transactions)),
<<"transactions">>)
end;
get_node_stat(Node, Name)
@ -207,7 +203,7 @@ get_node_stat(Node, Name)
{badrpc, _Reason} ->
?STATERR(500, <<"Internal Server Error">>);
Transactions ->
?STATVAL((iolist_to_binary(integer_to_list(Transactions))),
?STATVAL((integer_to_binary(Transactions)),
<<"transactions">>)
end;
get_node_stat(Node, Name)
@ -218,7 +214,7 @@ get_node_stat(Node, Name)
{badrpc, _Reason} ->
?STATERR(500, <<"Internal Server Error">>);
Transactions ->
?STATVAL((iolist_to_binary(integer_to_list(Transactions))),
?STATVAL((integer_to_binary(Transactions)),
<<"transactions">>)
end;
get_node_stat(_, Name) ->

View File

@ -70,7 +70,7 @@ get_os() ->
OSType = list_to_binary([atom_to_list(Osfamily), $/, atom_to_list(Osname)]),
OSVersion = case os:version() of
{Major, Minor, Release} ->
iolist_to_binary(io_lib:format("~w.~w.~w",
(str:format("~w.~w.~w",
[Major, Minor, Release]));
VersionString -> VersionString
end,

View File

@ -127,7 +127,7 @@ subscription_opt_to_sql({subscription_depth, Depth}) ->
N -> integer_to_sql(N)
end}.
integer_to_sql(N) -> iolist_to_binary(integer_to_list(N)).
integer_to_sql(N) -> integer_to_binary(N).
boolean_to_sql(true) -> <<"1">>;
boolean_to_sql(false) -> <<"0">>.

View File

@ -170,7 +170,7 @@ write_subscription(_JID, _NodeId, SubID, Options) ->
-spec make_subid() -> SubId::mod_pubsub:subId().
make_subid() ->
{T1, T2, T3} = p1_time_compat:timestamp(),
iolist_to_binary(io_lib:fwrite("~.16B~.16B~.16B", [T1, T2, T3])).
(str:format("~.16B~.16B~.16B", [T1, T2, T3])).
%%
%% Subscription XForm processing.
@ -207,14 +207,14 @@ val_xfield(digest_frequency = Opt, [Val]) ->
N when is_integer(N) -> N;
_ ->
Txt = <<"Value of '~s' should be integer">>,
ErrTxt = iolist_to_binary(io_lib:format(Txt, [Opt])),
ErrTxt = (str:format(Txt, [Opt])),
{error, xmpp:err_not_acceptable(ErrTxt, ?MYLANG)}
end;
val_xfield(expire = Opt, [Val]) ->
try xmpp_util:decode_timestamp(Val)
catch _:{bad_timestamp, _} ->
Txt = <<"Value of '~s' should be datetime string">>,
ErrTxt = iolist_to_binary(io_lib:format(Txt, [Opt])),
ErrTxt = (str:format(Txt, [Opt])),
{error, xmpp:err_not_acceptable(ErrTxt, ?MYLANG)}
end;
val_xfield(include_body = Opt, [Val]) -> xopt_to_bool(Opt, Val);
@ -227,7 +227,7 @@ val_xfield(subscription_depth = Opt, [Depth]) ->
N when is_integer(N) -> N;
_ ->
Txt = <<"Value of '~s' should be integer">>,
ErrTxt = iolist_to_binary(io_lib:format(Txt, [Opt])),
ErrTxt = (str:format(Txt, [Opt])),
{error, xmpp:err_not_acceptable(ErrTxt, ?MYLANG)}
end.
@ -238,7 +238,7 @@ xopt_to_bool(_, <<"false">>) -> false;
xopt_to_bool(_, <<"true">>) -> true;
xopt_to_bool(Option, _) ->
Txt = <<"Value of '~s' should be boolean">>,
ErrTxt = iolist_to_binary(io_lib:format(Txt, [Option])),
ErrTxt = (str:format(Txt, [Option])),
{error, xmpp:err_not_acceptable(ErrTxt, ?MYLANG)}.
%% Return a field for an XForm for Key, with data filled in, if
@ -311,7 +311,7 @@ xfield_label(subscription_depth) -> ?SUBSCRIPTION_DEPTH_LABEL.
xfield_val(deliver, Val) -> [bool_to_xopt(Val)];
%xfield_val(digest, Val) -> [bool_to_xopt(Val)];
%xfield_val(digest_frequency, Val) ->
% [iolist_to_binary(integer_to_list(Val))];
% [integer_to_binary(Val))];
%xfield_val(expire, Val) ->
% [jlib:now_to_utc_string(Val)];
%xfield_val(include_body, Val) -> [bool_to_xopt(Val)];
@ -320,7 +320,7 @@ xfield_val(subscription_type, items) -> [<<"items">>];
xfield_val(subscription_type, nodes) -> [<<"nodes">>];
xfield_val(subscription_depth, all) -> [<<"all">>];
xfield_val(subscription_depth, N) ->
[iolist_to_binary(integer_to_list(N))].
[integer_to_binary(N)].
bool_to_xopt(true) -> <<"true">>;

View File

@ -135,7 +135,7 @@ create_table() -> ok.
-spec make_subid() -> mod_pubsub:subId().
make_subid() ->
{T1, T2, T3} = p1_time_compat:timestamp(),
iolist_to_binary(io_lib:fwrite("~.16B~.16B~.16B", [T1, T2, T3])).
(str:format("~.16B~.16B~.16B", [T1, T2, T3])).
%%
%% Subscription XForm processing.
@ -172,14 +172,14 @@ val_xfield(digest_frequency = Opt, [Val]) ->
N when is_integer(N) -> N;
_ ->
Txt = <<"Value of '~s' should be integer">>,
ErrTxt = iolist_to_binary(io_lib:format(Txt, [Opt])),
ErrTxt = (str:format(Txt, [Opt])),
{error, xmpp:err_not_acceptable(ErrTxt, ?MYLANG)}
end;
val_xfield(expire = Opt, [Val]) ->
try xmpp_util:decode_timestamp(Val)
catch _:{bad_timestamp, _} ->
Txt = <<"Value of '~s' should be datetime string">>,
ErrTxt = iolist_to_binary(io_lib:format(Txt, [Opt])),
ErrTxt = (str:format(Txt, [Opt])),
{error, xmpp:err_not_acceptable(ErrTxt, ?MYLANG)}
end;
val_xfield(include_body = Opt, [Val]) -> xopt_to_bool(Opt, Val);
@ -192,7 +192,7 @@ val_xfield(subscription_depth = Opt, [Depth]) ->
N when is_integer(N) -> N;
_ ->
Txt = <<"Value of '~s' should be integer">>,
ErrTxt = iolist_to_binary(io_lib:format(Txt, [Opt])),
ErrTxt = (str:format(Txt, [Opt])),
{error, xmpp:err_not_acceptable(ErrTxt, ?MYLANG)}
end.
@ -203,7 +203,7 @@ xopt_to_bool(_, <<"false">>) -> false;
xopt_to_bool(_, <<"true">>) -> true;
xopt_to_bool(Option, _) ->
Txt = <<"Value of '~s' should be boolean">>,
ErrTxt = iolist_to_binary(io_lib:format(Txt, [Option])),
ErrTxt = (str:format(Txt, [Option])),
{error, xmpp:err_not_acceptable(ErrTxt, ?MYLANG)}.
%% Return a field for an XForm for Key, with data filled in, if
@ -276,7 +276,7 @@ xfield_label(subscription_depth) -> ?SUBSCRIPTION_DEPTH_LABEL.
xfield_val(deliver, Val) -> [bool_to_xopt(Val)];
%xfield_val(digest, Val) -> [bool_to_xopt(Val)];
%xfield_val(digest_frequency, Val) ->
% [iolist_to_binary(integer_to_list(Val))];
% [integer_to_binary(Val))];
%xfield_val(expire, Val) ->
% [jlib:now_to_utc_string(Val)];
%xfield_val(include_body, Val) -> [bool_to_xopt(Val)];
@ -285,7 +285,7 @@ xfield_val(subscription_type, items) -> [<<"items">>];
xfield_val(subscription_type, nodes) -> [<<"nodes">>];
xfield_val(subscription_depth, all) -> [<<"all">>];
xfield_val(subscription_depth, N) ->
[iolist_to_binary(integer_to_list(N))].
[integer_to_binary(N)].
bool_to_xopt(false) -> <<"false">>;
bool_to_xopt(true) -> <<"true">>.