Rewrite io:format calls to loglevel macros (EJAB-555)

SVN Revision: 1239
This commit is contained in:
Christophe Romain 2008-03-21 14:44:16 +00:00
parent 694baba127
commit b2bd9759c8
14 changed files with 97 additions and 63 deletions

View File

@ -1,3 +1,22 @@
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> 2008-03-20 Badlop <badlop@process-one.net>
* doc/guide.tex: Improve explanation of how to start ejabberd when * doc/guide.tex: Improve explanation of how to start ejabberd when

View File

@ -14,6 +14,8 @@
mech_new/3, mech_new/3,
mech_step/2]). mech_step/2]).
-include("ejabberd.hrl").
-behaviour(cyrsasl). -behaviour(cyrsasl).
-record(state, {step, nonce, username, authzid, get_password}). -record(state, {step, nonce, username, authzid, get_password}).
@ -67,7 +69,7 @@ mech_step(#state{step = 5,
authzid = AuthzId}, "") -> authzid = AuthzId}, "") ->
{ok, [{username, UserName}, {authzid, AuthzId}]}; {ok, [{username, UserName}, {authzid, AuthzId}]};
mech_step(A, B) -> 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"}. {error, "bad-protocol"}.

View File

@ -38,6 +38,10 @@
%% --------------------------------- %% ---------------------------------
%% Logging mechanism %% Logging mechanism
%% Print in standard output
-define(PRINT(Format, Args),
io:format(Format, Args)).
-define(DEBUG(Format, Args), -define(DEBUG(Format, Args),
ejabberd_logger:debug_msg(?MODULE,?LINE,Format, Args)). ejabberd_logger:debug_msg(?MODULE,?LINE,Format, Args)).

View File

@ -212,7 +212,7 @@ ctl_process_get_registered(_Val, Host, ["registered-users"]) ->
NewLine = io_lib:format("~n", []), NewLine = io_lib:format("~n", []),
SUsers = lists:sort(Users), SUsers = lists:sort(Users),
FUsers = lists:map(fun({U, _S}) -> [U, NewLine] end, SUsers), FUsers = lists:map(fun({U, _S}) -> [U, NewLine] end, SUsers),
io:format("~s", [FUsers]), ?PRINT("~s", [FUsers]),
{stop, ?STATUS_SUCCESS}; {stop, ?STATUS_SUCCESS};
ctl_process_get_registered(Val, _Host, _Args) -> ctl_process_get_registered(Val, _Host, _Args) ->
Val. Val.

View File

