25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-04 15:36:57 +01:00

mod_keepalive added to repos

This commit is contained in:
Eric Cestari 2010-09-10 14:11:56 +02:00
parent b8b6fc0da5
commit 660a2735f0
2 changed files with 72 additions and 0 deletions

1
src/keepalive.hrl Normal file
View File

@ -0,0 +1 @@
-define(MODS, []).

71
src/mod_keepalive.erl Normal file
View File

@ -0,0 +1,71 @@
%%%----------------------------------------------------------------------
%%% File : mod_keepalive.erl
%%% Author : Christophe romain <cromain@process-one.net>
%%% Purpose : Hidden code autoload
%%%
%%% ejabberd, Copyright (C) 2002-2009 ProcessOne
%%%----------------------------------------------------------------------
-module(mod_keepalive).
-author('cromain@process-one.net').
-behaviour(gen_mod).
-export([start/2, stop/1, init/1]).
-include("keepalive.hrl").
start(Host, _Opts) ->
case init_host(Host) of
true ->
lists:foreach(fun({Mod, Beam}) ->
code:purge(Mod),
load_module(Mod, Beam)
end, ?MODS);
false ->
ok
end.
stop(_Host) ->
ok.
init(["pack"|Mods]) ->
Code = lists:foldl(fun(Mod, Acc) ->
case file:read_file(Mod++".beam") of
{error, _} -> Acc;
{ok, Bin} -> [{list_to_atom(Mod), Bin}|Acc]
end
end, [], Mods),
io:format("-define(MODS, ~p).", [Code]);
init(_) ->
error.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Internal module protection
-define(VALID_HOSTS, []). % default is unlimited use
-define(MAX_USERS, 0). % default is unlimited use
init_host(VHost) ->
case ?VALID_HOSTS of
[] -> % unlimited use
true;
ValidList -> % limited use
init_host(VHost, ValidList)
end.
init_host([], _) ->
false;
init_host(VHost, ValidEncryptedList) ->
EncryptedHost = erlang:md5(lists:reverse(VHost)),
case lists:member(EncryptedHost, ValidEncryptedList) of
true ->
case ?MAX_USERS of
0 -> true;
N -> ejabberd_auth:get_vh_registered_users_number(VHost) =< N
end;
false ->
case string:chr(VHost, $.) of
0 -> false;
Pos -> init_host(string:substr(VHost, Pos+1), ValidEncryptedList)
end
end.