2004-08-24 22:11:01 +02:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
%%% File : mod_service_log.erl
|
2007-12-24 13:58:05 +01:00
|
|
|
%%% Author : Alexey Shchepin <alexey@process-one.net>
|
2006-01-27 06:00:27 +01:00
|
|
|
%%% Purpose : Copy user messages to logger service
|
2007-12-24 13:58:05 +01:00
|
|
|
%%% Created : 24 Aug 2003 by Alexey Shchepin <alexey@process-one.net>
|
|
|
|
%%%
|
|
|
|
%%%
|
2011-02-14 13:47:22 +01:00
|
|
|
%%% ejabberd, Copyright (C) 2002-2011 ProcessOne
|
2007-12-24 13:58:05 +01:00
|
|
|
%%%
|
|
|
|
%%% This program is free software; you can redistribute it and/or
|
|
|
|
%%% modify it under the terms of the GNU General Public License as
|
|
|
|
%%% published by the Free Software Foundation; either version 2 of the
|
|
|
|
%%% License, or (at your option) any later version.
|
|
|
|
%%%
|
|
|
|
%%% This program is distributed in the hope that it will be useful,
|
|
|
|
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
%%% General Public License for more details.
|
2009-01-19 15:47:33 +01:00
|
|
|
%%%
|
2007-12-24 13:58:05 +01:00
|
|
|
%%% You should have received a copy of the GNU General Public License
|
|
|
|
%%% along with this program; if not, write to the Free Software
|
|
|
|
%%% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
|
|
|
%%% 02111-1307 USA
|
|
|
|
%%%
|
2004-08-24 22:11:01 +02:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
|
|
|
|
-module(mod_service_log).
|
2007-12-24 13:58:05 +01:00
|
|
|
-author('alexey@process-one.net').
|
2004-08-24 22:11:01 +02:00
|
|
|
|
|
|
|
-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]).
|
|
|
|
|
2008-10-07 11:55:38 +02:00
|
|
|
-include_lib("exmpp/include/exmpp.hrl").
|
|
|
|
|
2004-08-24 22:11:01 +02:00
|
|
|
-include("ejabberd.hrl").
|
|
|
|
|
2005-06-20 05:18:13 +02:00
|
|
|
start(Host, _Opts) ->
|
2009-01-03 16:15:38 +01:00
|
|
|
HostB = list_to_binary(Host),
|
|
|
|
ejabberd_hooks:add(user_send_packet, HostB,
|
2004-08-24 22:11:01 +02:00
|
|
|
?MODULE, log_user_send, 50),
|
2009-01-03 16:15:38 +01:00
|
|
|
ejabberd_hooks:add(user_receive_packet, HostB,
|
2004-08-24 22:11:01 +02:00
|
|
|
?MODULE, log_user_receive, 50),
|
|
|
|
ok.
|
|
|
|
|
2005-06-20 05:18:13 +02:00
|
|
|
stop(Host) ->
|
2009-01-03 16:15:38 +01:00
|
|
|
HostB = list_to_binary(Host),
|
|
|
|
ejabberd_hooks:delete(user_send_packet, HostB,
|
2004-08-24 22:11:01 +02:00
|
|
|
?MODULE, log_user_send, 50),
|
2009-01-03 16:15:38 +01:00
|
|
|
ejabberd_hooks:delete(user_receive_packet, HostB,
|
2004-08-24 22:11:01 +02:00
|
|
|
?MODULE, log_user_receive, 50),
|
|
|
|
ok.
|
|
|
|
|
|
|
|
log_user_send(From, To, Packet) ->
|
2009-06-01 18:38:28 +02:00
|
|
|
log_packet(From, To, Packet, exmpp_jid:prep_domain_as_list(From)).
|
2004-08-24 22:11:01 +02:00
|
|
|
|
|
|
|
log_user_receive(_JID, From, To, Packet) ->
|
2009-06-01 18:38:28 +02:00
|
|
|
log_packet(From, To, Packet, exmpp_jid:prep_domain_as_list(To)).
|
2004-08-24 22:11:01 +02:00
|
|
|
|
|
|
|
|
2008-10-07 11:55:38 +02:00
|
|
|
log_packet(From, To, Packet, Host) ->
|
2005-06-20 05:18:13 +02:00
|
|
|
Loggers = gen_mod:get_module_opt(Host, ?MODULE, loggers, []),
|
2009-06-01 18:26:00 +02:00
|
|
|
ServerJID = exmpp_jid:make(Host),
|
2008-10-07 11:55:38 +02:00
|
|
|
FixedPacket = exmpp_stanza:set_jids(Packet, From, To),
|
2004-08-24 22:11:01 +02:00
|
|
|
lists:foreach(
|
|
|
|
fun(Logger) ->
|
|
|
|
ejabberd_router:route(
|
|
|
|
ServerJID,
|
2009-06-01 18:26:00 +02:00
|
|
|
exmpp_jid:make(Logger),
|
2008-10-07 11:55:38 +02:00
|
|
|
#xmlel{name = 'route', children = [FixedPacket]})
|
2004-08-24 22:11:01 +02:00
|
|
|
end, Loggers).
|
|
|
|
|