@ -58,7 +58,7 @@ start() ->
Node = list_to_atom(SNode1), Node = list_to_atom(SNode1),
Status = case rpc:call(Node, ?MODULE, process, [Args]) of Status = case rpc:call(Node, ?MODULE, process, [Args]) of
{badrpc, Reason} -> {badrpc, Reason} ->
io:format("RPC failed on the node ~p: ~p~n", ?PRINT("RPC failed on the node ~p: ~p~n",
[Node, Reason]), [Node, Reason]),
?STATUS_BADRPC; ?STATUS_BADRPC;
S -> S ->
@ -77,14 +77,14 @@ init() ->
process(["status"]) -> process(["status"]) ->
{InternalStatus, ProvidedStatus} = init:get_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]), [node(), InternalStatus, ProvidedStatus]),
case lists:keysearch(ejabberd, 1, application:which_applications()) of case lists:keysearch(ejabberd, 1, application:which_applications()) of
false -> false ->
io:format("ejabberd is not running~n", []), ?PRINT("ejabberd is not running~n", []),
?STATUS_ERROR; ?STATUS_ERROR;
{value,_Version} -> {value,_Version} ->
io:format("ejabberd is running~n", []), ?PRINT("ejabberd is running~n", []),
?STATUS_SUCCESS ?STATUS_SUCCESS
end; end;
@ -107,11 +107,11 @@ process(["register", User, Server, Password]) ->
{atomic, ok} -> {atomic, ok} ->
?STATUS_SUCCESS; ?STATUS_SUCCESS;
{atomic, exists} -> {atomic, exists} ->
io:format("User ~p already registered at node ~p~n", ?PRINT("User ~p already registered at node ~p~n",
[User ++ "@" ++ Server, node()]), [User ++ "@" ++ Server, node()]),
?STATUS_ERROR; ?STATUS_ERROR;
{error, Reason} -> {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]), [User ++ "@" ++ Server, node(), Reason]),
?STATUS_ERROR ?STATUS_ERROR
end; end;
@ -119,7 +119,7 @@ process(["register", User, Server, Password]) ->
process(["unregister", User, Server]) -> process(["unregister", User, Server]) ->
case ejabberd_auth:remove_user(User, Server) of case ejabberd_auth:remove_user(User, Server) of
{error, Reason} -> {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]), [User ++ "@" ++ Server, node(), Reason]),
?STATUS_ERROR; ?STATUS_ERROR;
_ -> _ ->
@ -131,7 +131,7 @@ process(["backup", Path]) ->
ok -> ok ->
?STATUS_SUCCESS; ?STATUS_SUCCESS;
{error, Reason} -> {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]), [filename:absname(Path), node(), Reason]),
?STATUS_ERROR ?STATUS_ERROR
end; end;
@ -141,7 +141,7 @@ process(["dump", Path]) ->
ok -> ok ->
?STATUS_SUCCESS; ?STATUS_SUCCESS;
{error, Reason} -> {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]), [filename:absname(Path), node(), Reason]),
?STATUS_ERROR ?STATUS_ERROR
end; end;
@ -151,7 +151,7 @@ process(["load", Path]) ->
{atomic, ok} -> {atomic, ok} ->
?STATUS_SUCCESS; ?STATUS_SUCCESS;
{error, Reason} -> {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]), [filename:absname(Path), node(), Reason]),
?STATUS_ERROR ?STATUS_ERROR
end; end;
@ -161,15 +161,15 @@ process(["restore", Path]) ->
{atomic, _} -> {atomic, _} ->
?STATUS_SUCCESS; ?STATUS_SUCCESS;
{error, Reason} -> {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]), [filename:absname(Path), node(), Reason]),
?STATUS_ERROR; ?STATUS_ERROR;
{aborted,{no_exists,Table}} -> {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]), [filename:absname(Path), node(), Table]),
?STATUS_ERROR; ?STATUS_ERROR;
{aborted,enoent} -> {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()]), [filename:absname(Path), node()]),
?STATUS_ERROR ?STATUS_ERROR
end; end;
@ -179,7 +179,7 @@ process(["install-fallback", Path]) ->
ok -> ok ->
?STATUS_SUCCESS; ?STATUS_SUCCESS;
{error, Reason} -> {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]), [filename:absname(Path), node(), Reason]),
?STATUS_ERROR ?STATUS_ERROR
end; end;
@ -189,7 +189,7 @@ process(["import-file", Path]) ->
ok -> ok ->
?STATUS_SUCCESS; ?STATUS_SUCCESS;
{error, Reason} -> {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]), [filename:absname(Path), node(), Reason]),
?STATUS_ERROR ?STATUS_ERROR
end; end;
@ -199,7 +199,7 @@ process(["import-dir", Path]) ->
ok -> ok ->
?STATUS_SUCCESS; ?STATUS_SUCCESS;
{error, Reason} -> {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]), [filename:absname(Path), node(), Reason]),
?STATUS_ERROR ?STATUS_ERROR
end; end;
@ -209,7 +209,7 @@ process(["delete-expired-messages"]) ->
?STATUS_SUCCESS; ?STATUS_SUCCESS;
process(["mnesia"]) -> process(["mnesia"]) ->
io:format("~p~n", [mnesia:system_info(all)]), ?PRINT("~p~n", [mnesia:system_info(all)]),
?STATUS_SUCCESS; ?STATUS_SUCCESS;
process(["mnesia", "info"]) -> process(["mnesia", "info"]) ->
@ -218,30 +218,30 @@ process(["mnesia", "info"]) ->
process(["mnesia", Arg]) when is_list(Arg) -> process(["mnesia", Arg]) when is_list(Arg) ->
case catch mnesia:system_info(list_to_atom(Arg)) of case catch mnesia:system_info(list_to_atom(Arg)) of
{'EXIT', Error} -> io:format("Error: ~p~n", [Error]); {'EXIT', Error} -> ?PRINT("Error: ~p~n", [Error]);
Return -> io:format("~p~n", [Return]) Return -> ?PRINT("~p~n", [Return])
end, end,
?STATUS_SUCCESS; ?STATUS_SUCCESS;
process(["delete-old-messages", Days]) -> process(["delete-old-messages", Days]) ->
case catch list_to_integer(Days) of case catch list_to_integer(Days) of
{'EXIT',{Reason, _Stack}} -> {'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]), [Reason]),
?STATUS_ERROR; ?STATUS_ERROR;
Integer when Integer >= 0 -> Integer when Integer >= 0 ->
{atomic, _} = mod_offline:remove_old_messages(Integer), {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; ?STATUS_SUCCESS;
_Integer -> _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 ?STATUS_ERROR
end; end;
process(["vhost", H | Args]) -> process(["vhost", H | Args]) ->
case jlib:nameprep(H) of case jlib:nameprep(H) of
false -> false ->
io:format("Bad hostname: ~p~n", [H]), ?PRINT("Bad hostname: ~p~n", [H]),
?STATUS_ERROR; ?STATUS_ERROR;
Host -> Host ->
case ejabberd_hooks:run_fold( case ejabberd_hooks:run_fold(
@ -296,7 +296,7 @@ print_usage() ->
[" ", Cmd, string:chars($\s, MaxCmdLen - length(Cmd) + 2), [" ", Cmd, string:chars($\s, MaxCmdLen - length(Cmd) + 2),
Desc, NewLine] Desc, NewLine]
end, CmdDescs), end, CmdDescs),
io:format( ?PRINT(
"Usage: ejabberdctl [--node nodename] command [options]~n" "Usage: ejabberdctl [--node nodename] command [options]~n"
"~n" "~n"
"Available commands in this ejabberd node:~n" "Available commands in this ejabberd node:~n"
@ -305,8 +305,8 @@ print_usage() ->
"Examples:~n" "Examples:~n"
" ejabberdctl restart~n" " ejabberdctl restart~n"
" ejabberdctl --node ejabberd@host restart~n" " ejabberdctl --node ejabberd@host restart~n"
" ejabberdctl vhost jabber.example.org ...~n" " ejabberdctl vhost jabber.example.org ...~n",
). []).
print_vhost_usage(Host) -> print_vhost_usage(Host) ->
CmdDescs = CmdDescs =
@ -329,15 +329,15 @@ print_vhost_usage(Host) ->
[" ", Cmd, string:chars($\s, MaxCmdLen - length(Cmd) + 2), [" ", Cmd, string:chars($\s, MaxCmdLen - length(Cmd) + 2),
Desc, NewLine] Desc, NewLine]
end, CmdDescs), end, CmdDescs),
io:format( ?PRINT(
"Usage: ejabberdctl [--node nodename] vhost hostname command [options]~n" "Usage: ejabberdctl [--node nodename] vhost hostname command [options]~n"
"~n" "~n"
"Available commands in this ejabberd node and this vhost:~n" "Available commands in this ejabberd node and this vhost:~n"
++ FmtCmdDescs ++ ++ FmtCmdDescs ++
"~n" "~n"
"Examples:~n" "Examples:~n"
" ejabberdctl vhost "++Host++" registered-users~n" " ejabberdctl vhost "++Host++" registered-users~n",
). []).
register_commands(CmdDescs, Module, Function) -> register_commands(CmdDescs, Module, Function) ->
ets:insert(ejabberd_ctl_cmds, CmdDescs), ets:insert(ejabberd_ctl_cmds, CmdDescs),

