mirror of
https://github.com/processone/ejabberd.git
synced 2024-12-22 17:28:25 +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>
|
2009-01-17 Mickael Remond <mremond@process-one.net>
|
||||||
|
|
||||||
* src/ejabberd_c2s.erl: Added comments.
|
* src/ejabberd_c2s.erl: Added comments.
|
||||||
|
@ -322,7 +322,8 @@ process_active_set(LUser, LServer, {value, 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, ?ERR_ITEM_NOT_FOUND}
|
{error, ?ERR_ITEM_NOT_FOUND}
|
||||||
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([{xmlelement, "item", Attrs, SubEls} | Els], Res) ->
|
parse_items([{xmlelement, "item", Attrs, SubEls} | Els], Res) ->
|
||||||
Type = xml:get_attr("type", Attrs),
|
Type = xml:get_attr("type", Attrs),
|
||||||
Value = xml:get_attr("value", 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) ->
|
get_user_list(_, User, Server) ->
|
||||||
LUser = jlib:nodeprep(User),
|
LUser = jlib:nodeprep(User),
|
||||||
LServer = jlib:nameprep(Server),
|
LServer = jlib:nameprep(Server),
|
||||||
@ -537,8 +544,8 @@ get_user_list(_, User, Server) ->
|
|||||||
_ ->
|
_ ->
|
||||||
case lists:keysearch(Default, 1, Lists) of
|
case lists:keysearch(Default, 1, Lists) of
|
||||||
{value, {_, List}} ->
|
{value, {_, List}} ->
|
||||||
SortedList = lists:keysort(#listitem.order, List),
|
NeedDb = is_list_needdb(List),
|
||||||
#userlist{name = Default, list = SortedList};
|
#userlist{name = Default, list = List, needdb = NeedDb};
|
||||||
_ ->
|
_ ->
|
||||||
#userlist{}
|
#userlist{}
|
||||||
end
|
end
|
||||||
@ -549,7 +556,7 @@ get_user_list(_, User, Server) ->
|
|||||||
|
|
||||||
|
|
||||||
check_packet(_, User, Server,
|
check_packet(_, User, Server,
|
||||||
#userlist{list = List},
|
#userlist{list = List, needdb = NeedDb},
|
||||||
{From, To, {xmlelement, PName, _, _}},
|
{From, To, {xmlelement, PName, _, _}},
|
||||||
Dir) ->
|
Dir) ->
|
||||||
case List of
|
case List of
|
||||||
@ -565,33 +572,37 @@ check_packet(_, User, Server,
|
|||||||
{message, in} ->
|
{message, in} ->
|
||||||
LJID = jlib:jid_tolower(From),
|
LJID = jlib:jid_tolower(From),
|
||||||
{Subscription, Groups} =
|
{Subscription, Groups} =
|
||||||
ejabberd_hooks:run_fold(
|
case NeedDb of
|
||||||
roster_get_jid_info, jlib:nameprep(Server),
|
true -> ejabberd_hooks:run_fold(roster_get_jid_info, jlib:nameprep(Server), {none, []}, [User, Server, LJID]);
|
||||||
{none, []}, [User, Server, LJID]),
|
false -> {[], []}
|
||||||
|
end,
|
||||||
check_packet_aux(List, message,
|
check_packet_aux(List, message,
|
||||||
LJID, Subscription, Groups);
|
LJID, Subscription, Groups);
|
||||||
{iq, in} ->
|
{iq, in} ->
|
||||||
LJID = jlib:jid_tolower(From),
|
LJID = jlib:jid_tolower(From),
|
||||||
{Subscription, Groups} =
|
{Subscription, Groups} =
|
||||||
ejabberd_hooks:run_fold(
|
case NeedDb of
|
||||||
roster_get_jid_info, jlib:nameprep(Server),
|
true -> ejabberd_hooks:run_fold(roster_get_jid_info, jlib:nameprep(Server), {none, []}, [User, Server, LJID]);
|
||||||
{none, []}, [User, Server, LJID]),
|
false -> {[], []}
|
||||||
|
end,
|
||||||
check_packet_aux(List, iq,
|
check_packet_aux(List, iq,
|
||||||
LJID, Subscription, Groups);
|
LJID, Subscription, Groups);
|
||||||
{presence, in} ->
|
{presence, in} ->
|
||||||
LJID = jlib:jid_tolower(From),
|
LJID = jlib:jid_tolower(From),
|
||||||
{Subscription, Groups} =
|
{Subscription, Groups} =
|
||||||
ejabberd_hooks:run_fold(
|
case NeedDb of
|
||||||
roster_get_jid_info, jlib:nameprep(Server),
|
true -> ejabberd_hooks:run_fold(roster_get_jid_info, jlib:nameprep(Server), {none, []}, [User, Server, LJID]);
|
||||||
{none, []}, [User, Server, LJID]),
|
false -> {[], []}
|
||||||
|
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:jid_tolower(To),
|
LJID = jlib:jid_tolower(To),
|
||||||
{Subscription, Groups} =
|
{Subscription, Groups} =
|
||||||
ejabberd_hooks:run_fold(
|
case NeedDb of
|
||||||
roster_get_jid_info, jlib:nameprep(Server),
|
true -> ejabberd_hooks:run_fold(roster_get_jid_info, jlib:nameprep(Server), {none, []}, [User, Server, LJID]);
|
||||||
{none, []}, [User, Server, LJID]),
|
false -> {[], []}
|
||||||
|
end,
|
||||||
check_packet_aux(List, presence_out,
|
check_packet_aux(List, presence_out,
|
||||||
LJID, Subscription, Groups);
|
LJID, Subscription, Groups);
|
||||||
_ ->
|
_ ->
|
||||||
|
@ -34,4 +34,4 @@
|
|||||||
match_presence_out = false
|
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"],
|
"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, ?ERR_INTERNAL_SERVER_ERROR}
|
{error, ?ERR_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([{xmlelement, "item", Attrs, SubEls} | Els], Res) ->
|
parse_items([{xmlelement, "item", Attrs, SubEls} | Els], Res) ->
|
||||||
Type = xml:get_attr("type", Attrs),
|
Type = xml:get_attr("type", Attrs),
|
||||||
Value = xml:get_attr("value", 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) ->
|
get_user_list(_, User, Server) ->
|
||||||
LUser = jlib:nodeprep(User),
|
LUser = jlib:nodeprep(User),
|
||||||
@ -538,7 +543,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;
|
||||||
@ -548,7 +554,7 @@ get_user_list(_, User, Server) ->
|
|||||||
|
|
||||||
|
|
||||||
check_packet(_, User, Server,
|
check_packet(_, User, Server,
|
||||||
#userlist{list = List},
|
#userlist{list = List, needdb = NeedDb},
|
||||||
{From, To, {xmlelement, PName, _, _}},
|
{From, To, {xmlelement, PName, _, _}},
|
||||||
Dir) ->
|
Dir) ->
|
||||||
case List of
|
case List of
|
||||||
@ -564,33 +570,37 @@ check_packet(_, User, Server,
|
|||||||
{message, in} ->
|
{message, in} ->
|
||||||
LJID = jlib:jid_tolower(From),
|
LJID = jlib:jid_tolower(From),
|
||||||
{Subscription, Groups} =
|
{Subscription, Groups} =
|
||||||
ejabberd_hooks:run_fold(
|
case NeedDb of
|
||||||
roster_get_jid_info, jlib:nameprep(Server),
|
true -> ejabberd_hooks:run_fold(roster_get_jid_info, jlib:nameprep(Server), {none, []}, [User, Server, LJID]);
|
||||||
{none, []}, [User, Server, LJID]),
|
false -> {[], []}
|
||||||
|
end,
|
||||||
check_packet_aux(List, message,
|
check_packet_aux(List, message,
|
||||||
LJID, Subscription, Groups);
|
LJID, Subscription, Groups);
|
||||||
{iq, in} ->
|
{iq, in} ->
|
||||||
LJID = jlib:jid_tolower(From),
|
LJID = jlib:jid_tolower(From),
|
||||||
{Subscription, Groups} =
|
{Subscription, Groups} =
|
||||||
ejabberd_hooks:run_fold(
|
case NeedDb of
|
||||||
roster_get_jid_info, jlib:nameprep(Server),
|
true -> ejabberd_hooks:run_fold(roster_get_jid_info, jlib:nameprep(Server), {none, []}, [User, Server, LJID]);
|
||||||
{none, []}, [User, Server, LJID]),
|
false -> {[], []}
|
||||||
|
end,
|
||||||
check_packet_aux(List, iq,
|
check_packet_aux(List, iq,
|
||||||
LJID, Subscription, Groups);
|
LJID, Subscription, Groups);
|
||||||
{presence, in} ->
|
{presence, in} ->
|
||||||
LJID = jlib:jid_tolower(From),
|
LJID = jlib:jid_tolower(From),
|
||||||
{Subscription, Groups} =
|
{Subscription, Groups} =
|
||||||
ejabberd_hooks:run_fold(
|
case NeedDb of
|
||||||
roster_get_jid_info, jlib:nameprep(Server),
|
true -> ejabberd_hooks:run_fold(roster_get_jid_info, jlib:nameprep(Server), {none, []}, [User, Server, LJID]);
|
||||||
{none, []}, [User, Server, LJID]),
|
false -> {[], []}
|
||||||
|
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:jid_tolower(To),
|
LJID = jlib:jid_tolower(To),
|
||||||
{Subscription, Groups} =
|
{Subscription, Groups} =
|
||||||
ejabberd_hooks:run_fold(
|
case NeedDb of
|
||||||
roster_get_jid_info, jlib:nameprep(Server),
|
true -> ejabberd_hooks:run_fold(roster_get_jid_info, jlib:nameprep(Server), {none, []}, [User, Server, LJID]);
|
||||||
{none, []}, [User, Server, LJID]),
|
false -> {[], []}
|
||||||
|
end,
|
||||||
check_packet_aux(List, presence_out,
|
check_packet_aux(List, presence_out,
|
||||||
LJID, Subscription, Groups);
|
LJID, Subscription, Groups);
|
||||||
_ ->
|
_ ->
|
||||||
|
Loading…
Reference in New Issue
Block a user