summaryrefslogtreecommitdiff
path: root/src/acl.erl
diff options
context:
space:
mode:
authorAlexey Shchepin <alexey@process-one.net>2003-01-18 19:42:48 +0000
committerAlexey Shchepin <alexey@process-one.net>2003-01-18 19:42:48 +0000
commit942fbb9fae632850a4c88d8153adc17595ea4421 (patch)
tree8e2250554335ae6e38c3921994f3672ae692db82 /src/acl.erl
parent*** empty log message *** (diff)
*** empty log message ***
SVN Revision: 43
Diffstat (limited to 'src/acl.erl')
-rw-r--r--src/acl.erl51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/acl.erl b/src/acl.erl
new file mode 100644
index 00000000..109d4edd
--- /dev/null
+++ b/src/acl.erl
@@ -0,0 +1,51 @@
+%%%----------------------------------------------------------------------
+%%% File : acl.erl
+%%% Author : Alexey Shchepin <alexey@sevcom.net>
+%%% Purpose :
+%%% Created : 18 Jan 2003 by Alexey Shchepin <alexey@sevcom.net>
+%%% Id : $Id$
+%%%----------------------------------------------------------------------
+
+-module(acl).
+-author('alexey@sevcom.net').
+-vsn('$Revision$ ').
+
+-export([start/0, add/2, match_rule/2, match_acl/2]).
+
+-include("ejabberd.hrl").
+
+start() ->
+ ets:new(acls, [bag, named_table, public]).
+
+
+add(ACLName, ACLData) ->
+ ets:insert(acls, {ACLName, ACLData}).
+
+match_rule(Rule, JID) ->
+ ACLs = ejabberd_config:get_option(Rule),
+ match_acls(ACLs, JID).
+
+match_acls([], _) ->
+ deny;
+match_acls([{Access, ACL} | ACLs], JID) ->
+ case match_acl(ACL, JID) of
+ true ->
+ Access;
+ _ ->
+ match_acls(ACLs, JID)
+ end.
+
+match_acl(ACL, JID) ->
+ {User, Server, Resource} = jlib:jid_tolower(JID),
+ lists:any(fun({_, Spec}) ->
+ case Spec of
+ all ->
+ true;
+ {user, U} ->
+ (U == User) and (?MYNAME == Server);
+ {user, U, S} ->
+ (U == User) and (S == Server);
+ {server, S} ->
+ S == Server
+ end
+ end, ets:lookup(acls, ACL)).