mirror of
https://github.com/processone/ejabberd.git
synced 2024-12-20 17:27:00 +01:00
* 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: 1834
This commit is contained in:
parent
978effade4
commit
2e511c78af
@ -1,3 +1,11 @@
|
||||
2009-01-20 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
|
||||
|
||||
2009-01-17 Mickael Remond <mremond@process-one.net>
|
||||
|
||||
* src/ejabberd_c2s.erl: Added comments.
|
||||
|
@ -322,7 +322,8 @@ process_active_set(LUser, LServer, {value, 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, ?ERR_ITEM_NOT_FOUND}
|
||||
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([{xmlelement, "item", Attrs, SubEls} | Els], Res) ->
|
||||
Type = xml:get_attr("type", Attrs),
|
||||
Value = xml:get_attr("value", Attrs),
|
||||
@ -524,6 +521,16 @@ parse_matches1(_Item, [{xmlelement, _, _, _} | _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) ->
|
||||
LUser = jlib:nodeprep(User),
|
||||
LServer = jlib:nameprep(Server),
|
||||
@ -537,8 +544,8 @@ get_user_list(_, User, Server) ->
|
||||
_ ->
|
||||
case lists:keysearch(Default, 1, Lists) of
|
||||
{value, {_, List}} ->
|
||||
SortedList = lists:keysort(#listitem.order, List),
|
||||
#userlist{name = Default, list = SortedList};
|
||||
NeedDb = is_list_needdb(List),
|
||||
#userlist{name = Default, list = List, needdb = NeedDb};
|
||||
_ ->
|
||||
#userlist{}
|
||||
end
|
||||
@ -549,7 +556,7 @@ get_user_list(_, User, Server) ->
|
||||
|
||||
|
||||
check_packet(_, User, Server,
|
||||
#userlist{list = List},
|
||||
#userlist{list = List, needdb = NeedDb},
|
||||
{From, To, {xmlelement, PName, _, _}},
|
||||
Dir) ->
|
||||
case List of
|
||||
@ -565,33 +572,37 @@ check_packet(_, User, Server,
|
||||
{message, in} ->
|
||||
LJID = jlib:jid_tolower(From),
|
||||
{Subscription, Groups} =
|
||||
ejabberd_hooks:run_fold(
|
||||
roster_get_jid_info, jlib:nameprep(Server),
|
||||
{none, []}, [User, Server, LJID]),
|
||||
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} =
|
||||
ejabberd_hooks:run_fold(
|
||||
roster_get_jid_info, jlib:nameprep(Server),
|
||||
{none, []}, [User, Server, LJID]),
|
||||
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} =
|
||||
ejabberd_hooks:run_fold(
|
||||
roster_get_jid_info, jlib:nameprep(Server),
|
||||
{none, []}, [User, Server, LJID]),
|
||||
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} =
|
||||
ejabberd_hooks:run_fold(
|
||||
roster_get_jid_info, jlib:nameprep(Server),
|
||||
{none, []}, [User, Server, LJID]),
|
||||
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);
|
||||
_ ->
|
||||
|
@ -34,4 +34,4 @@
|
||||
match_presence_out = false
|
||||
}).
|
||||
|
||||
-record(userlist, {name = none, list = []}).
|
||||
-record(userlist, {name = none, list = [], needdb = false }).
|
||||
|
@ -317,7 +317,8 @@ process_active_set(LUser, LServer, {value, 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, ?ERR_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([{xmlelement, "item", Attrs, SubEls} | Els], Res) ->
|
||||
Type = xml:get_attr("type", Attrs),
|
||||
Value = xml:get_attr("value", Attrs),
|
||||
@ -522,7 +519,15 @@ parse_matches1(_Item, [{xmlelement, _, _, _} | _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) ->
|
||||
LUser = jlib:nodeprep(User),
|
||||
@ -538,7 +543,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;
|
||||
@ -548,7 +554,7 @@ get_user_list(_, User, Server) ->
|
||||
|
||||
|
||||
check_packet(_, User, Server,
|
||||
#userlist{list = List},
|
||||
#userlist{list = List, needdb = NeedDb},
|
||||
{From, To, {xmlelement, PName, _, _}},
|
||||
Dir) ->
|
||||
case List of
|
||||
@ -564,33 +570,37 @@ check_packet(_, User, Server,
|
||||
{message, in} ->
|
||||
LJID = jlib:jid_tolower(From),
|
||||
{Subscription, Groups} =
|
||||
ejabberd_hooks:run_fold(
|
||||
roster_get_jid_info, jlib:nameprep(Server),
|
||||
{none, []}, [User, Server, LJID]),
|
||||
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} =
|
||||
ejabberd_hooks:run_fold(
|
||||
roster_get_jid_info, jlib:nameprep(Server),
|
||||
{none, []}, [User, Server, LJID]),
|
||||
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} =
|
||||
ejabberd_hooks:run_fold(
|
||||
roster_get_jid_info, jlib:nameprep(Server),
|
||||
{none, []}, [User, Server, LJID]),
|
||||
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} =
|
||||
ejabberd_hooks:run_fold(
|
||||
roster_get_jid_info, jlib:nameprep(Server),
|
||||
{none, []}, [User, Server, LJID]),
|
||||
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