View File

@ -33,6 +33,8 @@
-export([set/1]). -export([set/1]).
-include("ejabberd.hrl").
-define(LOGMODULE, "error_logger"). -define(LOGMODULE, "error_logger").
%% Error levels: %% Error levels:
@ -80,7 +82,7 @@ load_logger(Forms, Mod, Loglevel) ->
{ok, M, Bin} -> {ok, M, Bin} ->
code:load_binary(M, Fname, Bin); code:load_binary(M, Fname, Bin);
Error -> Error ->
io:format("Error ~p~n", [Error]) ?CRITICAL_MSG("Error ~p~n", [Error])
end. end.
%% -------------------------------------------------------------- %% --------------------------------------------------------------

View File

@ -415,11 +415,11 @@ send_element(Pid, El) ->
ctl_process(_Val, ["incoming-s2s-number"]) -> ctl_process(_Val, ["incoming-s2s-number"]) ->
N = length(supervisor:which_children(ejabberd_s2s_in_sup)), N = length(supervisor:which_children(ejabberd_s2s_in_sup)),
io:format("~p~n", [N]), ?PRINT("~p~n", [N]),
{stop, ?STATUS_SUCCESS}; {stop, ?STATUS_SUCCESS};
ctl_process(_Val, ["outgoing-s2s-number"]) -> ctl_process(_Val, ["outgoing-s2s-number"]) ->
N = length(supervisor:which_children(ejabberd_s2s_out_sup)), N = length(supervisor:which_children(ejabberd_s2s_out_sup)),
io:format("~p~n", [N]), ?PRINT("~p~n", [N]),
{stop, ?STATUS_SUCCESS}; {stop, ?STATUS_SUCCESS};
ctl_process(Val, _Args) -> ctl_process(Val, _Args) ->
Val. Val.

