+2008-03-21 Badlop <badlop@process-one.net>
+
+ * src/cyrsasl_digest.erl: Rewrite io:format calls to loglevel
+ macros (EJAB-555)
+ * src/ejabberd_auth.erl: Likewise
+ * src/ejabberd_ctl.erl: Likewise
+ * src/ejabberd_loglevel.erl: Likewise
+ * src/ejabberd_s2s.erl: Likewise
+ * src/ejabberd_sm.erl: Likewise
+ * src/ejabberd_update.erl: Likewise
+ * src/extauth.erl: Likewise
+ * src/mod_irc/mod_irc.erl: Likewise
+ * src/shaper.erl: Likewise
+ * src/tls/tls.erl: Likewise
+ * src/web/ejabberd_http_poll.erl: Likewise
+
+ * src/ejabberd.hrl: New macro ?PRINT(Format, Args) to print in
+ standard output
+
2008-03-20 Badlop <badlop@process-one.net>
* doc/guide.tex: Improve explanation of how to start ejabberd when
mech_new/3,
mech_step/2]).
+-include("ejabberd.hrl").
+
-behaviour(cyrsasl).
-record(state, {step, nonce, username, authzid, get_password}).
authzid = AuthzId}, "") ->
{ok, [{username, UserName}, {authzid, AuthzId}]};
mech_step(A, B) ->
- io:format("SASL DIGEST: A ~p B ~p", [A,B]),
+ ?DEBUG("SASL DIGEST: A ~p B ~p", [A,B]),
{error, "bad-protocol"}.
%% ---------------------------------
%% Logging mechanism
+%% Print in standard output
+-define(PRINT(Format, Args),
+ io:format(Format, Args)).
+
-define(DEBUG(Format, Args),
ejabberd_logger:debug_msg(?MODULE,?LINE,Format, Args)).
NewLine = io_lib:format("~n", []),
SUsers = lists:sort(Users),
FUsers = lists:map(fun({U, _S}) -> [U, NewLine] end, SUsers),
- io:format("~s", [FUsers]),
+ ?PRINT("~s", [FUsers]),
{stop, ?STATUS_SUCCESS};
ctl_process_get_registered(Val, _Host, _Args) ->
Val.
Node = list_to_atom(SNode1),
Status = case rpc:call(Node, ?MODULE, process, [Args]) of
{badrpc, Reason} ->
- io:format("RPC failed on the node ~p: ~p~n",
+ ?PRINT("RPC failed on the node ~p: ~p~n",
[Node, Reason]),
?STATUS_BADRPC;
S ->
process(["status"]) ->
{InternalStatus, ProvidedStatus} = init:get_status(),
- io:format("Node ~p is ~p. Status: ~p~n",
+ ?PRINT("Node ~p is ~p. Status: ~p~n",
[node(), InternalStatus, ProvidedStatus]),
case lists:keysearch(ejabberd, 1, application:which_applications()) of
false ->
- io:format("ejabberd is not running~n", []),
+ ?PRINT("ejabberd is not running~n", []),
?STATUS_ERROR;
{value,_Version} ->
- io:format("ejabberd is running~n", []),
+ ?PRINT("ejabberd is running~n", []),
?STATUS_SUCCESS
end;
{atomic, ok} ->
?STATUS_SUCCESS;
{atomic, exists} ->
- io:format("User ~p already registered at node ~p~n",
+ ?PRINT("User ~p already registered at node ~p~n",
[User ++ "@" ++ Server, node()]),
?STATUS_ERROR;
{error, Reason} ->
- io:format("Can't register user ~p at node ~p: ~p~n",
+ ?PRINT("Can't register user ~p at node ~p: ~p~n",
[User ++ "@" ++ Server, node(), Reason]),
?STATUS_ERROR
end;
process(["unregister", User, Server]) ->
case ejabberd_auth:remove_user(User, Server) of
{error, Reason} ->
- io:format("Can't unregister user ~p at node ~p: ~p~n",
+ ?PRINT("Can't unregister user ~p at node ~p: ~p~n",
[User ++ "@" ++ Server, node(), Reason]),
?STATUS_ERROR;
_ ->
ok ->
?STATUS_SUCCESS;
{error, Reason} ->
- io:format("Can't store backup in ~p at node ~p: ~p~n",
+ ?PRINT("Can't store backup in ~p at node ~p: ~p~n",
[filename:absname(Path), node(), Reason]),
?STATUS_ERROR
end;
ok ->
?STATUS_SUCCESS;
{error, Reason} ->
- io:format("Can't store dump in ~p at node ~p: ~p~n",
+ ?PRINT("Can't store dump in ~p at node ~p: ~p~n",
[filename:absname(Path), node(), Reason]),
?STATUS_ERROR
end;
{atomic, ok} ->
?STATUS_SUCCESS;
{error, Reason} ->
- io:format("Can't load dump in ~p at node ~p: ~p~n",
+ ?PRINT("Can't load dump in ~p at node ~p: ~p~n",
[filename:absname(Path), node(), Reason]),
?STATUS_ERROR
end;
{atomic, _} ->
?STATUS_SUCCESS;
{error, Reason} ->
- io:format("Can't restore backup from ~p at node ~p: ~p~n",
+ ?PRINT("Can't restore backup from ~p at node ~p: ~p~n",
[filename:absname(Path), node(), Reason]),
?STATUS_ERROR;
{aborted,{no_exists,Table}} ->
- io:format("Can't restore backup from ~p at node ~p: Table ~p does not exist.~n",
+ ?PRINT("Can't restore backup from ~p at node ~p: Table ~p does not exist.~n",
[filename:absname(Path), node(), Table]),
?STATUS_ERROR;
{aborted,enoent} ->
- io:format("Can't restore backup from ~p at node ~p: File not found.~n",
+ ?PRINT("Can't restore backup from ~p at node ~p: File not found.~n",
[filename:absname(Path), node()]),
?STATUS_ERROR
end;
ok ->
?STATUS_SUCCESS;
{error, Reason} ->
- io:format("Can't install fallback from ~p at node ~p: ~p~n",
+ ?PRINT("Can't install fallback from ~p at node ~p: ~p~n",
[filename:absname(Path), node(), Reason]),
?STATUS_ERROR
end;
ok ->
?STATUS_SUCCESS;
{error, Reason} ->
- io:format("Can't import jabberd 1.4 spool file ~p at node ~p: ~p~n",
+ ?PRINT("Can't import jabberd 1.4 spool file ~p at node ~p: ~p~n",
[filename:absname(Path), node(), Reason]),
?STATUS_ERROR
end;
ok ->
?STATUS_SUCCESS;
{error, Reason} ->
- io:format("Can't import jabberd 1.4 spool dir ~p at node ~p: ~p~n",
+ ?PRINT("Can't import jabberd 1.4 spool dir ~p at node ~p: ~p~n",
[filename:absname(Path), node(), Reason]),
?STATUS_ERROR
end;
?STATUS_SUCCESS;
process(["mnesia"]) ->
- io:format("~p~n", [mnesia:system_info(all)]),
+ ?PRINT("~p~n", [mnesia:system_info(all)]),
?STATUS_SUCCESS;
process(["mnesia", "info"]) ->
process(["mnesia", Arg]) when is_list(Arg) ->
case catch mnesia:system_info(list_to_atom(Arg)) of
- {'EXIT', Error} -> io:format("Error: ~p~n", [Error]);
- Return -> io:format("~p~n", [Return])
+ {'EXIT', Error} -> ?PRINT("Error: ~p~n", [Error]);
+ Return -> ?PRINT("~p~n", [Return])
end,
?STATUS_SUCCESS;
process(["delete-old-messages", Days]) ->
case catch list_to_integer(Days) of
{'EXIT',{Reason, _Stack}} ->
- io:format("Can't delete old messages (~p). Please pass an integer as parameter.~n",
+ ?PRINT("Can't delete old messages (~p). Please pass an integer as parameter.~n",
[Reason]),
?STATUS_ERROR;
Integer when Integer >= 0 ->
{atomic, _} = mod_offline:remove_old_messages(Integer),
- io:format("Removed messages older than ~s days~n", [Days]),
+ ?PRINT("Removed messages older than ~s days~n", [Days]),
?STATUS_SUCCESS;
_Integer ->
- io:format("Can't delete old messages. Please pass a positive integer as parameter.~n", []),
+ ?PRINT("Can't delete old messages. Please pass a positive integer as parameter.~n", []),
?STATUS_ERROR
end;
process(["vhost", H | Args]) ->
case jlib:nameprep(H) of
false ->
- io:format("Bad hostname: ~p~n", [H]),
+ ?PRINT("Bad hostname: ~p~n", [H]),
?STATUS_ERROR;
Host ->
case ejabberd_hooks:run_fold(
[" ", Cmd, string:chars($\s, MaxCmdLen - length(Cmd) + 2),
Desc, NewLine]
end, CmdDescs),
- io:format(
+ ?PRINT(
"Usage: ejabberdctl [--node nodename] command [options]~n"
"~n"
"Available commands in this ejabberd node:~n"
"Examples:~n"
" ejabberdctl restart~n"
" ejabberdctl --node ejabberd@host restart~n"
- " ejabberdctl vhost jabber.example.org ...~n"
- ).
+ " ejabberdctl vhost jabber.example.org ...~n",
+ []).
print_vhost_usage(Host) ->
CmdDescs =
[" ", Cmd, string:chars($\s, MaxCmdLen - length(Cmd) + 2),
Desc, NewLine]
end, CmdDescs),
- io:format(
+ ?PRINT(
"Usage: ejabberdctl [--node nodename] vhost hostname command [options]~n"
"~n"
"Available commands in this ejabberd node and this vhost:~n"
++ FmtCmdDescs ++
"~n"
"Examples:~n"
- " ejabberdctl vhost "++Host++" registered-users~n"
- ).
+ " ejabberdctl vhost "++Host++" registered-users~n",
+ []).
register_commands(CmdDescs, Module, Function) ->
ets:insert(ejabberd_ctl_cmds, CmdDescs),
-export([set/1]).
+-include("ejabberd.hrl").
+
-define(LOGMODULE, "error_logger").
%% Error levels:
{ok, M, Bin} ->
code:load_binary(M, Fname, Bin);
Error ->
- io:format("Error ~p~n", [Error])
+ ?CRITICAL_MSG("Error ~p~n", [Error])
end.
%% --------------------------------------------------------------
ctl_process(_Val, ["incoming-s2s-number"]) ->
N = length(supervisor:which_children(ejabberd_s2s_in_sup)),
- io:format("~p~n", [N]),
+ ?PRINT("~p~n", [N]),
{stop, ?STATUS_SUCCESS};
ctl_process(_Val, ["outgoing-s2s-number"]) ->
N = length(supervisor:which_children(ejabberd_s2s_out_sup)),
- io:format("~p~n", [N]),
+ ?PRINT("~p~n", [N]),
{stop, ?STATUS_SUCCESS};
ctl_process(Val, _Args) ->
Val.
NewLine = io_lib:format("~n", []),
SUSRs = lists:sort(USRs),
FUSRs = lists:map(fun({U, S, R}) -> [U, $@, S, $/, R, NewLine] end, SUSRs),
- io:format("~s", [FUSRs]),
+ ?PRINT("~s", [FUSRs]),
{stop, ?STATUS_SUCCESS};
ctl_process(_Val, ["connected-users-number"]) ->
N = length(dirty_get_sessions_list()),
- io:format("~p~n", [N]),
+ ?PRINT("~p~n", [N]),
{stop, ?STATUS_SUCCESS};
ctl_process(_Val, ["user-resources", User, Server]) ->
Resources = get_user_resources(User, Server),
NewLine = io_lib:format("~n", []),
SResources = lists:sort(Resources),
FResources = lists:map(fun(R) -> [R, NewLine] end, SResources),
- io:format("~s", [FResources]),
+ ?PRINT("~s", [FResources]),
{stop, ?STATUS_SUCCESS};
ctl_process(Val, _Args) ->
Val.
%% API
-export([update/0, update_info/0]).
+-include("ejabberd.hrl").
+
%%====================================================================
%% API
%%====================================================================
release_handler_1:eval_script(
LowLevelScript, [],
[{ejabberd, "", filename:join(Dir, "..")}]),
- io:format("eval: ~p~n", [Eval]),
+ ?INFO_MSG("eval: ~p~n", [Eval]),
Eval;
{error, Reason} ->
{error, Reason}
false
end
end, Beams),
- io:format("beam files: ~p~n", [UpdatedBeams]),
+ ?INFO_MSG("beam files: ~p~n", [UpdatedBeams]),
Script = make_script(UpdatedBeams),
- io:format("script: ~p~n", [Script]),
+ ?INFO_MSG("script: ~p~n", [Script]),
LowLevelScript = make_low_level_script(UpdatedBeams, Script),
- io:format("low level script: ~p~n", [LowLevelScript]),
+ ?INFO_MSG("low level script: ~p~n", [LowLevelScript]),
Check =
release_handler_1:check_script(
LowLevelScript,
[{ejabberd, "", filename:join(Dir, "..")}]),
- io:format("check: ~p~n", [Check]),
+ ?INFO_MSG("check: ~p~n", [Check]),
{ok, Dir, UpdatedBeams, Script, LowLevelScript, Check};
{error, Reason} ->
{error, Reason}
-export([start/2, stop/1, init/2,
check_password/3, set_password/3, is_user_exists/2]).
+-include("ejabberd.hrl").
start(Host, ExtPrg) ->
spawn(?MODULE, init, [Host, ExtPrg]).
exit(normal)
end;
{'EXIT', Port, Reason} ->
- io:format("~p ~n", [Reason]),
+ ?CRITICAL_MSG("~p ~n", [Reason]),
exit(port_terminated)
end.
[[_ | _] = Channel, [_ | _] = Server] ->
case ets:lookup(irc_connection, {From, Server, Host}) of
[] ->
- io:format("open new connection~n"),
+ ?DEBUG("open new connection~n", []),
{Username, Encoding} = get_user_and_encoding(
Host, From, Server, DefEnc),
{ok, Pid} = mod_irc_connection:start(
ok;
[R] ->
Pid = R#irc_connection.pid,
- io:format("send to process ~p~n",
+ ?DEBUG("send to process ~p~n",
[Pid]),
mod_irc_connection:route_chan(
Pid, Channel, Resource, Packet),
ejabberd_router:route(To, From, Err);
[R] ->
Pid = R#irc_connection.pid,
- io:format("send to process ~p~n",
+ ?DEBUG("send to process ~p~n",
[Pid]),
mod_irc_connection:route_nick(
Pid, Nick, Packet),
-export([new/1, new1/1, update/2]).
+-include("ejabberd.hrl").
+
-record(maxrate, {maxrate, lastrate, lasttime}).
MinInterv = 1000 * Size /
(2 * State#maxrate.maxrate - State#maxrate.lastrate),
Interv = (now_to_usec(now()) - State#maxrate.lasttime) / 1000,
- %io:format("State: ~p, Size=~p~nM=~p, I=~p~n",
- % [State, Size, MinInterv, Interv]),
+ ?INFO_MSG("State: ~p, Size=~p~nM=~p, I=~p~n",
+ [State, Size, MinInterv, Interv]),
Pause = if
MinInterv > Interv ->
1 + trunc(MinInterv - Interv);
code_change/3,
terminate/2]).
+-include("ejabberd.hrl").
+
-define(SET_CERTIFICATE_FILE_ACCEPT, 1).
-define(SET_CERTIFICATE_FILE_CONNECT, 2).
-define(SET_ENCRYPTED_INPUT, 3).
<<0, Out/binary>> ->
case gen_tcp:send(TCPSocket, Out) of
ok ->
- %io:format("IN: ~p~n", [{TCPSocket, binary_to_list(In)}]),
+ %?PRINT("IN: ~p~n", [{TCPSocket, binary_to_list(In)}]),
{ok, In};
Error ->
Error
send(#tlssock{tcpsock = TCPSocket, tlsport = Port}, Packet) ->
case port_control(Port, ?SET_DECRYPTED_OUTPUT, Packet) of
<<0>> ->
- %io:format("OUT: ~p~n", [{TCPSocket, lists:flatten(Packet)}]),
+ %?PRINT("OUT: ~p~n", [{TCPSocket, lists:flatten(Packet)}]),
case port_control(Port, ?GET_ENCRYPTED_OUTPUT, []) of
<<0, Out/binary>> ->
gen_tcp:send(TCPSocket, Out);
{error, already_loaded} -> ok
end,
Port = open_port({spawn, tls_drv}, [binary]),
- io:format("open_port: ~p~n", [Port]),
+ ?PRINT("open_port: ~p~n", [Port]),
PCRes = port_control(Port, ?SET_CERTIFICATE_FILE_ACCEPT,
"./ssl.pem" ++ [0]),
- io:format("port_control: ~p~n", [PCRes]),
+ ?PRINT("port_control: ~p~n", [PCRes]),
{ok, ListenSocket} = gen_tcp:listen(1234, [binary,
{packet, 0},
{active, true},
{reuseaddr, true},
{nodelay, true}]),
- io:format("listen: ~p~n", [ListenSocket]),
+ ?PRINT("listen: ~p~n", [ListenSocket]),
{ok, Socket} = gen_tcp:accept(ListenSocket),
- io:format("accept: ~p~n", [Socket]),
+ ?PRINT("accept: ~p~n", [Socket]),
loop(Port, Socket).
loop(Port, Socket) ->
receive
{tcp, Socket, Data} ->
- %io:format("read: ~p~n", [Data]),
+ %?PRINT("read: ~p~n", [Data]),
Res = port_control(Port, ?SET_ENCRYPTED_INPUT, Data),
- io:format("SET_ENCRYPTED_INPUT: ~p~n", [Res]),
+ ?PRINT("SET_ENCRYPTED_INPUT: ~p~n", [Res]),
DIRes = port_control(Port, ?GET_DECRYPTED_INPUT, Data),
- io:format("GET_DECRYPTED_INPUT: ~p~n", [DIRes]),
+ ?PRINT("GET_DECRYPTED_INPUT: ~p~n", [DIRes]),
case DIRes of
<<0, In/binary>> ->
- io:format("input: ~s~n", [binary_to_list(In)]);
+ ?PRINT("input: ~s~n", [binary_to_list(In)]);
<<1, DIError/binary>> ->
- io:format("GET_DECRYPTED_INPUT error: ~p~n", [binary_to_list(DIError)])
+ ?PRINT("GET_DECRYPTED_INPUT error: ~p~n", [binary_to_list(DIError)])
end,
EORes = port_control(Port, ?GET_ENCRYPTED_OUTPUT, Data),
- io:format("GET_ENCRYPTED_OUTPUT: ~p~n", [EORes]),
+ ?PRINT("GET_ENCRYPTED_OUTPUT: ~p~n", [EORes]),
case EORes of
<<0, Out/binary>> ->
gen_tcp:send(Socket, Out);
<<1, EOError/binary>> ->
- io:format("GET_ENCRYPTED_OUTPUT error: ~p~n", [binary_to_list(EOError)])
+ ?PRINT("GET_ENCRYPTED_OUTPUT error: ~p~n", [binary_to_list(EOError)])
end,
loop(Port, Socket);
Msg ->
- io:format("receive: ~p~n", [Msg]),
+ ?PRINT("receive: ~p~n", [Msg]),
loop(Port, Socket)
end.
ParsedPacket = xml_stream:parse_element(Packet),
From = get_jid("from", ParsedPacket),
To = get_jid("to", ParsedPacket),
- io:format("MREMOND: Resend ~p ~p ~p~n",[From,To, ParsedPacket]),
+ ?DEBUG("Resend ~p ~p ~p~n",[From,To, ParsedPacket]),
ejabberd_router:route(From, To, ParsedPacket).
%% Type can be "from" or "to"