summaryrefslogtreecommitdiff
path: root/src/mod_privacy_odbc.erl
diff options
context:
space:
mode:
authorBadlop <badlop@process-one.net>2011-01-19 20:58:51 +0100
committerBadlop <badlop@process-one.net>2011-01-19 20:58:57 +0100
commita25c9c5df33d90ba73dac73d3a082da49c47e625 (patch)
tree5bb8a0907ef524d8cd8447b68810dab75d8687dc /src/mod_privacy_odbc.erl
parentFix delayed response of a timeout call was reused for next login (EJAB-1385) (diff)
Don't let presence-in privacy rule block a presence subscription using ODBC (EJAB-255)
Diffstat (limited to 'src/mod_privacy_odbc.erl')
-rw-r--r--src/mod_privacy_odbc.erl79
1 files changed, 36 insertions, 43 deletions
diff --git a/src/mod_privacy_odbc.erl b/src/mod_privacy_odbc.erl
index 593e9914..45241527 100644
--- a/src/mod_privacy_odbc.erl
+++ b/src/mod_privacy_odbc.erl
@@ -554,9 +554,12 @@ get_user_list(_, User, Server) ->
end.
+%% From is the sender, To is the destination.
+%% If Dir = out, User@Server is the sender account (From).
+%% If Dir = in, User@Server is the destination account (To).
check_packet(_, User, Server,
#userlist{list = List, needdb = NeedDb},
- {From, To, {xmlelement, PName, _, _}},
+ {From, To, {xmlelement, PName, Attrs, _}},
Dir) ->
case List of
[] ->
@@ -565,48 +568,36 @@ check_packet(_, User, Server,
PType = case PName of
"message" -> message;
"iq" -> iq;
- "presence" -> presence
+ "presence" ->
+ case xml:get_attr_s("type", Attrs) of
+ %% notification
+ "" -> presence;
+ "unavailable" -> presence;
+ %% subscribe, subscribed, unsubscribe,
+ %% unsubscribed, error, probe, or other
+ _ -> other
+ end
end,
- case {PType, Dir} of
- {message, in} ->
- LJID = jlib:jid_tolower(From),
- {Subscription, Groups} =
- case NeedDb of
- true -> ejabberd_hooks:run_fold(roster_get_jid_info, jlib:nameprep(Server), {none, []}, [User, Server, LJID]);
- false -> {[], []}
- end,
- check_packet_aux(List, message,
- LJID, Subscription, Groups);
- {iq, in} ->
- LJID = jlib:jid_tolower(From),
- {Subscription, Groups} =
- case NeedDb of
- true -> ejabberd_hooks:run_fold(roster_get_jid_info, jlib:nameprep(Server), {none, []}, [User, Server, LJID]);
- false -> {[], []}
- end,
- check_packet_aux(List, iq,
- LJID, Subscription, Groups);
- {presence, in} ->
- LJID = jlib:jid_tolower(From),
- {Subscription, Groups} =
- case NeedDb of
- true -> ejabberd_hooks:run_fold(roster_get_jid_info, jlib:nameprep(Server), {none, []}, [User, Server, LJID]);
- false -> {[], []}
- end,
- check_packet_aux(List, presence_in,
- LJID, Subscription, Groups);
- {presence, out} ->
- LJID = jlib:jid_tolower(To),
- {Subscription, Groups} =
- case NeedDb of
- true -> ejabberd_hooks:run_fold(roster_get_jid_info, jlib:nameprep(Server), {none, []}, [User, Server, LJID]);
- false -> {[], []}
- end,
- check_packet_aux(List, presence_out,
- LJID, Subscription, Groups);
- _ ->
- allow
- end
+ PType2 = case {PType, Dir} of
+ {message, in} -> message;
+ {iq, in} -> iq;
+ {presence, in} -> presence_in;
+ {presence, out} -> presence_out;
+ {_, _} -> other
+ end,
+ LJID = case Dir of
+ in -> jlib:jid_tolower(From);
+ out -> jlib:jid_tolower(To)
+ end,
+ {Subscription, Groups} =
+ case NeedDb of
+ true -> ejabberd_hooks:run_fold(roster_get_jid_info,
+ jlib:nameprep(Server),
+ {none, []},
+ [User, Server, LJID]);
+ false -> {[], []}
+ end,
+ check_packet_aux(List, PType2, LJID, Subscription, Groups)
end.
check_packet_aux([], _PType, _JID, _Subscription, _Groups) ->
@@ -646,7 +637,9 @@ is_ptype_match(Item, PType) ->
presence_in ->
Item#listitem.match_presence_in;
presence_out ->
- Item#listitem.match_presence_out
+ Item#listitem.match_presence_out;
+ other ->
+ false
end
end.