mirror of
https://github.com/processone/ejabberd.git
synced 2025-01-01 17:53:00 +01:00
* src/mod_offline.erl: Added a config option to define the maximum
number of offline messages per user (EJAB-314). SVN Revision: 878
This commit is contained in:
parent
b5c66657c9
commit
731457a8bb
@ -1,5 +1,8 @@
|
|||||||
2007-08-13 Mickael Remond <mickael.remond@process-one.net>
|
2007-08-13 Mickael Remond <mickael.remond@process-one.net>
|
||||||
|
|
||||||
|
* src/mod_offline.erl: Added a config option to define the maximum
|
||||||
|
number of offline messages per user (EJAB-314).
|
||||||
|
|
||||||
* doc/guide.tex: Added documentation for the mod_offline quota
|
* doc/guide.tex: Added documentation for the mod_offline quota
|
||||||
(EJAB-314).
|
(EJAB-314).
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
-behaviour(gen_mod).
|
-behaviour(gen_mod).
|
||||||
|
|
||||||
-export([start/2,
|
-export([start/2,
|
||||||
init/0,
|
init/1,
|
||||||
stop/1,
|
stop/1,
|
||||||
store_packet/3,
|
store_packet/3,
|
||||||
resend_offline_messages/2,
|
resend_offline_messages/2,
|
||||||
@ -29,12 +29,7 @@
|
|||||||
-define(PROCNAME, ejabberd_offline).
|
-define(PROCNAME, ejabberd_offline).
|
||||||
-define(OFFLINE_TABLE_LOCK_THRESHOLD, 1000).
|
-define(OFFLINE_TABLE_LOCK_THRESHOLD, 1000).
|
||||||
|
|
||||||
%% TODO: Move this part as a module config file parameter:
|
start(Host, Opts) ->
|
||||||
%% Can be an integer > 0 or infinity:
|
|
||||||
%%-define(MAX_OFFLINE_MSGS, infinity).
|
|
||||||
-define(MAX_OFFLINE_MSGS, 5).
|
|
||||||
|
|
||||||
start(Host, _Opts) ->
|
|
||||||
mnesia:create_table(offline_msg,
|
mnesia:create_table(offline_msg,
|
||||||
[{disc_only_copies, [node()]},
|
[{disc_only_copies, [node()]},
|
||||||
{type, bag},
|
{type, bag},
|
||||||
@ -48,20 +43,25 @@ start(Host, _Opts) ->
|
|||||||
?MODULE, remove_user, 50),
|
?MODULE, remove_user, 50),
|
||||||
ejabberd_hooks:add(anonymous_purge_hook, Host,
|
ejabberd_hooks:add(anonymous_purge_hook, Host,
|
||||||
?MODULE, remove_user, 50),
|
?MODULE, remove_user, 50),
|
||||||
|
MAX_OFFLINE_MSGS = gen_mod:get_opt(user_max_messages, Opts, infinity),
|
||||||
register(gen_mod:get_module_proc(Host, ?PROCNAME),
|
register(gen_mod:get_module_proc(Host, ?PROCNAME),
|
||||||
spawn(?MODULE, init, [])).
|
spawn(?MODULE, init, [MAX_OFFLINE_MSGS])).
|
||||||
|
|
||||||
init() ->
|
%% MAX_OFFLINE_MSGS is either infinity of integer > 0
|
||||||
loop().
|
init(infinity) ->
|
||||||
|
loop(infinity);
|
||||||
|
init(MAX_OFFLINE_MSGS)
|
||||||
|
when integer(MAX_OFFLINE_MSGS), MAX_OFFLINE_MSGS > 0 ->
|
||||||
|
loop(MAX_OFFLINE_MSGS).
|
||||||
|
|
||||||
loop() ->
|
loop(MAX_OFFLINE_MSGS) ->
|
||||||
receive
|
receive
|
||||||
#offline_msg{us=US} = Msg ->
|
#offline_msg{us=US} = Msg ->
|
||||||
Msgs = receive_all(US, [Msg]),
|
Msgs = receive_all(US, [Msg]),
|
||||||
Len = length(Msgs),
|
Len = length(Msgs),
|
||||||
F = fun() ->
|
F = fun() ->
|
||||||
%% Only count messages if needed:
|
%% Only count messages if needed:
|
||||||
Count = if ?MAX_OFFLINE_MSGS =/= infinity ->
|
Count = if MAX_OFFLINE_MSGS =/= infinity ->
|
||||||
Len + p1_mnesia:count_records(
|
Len + p1_mnesia:count_records(
|
||||||
offline_msg,
|
offline_msg,
|
||||||
#offline_msg{us=US, _='_'});
|
#offline_msg{us=US, _='_'});
|
||||||
@ -69,7 +69,7 @@ loop() ->
|
|||||||
0
|
0
|
||||||
end,
|
end,
|
||||||
if
|
if
|
||||||
Count > ?MAX_OFFLINE_MSGS ->
|
Count > MAX_OFFLINE_MSGS ->
|
||||||
discard_warn_sender(Msgs);
|
discard_warn_sender(Msgs);
|
||||||
true ->
|
true ->
|
||||||
if
|
if
|
||||||
@ -84,9 +84,9 @@ loop() ->
|
|||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
mnesia:transaction(F),
|
mnesia:transaction(F),
|
||||||
loop();
|
loop(MAX_OFFLINE_MSGS);
|
||||||
_ ->
|
_ ->
|
||||||
loop()
|
loop(MAX_OFFLINE_MSGS)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
receive_all(US, Msgs) ->
|
receive_all(US, Msgs) ->
|
||||||
|
Loading…
Reference in New Issue
Block a user