View File

@ -652,18 +652,18 @@ ctl_process(_Val, ["connected-users"]) ->
NewLine = io_lib:format("~n", []), NewLine = io_lib:format("~n", []),
SUSRs = lists:sort(USRs), SUSRs = lists:sort(USRs),
FUSRs = lists:map(fun({U, S, R}) -> [U, $@, S, $/, R, NewLine] end, SUSRs), FUSRs = lists:map(fun({U, S, R}) -> [U, $@, S, $/, R, NewLine] end, SUSRs),
io:format("~s", [FUSRs]), ?PRINT("~s", [FUSRs]),
{stop, ?STATUS_SUCCESS}; {stop, ?STATUS_SUCCESS};
ctl_process(_Val, ["connected-users-number"]) -> ctl_process(_Val, ["connected-users-number"]) ->
N = length(dirty_get_sessions_list()), N = length(dirty_get_sessions_list()),
io:format("~p~n", [N]), ?PRINT("~p~n", [N]),
{stop, ?STATUS_SUCCESS}; {stop, ?STATUS_SUCCESS};
ctl_process(_Val, ["user-resources", User, Server]) -> ctl_process(_Val, ["user-resources", User, Server]) ->
Resources = get_user_resources(User, Server), Resources = get_user_resources(User, Server),
NewLine = io_lib:format("~n", []), NewLine = io_lib:format("~n", []),
SResources = lists:sort(Resources), SResources = lists:sort(Resources),
FResources = lists:map(fun(R) -> [R, NewLine] end, SResources), FResources = lists:map(fun(R) -> [R, NewLine] end, SResources),
io:format("~s", [FResources]), ?PRINT("~s", [FResources]),
{stop, ?STATUS_SUCCESS}; {stop, ?STATUS_SUCCESS};
ctl_process(Val, _Args) -> ctl_process(Val, _Args) ->
Val. Val.

View File

