mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-26 16:26:24 +01:00
Merge 1834 from trunk.
* src/mod_privacy.erl: Only run roster_get_jid_info if privacy list has subscription or group (thanks to George Hazan)(EJAB-851). Sort items in privacy list by order before storing (EJAB-848) * src/mod_privacy.hrl: Likewise * src/mod_privacy_odbc.erl: Likewise SVN Revision: 1947
This commit is contained in:
parent
4046ecc99e
commit
890b1c4f60
@ -1,5 +1,11 @@
|
||||
2009-03-03 Badlop <badlop@process-one.net>
|
||||
|
||||
* src/mod_privacy.erl: Only run roster_get_jid_info if privacy
|
||||
list has subscription or group (thanks to George Hazan)(EJAB-851).
|
||||
Sort items in privacy list by order before storing (EJAB-848)
|
||||
* src/mod_privacy.hrl: Likewise
|
||||
* src/mod_privacy_odbc.erl: Likewise
|
||||
|
||||
* src/mod_muc/mod_muc_room.erl: Owner of a password protected room
|
||||
must provide the password, like other participants (EJAB-867)
|
||||
|
||||
|
@ -322,7 +322,8 @@ process_active_set(LUser, LServer, Name) ->
|
||||
[#privacy{lists = Lists}] ->
|
||||
case lists:keysearch(Name, 1, Lists) of
|
||||
{value, {_, List}} ->
|
||||
{result, [], #userlist{name = Name, list = List}};
|
||||
NeedDb = is_list_needdb(List),
|
||||
{result, [], #userlist{name = Name, list = List, needdb = NeedDb}};
|
||||
false ->
|
||||
{error, 'item-not-found'}
|
||||
end
|
||||
@ -414,11 +415,7 @@ parse_items(Els) ->
|
||||
|
||||
parse_items([], Res) ->
|
||||
%% Sort the items by their 'order' attribute
|
||||
%% 5 is the position of 'order' attribute in a #listitem tuple
|
||||
%% This integer can be calculated at runtime with:
|
||||
%% 2 + length(lists:takewhile(fun(E) -> E =/= order end,
|
||||
%% record_info(fields, listitem))),
|
||||
lists:keysort(5, Res);
|
||||
lists:keysort(#listitem.order, Res);
|
||||
parse_items([El = #xmlel{name = item} | Els], Res) ->
|
||||
Type = exmpp_xml:get_attribute_as_list(El, type, false),
|
||||
Value = exmpp_xml:get_attribute_as_list(El, value, false),
|
||||
@ -524,6 +521,16 @@ parse_matches1(_Item, [#xmlel{} | _Els]) ->
|
||||
|
||||
|
||||
|
||||
is_list_needdb(Items) ->
|
||||
lists:any(
|
||||
fun(X) ->
|
||||
case X#listitem.type of
|
||||
subscription -> true;
|
||||
group -> true;
|
||||
_ -> false
|
||||
end
|
||||
end, Items).
|
||||
|
||||
get_user_list(_, User, Server)
|
||||
when is_binary(User), is_binary(Server) ->
|
||||
try
|
||||
@ -555,7 +562,7 @@ get_user_list(_, User, Server)
|
||||
|
||||
|
||||
check_packet(_, User, Server,
|
||||
#userlist{list = List},
|
||||
#userlist{list = List, needdb = NeedDb},
|
||||
{From, To, #xmlel{name = PName}},
|
||||
Dir) when
|
||||
PName =:= message ;
|
||||
@ -569,37 +576,37 @@ check_packet(_, User, Server,
|
||||
{message, in} ->
|
||||
LJID = jlib:short_prepd_jid(From),
|
||||
{Subscription, Groups} =
|
||||
ejabberd_hooks:run_fold(
|
||||
roster_get_jid_info,
|
||||
Server,
|
||||
{none, []}, [User, Server, From]),
|
||||
case NeedDb of
|
||||
true -> ejabberd_hooks:run_fold(roster_get_jid_info, Server, {none, []}, [User, Server, From]);
|
||||
false -> {[], []}
|
||||
end,
|
||||
check_packet_aux(List, message,
|
||||
LJID, Subscription, Groups);
|
||||
{iq, in} ->
|
||||
LJID = jlib:short_prepd_jid(From),
|
||||
{Subscription, Groups} =
|
||||
ejabberd_hooks:run_fold(
|
||||
roster_get_jid_info,
|
||||
Server,
|
||||
{none, []}, [User, Server, From]),
|
||||
case NeedDb of
|
||||
true -> ejabberd_hooks:run_fold(roster_get_jid_info, Server, {none, []}, [User, Server, From]);
|
||||
false -> {[], []}
|
||||
end,
|
||||
check_packet_aux(List, iq,
|
||||
LJID, Subscription, Groups);
|
||||
{presence, in} ->
|
||||
LJID = jlib:short_prepd_jid(From),
|
||||
{Subscription, Groups} =
|
||||
ejabberd_hooks:run_fold(
|
||||
roster_get_jid_info,
|
||||
Server,
|
||||
{none, []}, [User, Server, From]),
|
||||
case NeedDb of
|
||||
true -> ejabberd_hooks:run_fold(roster_get_jid_info, Server, {none, []}, [User, Server, From]);
|
||||
false -> {[], []}
|
||||
end,
|
||||
check_packet_aux(List, presence_in,
|
||||
LJID, Subscription, Groups);
|
||||
{presence, out} ->
|
||||
LJID = jlib:short_prepd_jid(To),
|
||||
{Subscription, Groups} =
|
||||
ejabberd_hooks:run_fold(
|
||||
roster_get_jid_info,
|
||||
Server,
|
||||
{none, []}, [User, Server, To]),
|
||||
case NeedDb of
|
||||
true -> ejabberd_hooks:run_fold(roster_get_jid_info, Server, {none, []}, [User, Server, From]);
|
||||
false -> {[], []}
|
||||
end,
|
||||
check_packet_aux(List, presence_out,
|
||||
LJID, Subscription, Groups);
|
||||
_ ->
|
||||
|
@ -34,4 +34,4 @@
|
||||
match_presence_out = false
|
||||
}).
|
||||
|
||||
-record(userlist, {name = none, list = []}).
|
||||
-record(userlist, {name = none, list = [], needdb = false }).
|
||||
|
@ -322,7 +322,8 @@ process_active_set(LUser, LServer, Name) ->
|
||||
"match_presence_in", "match_presence_out"],
|
||||
RItems} ->
|
||||
Items = lists:map(fun raw_to_item/1, RItems),
|
||||
{result, [], #userlist{name = Name, list = Items}};
|
||||
NeedDb = is_list_needdb(Items),
|
||||
{result, [], #userlist{name = Name, list = Items, needdb = NeedDb}};
|
||||
_ ->
|
||||
{error, 'internal-server-error'}
|
||||
end;
|
||||
@ -415,11 +416,7 @@ parse_items(Els) ->
|
||||
|
||||
parse_items([], Res) ->
|
||||
%% Sort the items by their 'order' attribute
|
||||
%% 5 is the position of 'order' attribute in a #listitem tuple
|
||||
%% This integer can be calculated at runtime with:
|
||||
%% 2 + length(lists:takewhile(fun(E) -> E =/= order end,
|
||||
%% record_info(fields, listitem))),
|
||||
lists:keysort(5, Res);
|
||||
lists:keysort(#listitem.order, Res);
|
||||
parse_items([El = #xmlel{name = item} | Els], Res) ->
|
||||
Type = exmpp_xml:get_attribute_as_list(El, type, false),
|
||||
Value = exmpp_xml:get_attribute_as_list(El, value, false),
|
||||
@ -523,7 +520,15 @@ parse_matches1(_Item, [#xmlel{} | _Els]) ->
|
||||
|
||||
|
||||
|
||||
|
||||
is_list_needdb(Items) ->
|
||||
lists:any(
|
||||
fun(X) ->
|
||||
case X#listitem.type of
|
||||
subscription -> true;
|
||||
group -> true;
|
||||
_ -> false
|
||||
end
|
||||
end, Items).
|
||||
|
||||
get_user_list(_, User, Server)
|
||||
when is_binary(User), is_binary(Server) ->
|
||||
@ -540,7 +545,8 @@ get_user_list(_, User, Server)
|
||||
"match_presence_in", "match_presence_out"],
|
||||
RItems} ->
|
||||
Items = lists:map(fun raw_to_item/1, RItems),
|
||||
#userlist{name = Default, list = Items};
|
||||
NeedDb = is_list_needdb(Items),
|
||||
#userlist{name = Default, list = Items, needdb = NeedDb};
|
||||
_ ->
|
||||
#userlist{}
|
||||
end;
|
||||
@ -554,7 +560,7 @@ get_user_list(_, User, Server)
|
||||
|
||||
|
||||
check_packet(_, User, Server,
|
||||
#userlist{list = List},
|
||||
#userlist{list = List, needdb = NeedDb},
|
||||
{From, To, #xmlel{name = PName}},
|
||||
Dir) when
|
||||
PName =:= message ;
|
||||
@ -568,37 +574,37 @@ check_packet(_, User, Server,
|
||||
{message, in} ->
|
||||
LJID = jlib:short_prepd_jid(From),
|
||||
{Subscription, Groups} =
|
||||
ejabberd_hooks:run_fold(
|
||||
roster_get_jid_info,
|
||||
Server,
|
||||
{none, []}, [User, Server, From]),
|
||||
case NeedDb of
|
||||
true -> ejabberd_hooks:run_fold(roster_get_jid_info, Server, {none, []}, [User, Server, LJID]);
|
||||
false -> {[], []}
|
||||
end,
|
||||
check_packet_aux(List, message,
|
||||
LJID, Subscription, Groups);
|
||||
{iq, in} ->
|
||||
LJID = jlib:short_prepd_jid(From),
|
||||
{Subscription, Groups} =
|
||||
ejabberd_hooks:run_fold(
|
||||
roster_get_jid_info,
|
||||
Server,
|
||||
{none, []}, [User, Server, From]),
|
||||
case NeedDb of
|
||||
true -> ejabberd_hooks:run_fold(roster_get_jid_info, Server, {none, []}, [User, Server, LJID]);
|
||||
false -> {[], []}
|
||||
end,
|
||||
check_packet_aux(List, iq,
|
||||
LJID, Subscription, Groups);
|
||||
{presence, in} ->
|
||||
LJID = jlib:short_prepd_jid(From),
|
||||
{Subscription, Groups} =
|
||||
ejabberd_hooks:run_fold(
|
||||
roster_get_jid_info,
|
||||
Server,
|
||||
{none, []}, [User, Server, From]),
|
||||
case NeedDb of
|
||||
true -> ejabberd_hooks:run_fold(roster_get_jid_info, Server, {none, []}, [User, Server, LJID]);
|
||||
false -> {[], []}
|
||||
end,
|
||||
check_packet_aux(List, presence_in,
|
||||
LJID, Subscription, Groups);
|
||||
{presence, out} ->
|
||||
LJID = jlib:short_prepd_jid(To),
|
||||
{Subscription, Groups} =
|
||||
ejabberd_hooks:run_fold(
|
||||
roster_get_jid_info,
|
||||
Server,
|
||||
{none, []}, [User, Server, To]),
|
||||
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);
|
||||
_ ->
|
||||
|
Loading…
Reference in New Issue
Block a user