25
1
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:
Badlop 2009-03-03 19:26:24 +00:00
parent 4046ecc99e
commit 890b1c4f60
4 changed files with 68 additions and 49 deletions

View File

@ -1,5 +1,11 @@
2009-03-03 Badlop <badlop@process-one.net> 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 * src/mod_muc/mod_muc_room.erl: Owner of a password protected room
must provide the password, like other participants (EJAB-867) must provide the password, like other participants (EJAB-867)

View File

@ -322,7 +322,8 @@ process_active_set(LUser, LServer, Name) ->
[#privacy{lists = Lists}] -> [#privacy{lists = Lists}] ->
case lists:keysearch(Name, 1, Lists) of case lists:keysearch(Name, 1, Lists) of
{value, {_, List}} -> {value, {_, List}} ->
{result, [], #userlist{name = Name, list = List}}; NeedDb = is_list_needdb(List),
{result, [], #userlist{name = Name, list = List, needdb = NeedDb}};
false -> false ->
{error, 'item-not-found'} {error, 'item-not-found'}
end end
@ -414,11 +415,7 @@ parse_items(Els) ->
parse_items([], Res) -> parse_items([], Res) ->
%% Sort the items by their 'order' attribute %% Sort the items by their 'order' attribute
%% 5 is the position of 'order' attribute in a #listitem tuple lists:keysort(#listitem.order, Res);
%% 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);
parse_items([El = #xmlel{name = item} | Els], Res) -> parse_items([El = #xmlel{name = item} | Els], Res) ->
Type = exmpp_xml:get_attribute_as_list(El, type, false), Type = exmpp_xml:get_attribute_as_list(El, type, false),
Value = exmpp_xml:get_attribute_as_list(El, value, 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) get_user_list(_, User, Server)
when is_binary(User), is_binary(Server) -> when is_binary(User), is_binary(Server) ->
try try
@ -555,7 +562,7 @@ get_user_list(_, User, Server)
check_packet(_, User, Server, check_packet(_, User, Server,
#userlist{list = List}, #userlist{list = List, needdb = NeedDb},
{From, To, #xmlel{name = PName}}, {From, To, #xmlel{name = PName}},
Dir) when Dir) when
PName =:= message ; PName =:= message ;
@ -569,37 +576,37 @@ check_packet(_, User, Server,
{message, in} -> {message, in} ->
LJID = jlib:short_prepd_jid(From), LJID = jlib:short_prepd_jid(From),
{Subscription, Groups} = {Subscription, Groups} =
ejabberd_hooks:run_fold( case NeedDb of
roster_get_jid_info, true -> ejabberd_hooks:run_fold(roster_get_jid_info, Server, {none, []}, [User, Server, From]);
Server, false -> {[], []}
{none, []}, [User, Server, From]), end,
check_packet_aux(List, message, check_packet_aux(List, message,
LJID, Subscription, Groups); LJID, Subscription, Groups);
{iq, in} -> {iq, in} ->
LJID = jlib:short_prepd_jid(From), LJID = jlib:short_prepd_jid(From),
{Subscription, Groups} = {Subscription, Groups} =
ejabberd_hooks:run_fold( case NeedDb of
roster_get_jid_info, true -> ejabberd_hooks:run_fold(roster_get_jid_info, Server, {none, []}, [User, Server, From]);
Server, false -> {[], []}
{none, []}, [User, Server, From]), end,
check_packet_aux(List, iq, check_packet_aux(List, iq,
LJID, Subscription, Groups); LJID, Subscription, Groups);
{presence, in} -> {presence, in} ->
LJID = jlib:short_prepd_jid(From), LJID = jlib:short_prepd_jid(From),
{Subscription, Groups} = {Subscription, Groups} =
ejabberd_hooks:run_fold( case NeedDb of
roster_get_jid_info, true -> ejabberd_hooks:run_fold(roster_get_jid_info, Server, {none, []}, [User, Server, From]);
Server, false -> {[], []}
{none, []}, [User, Server, From]), end,
check_packet_aux(List, presence_in, check_packet_aux(List, presence_in,
LJID, Subscription, Groups); LJID, Subscription, Groups);
{presence, out} -> {presence, out} ->
LJID = jlib:short_prepd_jid(To), LJID = jlib:short_prepd_jid(To),
{Subscription, Groups} = {Subscription, Groups} =
ejabberd_hooks:run_fold( case NeedDb of
roster_get_jid_info, true -> ejabberd_hooks:run_fold(roster_get_jid_info, Server, {none, []}, [User, Server, From]);
Server, false -> {[], []}
{none, []}, [User, Server, To]), end,
check_packet_aux(List, presence_out, check_packet_aux(List, presence_out,
LJID, Subscription, Groups); LJID, Subscription, Groups);
_ -> _ ->

View File

@ -34,4 +34,4 @@
match_presence_out = false match_presence_out = false
}). }).
-record(userlist, {name = none, list = []}). -record(userlist, {name = none, list = [], needdb = false }).

View File

@ -322,7 +322,8 @@ process_active_set(LUser, LServer, Name) ->
"match_presence_in", "match_presence_out"], "match_presence_in", "match_presence_out"],
RItems} -> RItems} ->
Items = lists:map(fun raw_to_item/1, 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'} {error, 'internal-server-error'}
end; end;
@ -415,11 +416,7 @@ parse_items(Els) ->
parse_items([], Res) -> parse_items([], Res) ->
%% Sort the items by their 'order' attribute %% Sort the items by their 'order' attribute
%% 5 is the position of 'order' attribute in a #listitem tuple lists:keysort(#listitem.order, Res);
%% 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);
parse_items([El = #xmlel{name = item} | Els], Res) -> parse_items([El = #xmlel{name = item} | Els], Res) ->
Type = exmpp_xml:get_attribute_as_list(El, type, false), Type = exmpp_xml:get_attribute_as_list(El, type, false),
Value = exmpp_xml:get_attribute_as_list(El, value, 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) get_user_list(_, User, Server)
when is_binary(User), is_binary(Server) -> when is_binary(User), is_binary(Server) ->
@ -540,7 +545,8 @@ get_user_list(_, User, Server)
"match_presence_in", "match_presence_out"], "match_presence_in", "match_presence_out"],
RItems} -> RItems} ->
Items = lists:map(fun raw_to_item/1, 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{} #userlist{}
end; end;
@ -554,7 +560,7 @@ get_user_list(_, User, Server)
check_packet(_, User, Server, check_packet(_, User, Server,
#userlist{list = List}, #userlist{list = List, needdb = NeedDb},
{From, To, #xmlel{name = PName}}, {From, To, #xmlel{name = PName}},
Dir) when Dir) when
PName =:= message ; PName =:= message ;
@ -568,37 +574,37 @@ check_packet(_, User, Server,
{message, in} -> {message, in} ->
LJID = jlib:short_prepd_jid(From), LJID = jlib:short_prepd_jid(From),
{Subscription, Groups} = {Subscription, Groups} =
ejabberd_hooks:run_fold( case NeedDb of
roster_get_jid_info, true -> ejabberd_hooks:run_fold(roster_get_jid_info, Server, {none, []}, [User, Server, LJID]);
Server, false -> {[], []}
{none, []}, [User, Server, From]), end,
check_packet_aux(List, message, check_packet_aux(List, message,
LJID, Subscription, Groups); LJID, Subscription, Groups);
{iq, in} -> {iq, in} ->
LJID = jlib:short_prepd_jid(From), LJID = jlib:short_prepd_jid(From),
{Subscription, Groups} = {Subscription, Groups} =
ejabberd_hooks:run_fold( case NeedDb of
roster_get_jid_info, true -> ejabberd_hooks:run_fold(roster_get_jid_info, Server, {none, []}, [User, Server, LJID]);
Server, false -> {[], []}
{none, []}, [User, Server, From]), end,
check_packet_aux(List, iq, check_packet_aux(List, iq,
LJID, Subscription, Groups); LJID, Subscription, Groups);
{presence, in} -> {presence, in} ->
LJID = jlib:short_prepd_jid(From), LJID = jlib:short_prepd_jid(From),
{Subscription, Groups} = {Subscription, Groups} =
ejabberd_hooks:run_fold( case NeedDb of
roster_get_jid_info, true -> ejabberd_hooks:run_fold(roster_get_jid_info, Server, {none, []}, [User, Server, LJID]);
Server, false -> {[], []}
{none, []}, [User, Server, From]), end,
check_packet_aux(List, presence_in, check_packet_aux(List, presence_in,
LJID, Subscription, Groups); LJID, Subscription, Groups);
{presence, out} -> {presence, out} ->
LJID = jlib:short_prepd_jid(To), LJID = jlib:short_prepd_jid(To),
{Subscription, Groups} = {Subscription, Groups} =
ejabberd_hooks:run_fold( case NeedDb of
roster_get_jid_info, true -> ejabberd_hooks:run_fold(roster_get_jid_info, jlib:nameprep(Server), {none, []}, [User, Server, LJID]);
Server, false -> {[], []}
{none, []}, [User, Server, To]), end,
check_packet_aux(List, presence_out, check_packet_aux(List, presence_out,
LJID, Subscription, Groups); LJID, Subscription, Groups);
_ -> _ ->