2004-08-24 22:11:01 +02:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
%%% File : mod_service_log.erl
|
|
|
|
%%% Author : Alexey Shchepin <alexey@sevcom.net>
|
|
|
|
%%% Purpose : Manage announce messages
|
|
|
|
%%% Created : 24 Aug 2003 by Alexey Shchepin <alexey@sevcom.net>
|
|
|
|
%%% Id : $Id$
|
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
|
|
|
|
-module(mod_service_log).
|
|
|
|
-author('alexey@sevcom.net').
|
|
|
|
|
|
|
|
-behaviour(gen_mod).
|
|
|
|
|
2005-06-20 05:18:13 +02:00
|
|
|
-export([start/2,
|
|
|
|
stop/1,
|
2004-08-24 22:11:01 +02:00
|
|
|
log_user_send/3,
|
|
|
|
log_user_receive/4]).
|
|
|
|
|
|
|
|
-include("ejabberd.hrl").
|
|
|
|
-include("jlib.hrl").
|
|
|
|
|
2005-06-20 05:18:13 +02:00
|
|
|
start(Host, _Opts) ->
|
|
|
|
ejabberd_hooks:add(user_send_packet, Host,
|
2004-08-24 22:11:01 +02:00
|
|
|
?MODULE, log_user_send, 50),
|
2005-06-20 05:18:13 +02:00
|
|
|
ejabberd_hooks:add(user_receive_packet, Host,
|
2004-08-24 22:11:01 +02:00
|
|
|
?MODULE, log_user_receive, 50),
|
|
|
|
ok.
|
|
|
|
|
2005-06-20 05:18:13 +02:00
|
|
|
stop(Host) ->
|
|
|
|
ejabberd_hooks:delete(user_send_packet, Host,
|
2004-08-24 22:11:01 +02:00
|
|
|
?MODULE, log_user_send, 50),
|
2005-06-20 05:18:13 +02:00
|
|
|
ejabberd_hooks:delete(user_receive_packet, Host,
|
2004-08-24 22:11:01 +02:00
|
|
|
?MODULE, log_user_receive, 50),
|
|
|
|
ok.
|
|
|
|
|
|
|
|
log_user_send(From, To, Packet) ->
|
|
|
|
log_packet(From, To, Packet).
|
|
|
|
|
|
|
|
log_user_receive(_JID, From, To, Packet) ->
|
|
|
|
log_packet(From, To, Packet).
|
|
|
|
|
|
|
|
|
|
|
|
log_packet(From, To, {xmlelement, Name, Attrs, Els}) ->
|
2005-06-20 05:18:13 +02:00
|
|
|
Host = From#jid.lserver,
|
|
|
|
Loggers = gen_mod:get_module_opt(Host, ?MODULE, loggers, []),
|
|
|
|
ServerJID = #jid{user = "", server = Host, resource = "",
|
|
|
|
luser = "", lserver = Host, lresource = ""},
|
2004-08-24 22:11:01 +02:00
|
|
|
NewAttrs = jlib:replace_from_to_attrs(jlib:jid_to_string(From),
|
|
|
|
jlib:jid_to_string(To),
|
|
|
|
Attrs),
|
|
|
|
FixedPacket = {xmlelement, Name, NewAttrs, Els},
|
|
|
|
lists:foreach(
|
|
|
|
fun(Logger) ->
|
|
|
|
ejabberd_router:route(
|
|
|
|
ServerJID,
|
|
|
|
#jid{user = "", server = Logger, resource = "",
|
|
|
|
luser = "", lserver = Logger, lresource = ""},
|
|
|
|
{xmlelement, "route", [], [FixedPacket]})
|
|
|
|
end, Loggers).
|
|
|
|
|