25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-12-26 17:38:45 +01:00

Merge branch '2.2.x' into websockets

This commit is contained in:
Eric Cestari 2010-09-16 11:07:12 +02:00
commit 44832e12b3
4 changed files with 75 additions and 2 deletions

1
.gitignore vendored
View File

@ -3,6 +3,7 @@ archives
build/ build/
*.dSYM/ *.dSYM/
.gitignore .gitignore
*.so
contrib/extract_translations/extract_translations.beam contrib/extract_translations/extract_translations.beam
doc/contributed_modules.tex doc/contributed_modules.tex
doc/features.aux doc/features.aux

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.

View File

@ -49,7 +49,7 @@
process([Domain | _Rest] = LocalPath, #request{auth = Auth} = Request)-> process([Domain | _Rest] = LocalPath, #request{auth = Auth} = Request)->
UD = get_auth(Auth), UD = get_auth(Auth),
Module = backend(Domain), Module = backend(Domain),
case out(Module, Request, Request#request.method, LocalPath,UD) of case catch out(Module, Request, Request#request.method, LocalPath,UD) of
{'EXIT', Error} -> {'EXIT', Error} ->
?ERROR_MSG("Error while processing ~p : ~n~p", [LocalPath, Error]), ?ERROR_MSG("Error while processing ~p : ~n~p", [LocalPath, Error]),
error(500); error(500);