@ -30,6 +30,8 @@
%% API %% API
-export([update/0, update_info/0]). -export([update/0, update_info/0]).
-include("ejabberd.hrl").
%%==================================================================== %%====================================================================
%% API %% API
%%==================================================================== %%====================================================================
@ -40,7 +42,7 @@ update() ->
release_handler_1:eval_script( release_handler_1:eval_script(
LowLevelScript, [], LowLevelScript, [],
[{ejabberd, "", filename:join(Dir, "..")}]), [{ejabberd, "", filename:join(Dir, "..")}]),
io:format("eval: ~p~n", [Eval]), ?INFO_MSG("eval: ~p~n", [Eval]),
Eval; Eval;
{error, Reason} -> {error, Reason} ->
{error, Reason} {error, Reason}
@ -67,16 +69,16 @@ update_info() ->
false false
end end
end, Beams), end, Beams),
io:format("beam files: ~p~n", [UpdatedBeams]), ?INFO_MSG("beam files: ~p~n", [UpdatedBeams]),
Script = make_script(UpdatedBeams), Script = make_script(UpdatedBeams),
io:format("script: ~p~n", [Script]), ?INFO_MSG("script: ~p~n", [Script]),
LowLevelScript = make_low_level_script(UpdatedBeams, 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 = Check =
release_handler_1:check_script( release_handler_1:check_script(
LowLevelScript, LowLevelScript,
[{ejabberd, "", filename:join(Dir, "..")}]), [{ejabberd, "", filename:join(Dir, "..")}]),
io:format("check: ~p~n", [Check]), ?INFO_MSG("check: ~p~n", [Check]),
{ok, Dir, UpdatedBeams, Script, LowLevelScript, Check}; {ok, Dir, UpdatedBeams, Script, LowLevelScript, Check};
{error, Reason} -> {error, Reason} ->
{error, Reason} {error, Reason}

View File

@ -30,6 +30,7 @@
-export([start/2, stop/1, init/2, -export([start/2, stop/1, init/2,
check_password/3, set_password/3, is_user_exists/2]). check_password/3, set_password/3, is_user_exists/2]).
-include("ejabberd.hrl").
start(Host, ExtPrg) -> start(Host, ExtPrg) ->
spawn(?MODULE, init, [Host, ExtPrg]). spawn(?MODULE, init, [Host, ExtPrg]).
@ -76,7 +77,7 @@ loop(Port) ->
exit(normal) exit(normal)
end; end;
{'EXIT', Port, Reason} -> {'EXIT', Port, Reason} ->
io:format("~p ~n", [Reason]), ?CRITICAL_MSG("~p ~n", [Reason]),
exit(port_terminated) exit(port_terminated)
end. end.

View File

@ -254,7 +254,7 @@ do_route1(Host, ServerHost, From, To, Packet, DefEnc) ->
[[_ | _] = Channel, [_ | _] = Server] -> [[_ | _] = Channel, [_ | _] = Server] ->
case ets:lookup(irc_connection, {From, Server, Host}) of 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( {Username, Encoding} = get_user_and_encoding(
Host, From, Server, DefEnc), Host, From, Server, DefEnc),
{ok, Pid} = mod_irc_connection:start( {ok, Pid} = mod_irc_connection:start(
@ -269,7 +269,7 @@ do_route1(Host, ServerHost, From, To, Packet, DefEnc) ->
ok; ok;
[R] -> [R] ->
Pid = R#irc_connection.pid, Pid = R#irc_connection.pid,
io:format("send to process ~p~n", ?DEBUG("send to process ~p~n",
[Pid]), [Pid]),
mod_irc_connection:route_chan( mod_irc_connection:route_chan(
Pid, Channel, Resource, Packet), Pid, Channel, Resource, Packet),
@ -285,7 +285,7 @@ do_route1(Host, ServerHost, From, To, Packet, DefEnc) ->
ejabberd_router:route(To, From, Err); ejabberd_router:route(To, From, Err);
[R] -> [R] ->
Pid = R#irc_connection.pid, Pid = R#irc_connection.pid,
io:format("send to process ~p~n", ?DEBUG("send to process ~p~n",
[Pid]), [Pid]),
mod_irc_connection:route_nick( mod_irc_connection:route_nick(
Pid, Nick, Packet), Pid, Nick, Packet),

View File

@ -29,6 +29,8 @@
-export([new/1, new1/1, update/2]). -export([new/1, new1/1, update/2]).
-include("ejabberd.hrl").
-record(maxrate, {maxrate, lastrate, lasttime}). -record(maxrate, {maxrate, lastrate, lasttime}).
@ -56,8 +58,8 @@ update(#maxrate{} = State, Size) ->
MinInterv = 1000 * Size / MinInterv = 1000 * Size /
(2 * State#maxrate.maxrate - State#maxrate.lastrate), (2 * State#maxrate.maxrate - State#maxrate.lastrate),
Interv = (now_to_usec(now()) - State#maxrate.lasttime) / 1000, Interv = (now_to_usec(now()) - State#maxrate.lasttime) / 1000,
%io:format("State: ~p, Size=~p~nM=~p, I=~p~n", ?INFO_MSG("State: ~p, Size=~p~nM=~p, I=~p~n",
% [State, Size, MinInterv, Interv]), [State, Size, MinInterv, Interv]),
Pause = if Pause = if
MinInterv > Interv -> MinInterv > Interv ->
1 + trunc(MinInterv - Interv); 1 + trunc(MinInterv - Interv);

View File

@ -49,6 +49,8 @@
code_change/3, code_change/3,
terminate/2]). terminate/2]).
-include("ejabberd.hrl").
-define(SET_CERTIFICATE_FILE_ACCEPT, 1). -define(SET_CERTIFICATE_FILE_ACCEPT, 1).
-define(SET_CERTIFICATE_FILE_CONNECT, 2). -define(SET_CERTIFICATE_FILE_CONNECT, 2).
-define(SET_ENCRYPTED_INPUT, 3). -define(SET_ENCRYPTED_INPUT, 3).
@ -166,7 +168,7 @@ recv_data1(#tlssock{tcpsock = TCPSocket, tlsport = Port}, Packet) ->
<<0, Out/binary>> -> <<0, Out/binary>> ->
case gen_tcp:send(TCPSocket, Out) of case gen_tcp:send(TCPSocket, Out) of
ok -> ok ->
%io:format("IN: ~p~n", [{TCPSocket, binary_to_list(In)}]), %?PRINT("IN: ~p~n", [{TCPSocket, binary_to_list(In)}]),
{ok, In}; {ok, In};
Error -> Error ->
Error Error
@ -184,7 +186,7 @@ recv_data1(#tlssock{tcpsock = TCPSocket, tlsport = Port}, Packet) ->
send(#tlssock{tcpsock = TCPSocket, tlsport = Port}, Packet) -> send(#tlssock{tcpsock = TCPSocket, tlsport = Port}, Packet) ->
case port_control(Port, ?SET_DECRYPTED_OUTPUT, Packet) of case port_control(Port, ?SET_DECRYPTED_OUTPUT, Packet) of
<<0>> -> <<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 case port_control(Port, ?GET_ENCRYPTED_OUTPUT, []) of
<<0, Out/binary>> -> <<0, Out/binary>> ->
gen_tcp:send(TCPSocket, Out); gen_tcp:send(TCPSocket, Out);
@ -243,50 +245,50 @@ test() ->
{error, already_loaded} -> ok {error, already_loaded} -> ok
end, end,
Port = open_port({spawn, tls_drv}, [binary]), 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, PCRes = port_control(Port, ?SET_CERTIFICATE_FILE_ACCEPT,
"./ssl.pem" ++ [0]), "./ssl.pem" ++ [0]),
io:format("port_control: ~p~n", [PCRes]), ?PRINT("port_control: ~p~n", [PCRes]),
{ok, ListenSocket} = gen_tcp:listen(1234, [binary, {ok, ListenSocket} = gen_tcp:listen(1234, [binary,
{packet, 0}, {packet, 0},
{active, true}, {active, true},
{reuseaddr, true}, {reuseaddr, true},
{nodelay, true}]), {nodelay, true}]),
io:format("listen: ~p~n", [ListenSocket]), ?PRINT("listen: ~p~n", [ListenSocket]),
{ok, Socket} = gen_tcp:accept(ListenSocket), {ok, Socket} = gen_tcp:accept(ListenSocket),
io:format("accept: ~p~n", [Socket]), ?PRINT("accept: ~p~n", [Socket]),
loop(Port, Socket). loop(Port, Socket).
loop(Port, Socket) -> loop(Port, Socket) ->
receive receive
{tcp, Socket, Data} -> {tcp, Socket, Data} ->
%io:format("read: ~p~n", [Data]), %?PRINT("read: ~p~n", [Data]),
Res = port_control(Port, ?SET_ENCRYPTED_INPUT, 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), 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 case DIRes of
<<0, In/binary>> -> <<0, In/binary>> ->
io:format("input: ~s~n", [binary_to_list(In)]); ?PRINT("input: ~s~n", [binary_to_list(In)]);
<<1, DIError/binary>> -> <<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, end,
EORes = port_control(Port, ?GET_ENCRYPTED_OUTPUT, Data), 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 case EORes of
<<0, Out/binary>> -> <<0, Out/binary>> ->
gen_tcp:send(Socket, Out); gen_tcp:send(Socket, Out);
<<1, EOError/binary>> -> <<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, end,
loop(Port, Socket); loop(Port, Socket);
Msg -> Msg ->
io:format("receive: ~p~n", [Msg]), ?PRINT("receive: ~p~n", [Msg]),
loop(Port, Socket) loop(Port, Socket)
end. end.

View File

@ -398,7 +398,7 @@ resend_message(Packet) ->
ParsedPacket = xml_stream:parse_element(Packet), ParsedPacket = xml_stream:parse_element(Packet),
From = get_jid("from", ParsedPacket), From = get_jid("from", ParsedPacket),
To = get_jid("to", 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). ejabberd_router:route(From, To, ParsedPacket).
%% Type can be "from" or "to" %% Type can be "from" or "to"