24
1
mirror of https://github.com/processone/ejabberd.git synced 2024-06-18 22:15:20 +02:00
xmpp.chapril.org-ejabberd/src/mod_service_log.erl
Jean-Sébastien Pédron 842ebfcca0 A lot of bug fixes regarding attribute values type:
o  Fix some bugs by getting attributes as list() instead of binary().
o  Instead creating #xmlattr directly, use the new ?XMLATTR macro; it'll
take care of the anything-to-binary() conversion.
o  Fix a bug where recipient and sender were used as binary() instead of
list(), which is required by the rest of the S2S code.
o  Fix a bug where binary_to_list/1 was called on a list().

Now concerning JIDs :
o  Now that #jid{} isn't part of the API of Exmppp anymore, replace
remaining direct usages by calls to exmpp_jid.
o  Replace exmpp_jid:make_bare_jid() by exmpp_jid:make_jid().
o  Replace exmpp_jid:*_to_jid/1 by exmpp_jid:parse_jid/1.

PR:		EJABP-1

SVN Revision: 1841
2009-01-21 13:34:26 +00:00

76 lines
2.4 KiB
Erlang

%%%----------------------------------------------------------------------
%%% File : mod_service_log.erl
%%% Author : Alexey Shchepin <alexey@process-one.net>
%%% Purpose : Copy user messages to logger service
%%% Created : 24 Aug 2003 by Alexey Shchepin <alexey@process-one.net>
%%%
%%%
%%% ejabberd, Copyright (C) 2002-2009 ProcessOne
%%%
%%% 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.
%%%
%%% 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
%%%
%%%----------------------------------------------------------------------
-module(mod_service_log).
-author('alexey@process-one.net').
-behaviour(gen_mod).
-export([start/2,
stop/1,
log_user_send/3,
log_user_receive/4]).
-include_lib("exmpp/include/exmpp.hrl").
-include("ejabberd.hrl").
start(Host, _Opts) ->
HostB = list_to_binary(Host),
ejabberd_hooks:add(user_send_packet, HostB,
?MODULE, log_user_send, 50),
ejabberd_hooks:add(user_receive_packet, HostB,
?MODULE, log_user_receive, 50),
ok.
stop(Host) ->
HostB = list_to_binary(Host),
ejabberd_hooks:delete(user_send_packet, HostB,
?MODULE, log_user_send, 50),
ejabberd_hooks:delete(user_receive_packet, HostB,
?MODULE, log_user_receive, 50),
ok.
log_user_send(From, To, Packet) ->
log_packet(From, To, Packet, exmpp_jid:ldomain_as_list(From)).
log_user_receive(_JID, From, To, Packet) ->
log_packet(From, To, Packet, exmpp_jid:ldomain_as_list(To)).
log_packet(From, To, Packet, Host) ->
Loggers = gen_mod:get_module_opt(Host, ?MODULE, loggers, []),
ServerJID = exmpp_jid:make_jid(Host),
FixedPacket = exmpp_stanza:set_jids(Packet, From, To),
lists:foreach(
fun(Logger) ->
ejabberd_router:route(
ServerJID,
exmpp_jid:make_jid(Logger),
#xmlel{name = 'route', children = [FixedPacket]})
end, Loggers).