mirror of
https://github.com/processone/ejabberd.git
synced 2024-12-22 17:28:25 +01:00
Rewrite io:format calls to loglevel macros (EJAB-555)
SVN Revision: 1239
This commit is contained in:
parent
694baba127
commit
b2bd9759c8
19
ChangeLog
19
ChangeLog
@ -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>
|
||||
|
||||
* doc/guide.tex: Improve explanation of how to start ejabberd when
|
||||
|
@ -14,6 +14,8 @@
|
||||
mech_new/3,
|
||||
mech_step/2]).
|
||||
|
||||
-include("ejabberd.hrl").
|
||||
|
||||
-behaviour(cyrsasl).
|
||||
|
||||
-record(state, {step, nonce, username, authzid, get_password}).
|
||||
@ -67,7 +69,7 @@ mech_step(#state{step = 5,
|
||||
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"}.
|
||||
|
||||
|
||||
|
@ -38,6 +38,10 @@
|
||||
%% ---------------------------------
|
||||
%% 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)).
|
||||
|
||||
|
@ -212,7 +212,7 @@ ctl_process_get_registered(_Val, Host, ["registered-users"]) ->
|
||||
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.
|
||||
|
@ -58,7 +58,7 @@ start() ->
|
||||
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 ->
|
||||
@ -77,14 +77,14 @@ init() ->
|
||||
|
||||
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;
|
||||
|
||||
@ -107,11 +107,11 @@ process(["register", User, Server, Password]) ->
|
||||
{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;
|
||||
@ -119,7 +119,7 @@ process(["register", User, Server, Password]) ->
|
||||
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;
|
||||
_ ->
|
||||
@ -131,7 +131,7 @@ process(["backup", Path]) ->
|
||||
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;
|
||||
@ -141,7 +141,7 @@ process(["dump", Path]) ->
|
||||
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;
|
||||
@ -151,7 +151,7 @@ process(["load", Path]) ->
|
||||
{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;
|
||||
@ -161,15 +161,15 @@ process(["restore", Path]) ->
|
||||
{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;
|
||||
@ -179,7 +179,7 @@ process(["install-fallback", Path]) ->
|
||||
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;
|
||||
@ -189,7 +189,7 @@ process(["import-file", Path]) ->
|
||||
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;
|
||||
@ -199,7 +199,7 @@ process(["import-dir", Path]) ->
|
||||
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;
|
||||
@ -209,7 +209,7 @@ process(["delete-expired-messages"]) ->
|
||||
?STATUS_SUCCESS;
|
||||
|
||||
process(["mnesia"]) ->
|
||||
io:format("~p~n", [mnesia:system_info(all)]),
|
||||
?PRINT("~p~n", [mnesia:system_info(all)]),
|
||||
?STATUS_SUCCESS;
|
||||
|
||||
process(["mnesia", "info"]) ->
|
||||
@ -218,30 +218,30 @@ 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(
|
||||
@ -296,7 +296,7 @@ print_usage() ->
|
||||
[" ", 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"
|
||||
@ -305,8 +305,8 @@ print_usage() ->
|
||||
"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 =
|
||||
@ -329,15 +329,15 @@ print_vhost_usage(Host) ->
|
||||
[" ", 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),
|
||||
|
@ -33,6 +33,8 @@
|
||||
|
||||
-export([set/1]).
|
||||
|
||||
-include("ejabberd.hrl").
|
||||
|
||||
-define(LOGMODULE, "error_logger").
|
||||
|
||||
%% Error levels:
|
||||
@ -80,7 +82,7 @@ load_logger(Forms, Mod, Loglevel) ->
|
||||
{ok, M, Bin} ->
|
||||
code:load_binary(M, Fname, Bin);
|
||||
Error ->
|
||||
io:format("Error ~p~n", [Error])
|
||||
?CRITICAL_MSG("Error ~p~n", [Error])
|
||||
end.
|
||||
|
||||
%% --------------------------------------------------------------
|
||||
|
@ -415,11 +415,11 @@ send_element(Pid, El) ->
|
||||
|
||||
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.
|
||||
|
@ -652,18 +652,18 @@ ctl_process(_Val, ["connected-users"]) ->
|
||||
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.
|
||||
|
@ -30,6 +30,8 @@
|
||||
%% API
|
||||
-export([update/0, update_info/0]).
|
||||
|
||||
-include("ejabberd.hrl").
|
||||
|
||||
%%====================================================================
|
||||
%% API
|
||||
%%====================================================================
|
||||
@ -40,7 +42,7 @@ update() ->
|
||||
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}
|
||||
@ -67,16 +69,16 @@ update_info() ->
|
||||
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}
|
||||
|
@ -30,6 +30,7 @@
|
||||
-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]).
|
||||
@ -76,7 +77,7 @@ loop(Port) ->
|
||||
exit(normal)
|
||||
end;
|
||||
{'EXIT', Port, Reason} ->
|
||||
io:format("~p ~n", [Reason]),
|
||||
?CRITICAL_MSG("~p ~n", [Reason]),
|
||||
exit(port_terminated)
|
||||
end.
|
||||
|
||||
|
@ -254,7 +254,7 @@ do_route1(Host, ServerHost, From, To, Packet, DefEnc) ->
|
||||
[[_ | _] = 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(
|
||||
@ -269,7 +269,7 @@ do_route1(Host, ServerHost, From, To, Packet, DefEnc) ->
|
||||
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),
|
||||
@ -285,7 +285,7 @@ do_route1(Host, ServerHost, From, To, Packet, DefEnc) ->
|
||||
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),
|
||||
|
@ -29,6 +29,8 @@
|
||||
|
||||
-export([new/1, new1/1, update/2]).
|
||||
|
||||
-include("ejabberd.hrl").
|
||||
|
||||
-record(maxrate, {maxrate, lastrate, lasttime}).
|
||||
|
||||
|
||||
@ -56,8 +58,8 @@ update(#maxrate{} = State, Size) ->
|
||||
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);
|
||||
|
@ -49,6 +49,8 @@
|
||||
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).
|
||||
@ -166,7 +168,7 @@ recv_data1(#tlssock{tcpsock = TCPSocket, tlsport = Port}, Packet) ->
|
||||
<<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
|
||||
@ -184,7 +186,7 @@ recv_data1(#tlssock{tcpsock = TCPSocket, tlsport = Port}, Packet) ->
|
||||
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);
|
||||
@ -243,50 +245,50 @@ test() ->
|
||||
{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.
|
||||
|
||||
|
@ -398,7 +398,7 @@ resend_message(Packet) ->
|
||||
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"
|
||||
|
Loading…
Reference in New Issue
Block a user