25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-26 16:26:24 +01:00

Convert to exmpp.

PR:		EJABP-1
Submitted by:	Pablo Polvorin <pablo.polvorin@process-one.net>

SVN Revision: 1606
This commit is contained in:
Jean-Sébastien Pédron 2008-10-06 15:01:36 +00:00
parent 5ceffdd5a7
commit 3f8a303286
3 changed files with 382 additions and 346 deletions

View File

@ -10,6 +10,9 @@
* src/mod_roster_odbc.erl (get_jid_info/4): Fix a confusion between * src/mod_roster_odbc.erl (get_jid_info/4): Fix a confusion between
#jid and tuples. Thanks to Pablo Polvorin! #jid and tuples. Thanks to Pablo Polvorin!
* src/mod_privacy.erl, src/mod_privacy_odbc.erl: Convert to exmpp.
Thanks to Pablo Polvorin!
2008-10-02 Jean-Sébastien Pédron <js.pedron@meetic-corp.com> 2008-10-02 Jean-Sébastien Pédron <js.pedron@meetic-corp.com>
* src/mod_roster_odbc.erl: Fix a bug where a JID represented as a * src/mod_roster_odbc.erl: Fix a bug where a JID represented as a

View File

@ -37,8 +37,9 @@
check_packet/6, check_packet/6,
updated_list/3]). updated_list/3]).
-include_lib("exmpp/include/exmpp.hrl").
-include("ejabberd.hrl"). -include("ejabberd.hrl").
-include("jlib.hrl").
-include("mod_privacy.hrl"). -include("mod_privacy.hrl").
@ -73,102 +74,93 @@ stop(Host) ->
?MODULE, updated_list, 50), ?MODULE, updated_list, 50),
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_PRIVACY). gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_PRIVACY).
process_iq(_From, _To, IQ) -> process_iq(_From, _To, IQ_Rec) ->
SubEl = IQ#iq.sub_el, exmpp_iq:error(IQ_Rec, 'not-allowed').
IQ#iq{type = error, sub_el = [SubEl, ?ERR_NOT_ALLOWED]}.
process_iq_get(_, From, _To, #iq{sub_el = SubEl}, process_iq_get(_, From, _To, #iq{payload = SubEl},
#userlist{name = Active}) -> #userlist{name = Active}) ->
#jid{luser = LUser, lserver = LServer} = From, #jid{lnode = LUser, ldomain = LServer} = From,
{xmlelement, _, _, Els} = SubEl, case exmpp_xml:get_child_elements(SubEl) of
case xml:remove_cdata(Els) of
[] -> [] ->
process_lists_get(LUser, LServer, Active); process_lists_get(LUser, LServer, Active);
[{xmlelement, Name, Attrs, _SubEls}] -> [#xmlel{name = Name} = Child] ->
case Name of case Name of
"list" -> list ->
ListName = xml:get_attr("name", Attrs), ListName = exmpp_xml:get_attribute(Child, name, false),
process_list_get(LUser, LServer, ListName); process_list_get(LUser, LServer, ListName);
_ -> _ ->
{error, ?ERR_BAD_REQUEST} {error, 'bad-request'}
end; end;
_ -> _ ->
{error, ?ERR_BAD_REQUEST} {error, 'bad-request'}
end. end.
process_lists_get(LUser, LServer, Active) -> process_lists_get(LUser, LServer, Active) ->
case catch mnesia:dirty_read(privacy, {LUser, LServer}) of case catch mnesia:dirty_read(privacy, {LUser, LServer}) of
{'EXIT', _Reason} -> {'EXIT', _Reason} ->
{error, ?ERR_INTERNAL_SERVER_ERROR}; {error, 'internal-server-error'};
[] -> [] ->
{result, [{xmlelement, "query", [{"xmlns", ?NS_PRIVACY}], []}]}; {result, #xmlel{ns = ?NS_PRIVACY, name = 'query'}};
[#privacy{default = Default, lists = Lists}] -> [#privacy{default = Default, lists = Lists}] ->
case Lists of case Lists of
[] -> [] ->
{result, [{xmlelement, "query", {result, #xmlel{ns = ?NS_PRIVACY, name = 'query'}};
[{"xmlns", ?NS_PRIVACY}], []}]};
_ -> _ ->
LItems = lists:map( LItems = lists:map(
fun({N, _}) -> fun({N, _}) ->
{xmlelement, "list", exmpp_xml:set_attribute(#xmlel{ns = ?NS_PRIVACY, name = list}, name, N)
[{"name", N}], []}
end, Lists), end, Lists),
DItems = DItems =
case Default of case Default of
none -> none ->
LItems; LItems;
_ -> _ ->
[{xmlelement, "default", [exmpp_xml:set_attribute(#xmlel{ns = ?NS_PRIVACY, name = default}, name, Default) | LItems]
[{"name", Default}], []} | LItems]
end, end,
ADItems = ADItems =
case Active of case Active of
none -> none ->
DItems; DItems;
_ -> _ ->
[{xmlelement, "active", [exmpp_xml:set_attribute(#xmlel{ns = ?NS_PRIVACY, name = active}, name, Active) | DItems]
[{"name", Active}], []} | DItems]
end, end,
{result, {result, #xmlel{ns = ?NS_PRIVACY, name = 'query', children = ADItems}}
[{xmlelement, "query", [{"xmlns", ?NS_PRIVACY}],
ADItems}]}
end end
end. end.
process_list_get(LUser, LServer, {value, Name}) -> process_list_get(_LUser, _LServer, false) ->
{error, 'bad-request'};
process_list_get(LUser, LServer, Name) ->
case catch mnesia:dirty_read(privacy, {LUser, LServer}) of case catch mnesia:dirty_read(privacy, {LUser, LServer}) of
{'EXIT', _Reason} -> {'EXIT', _Reason} ->
{error, ?ERR_INTERNAL_SERVER_ERROR}; {error, 'internal-server-error'};
[] -> [] ->
{error, ?ERR_ITEM_NOT_FOUND}; {error, 'item-not-found'};
%{result, [{xmlelement, "query", [{"xmlns", ?NS_PRIVACY}], []}]}; %{result, [{xmlelement, "query", [{"xmlns", ?NS_PRIVACY}], []}]};
[#privacy{lists = Lists}] -> [#privacy{lists = Lists}] ->
case lists:keysearch(Name, 1, Lists) of case lists:keysearch(Name, 1, Lists) of
{value, {_, List}} -> {value, {_, List}} ->
LItems = lists:map(fun item_to_xml/1, List), LItems = lists:map(fun item_to_xml/1, List),
{result, ListEl = exmpp_xml:set_attribute(#xmlel{ns = ?NS_PRIVACY, name = list, children = LItems}, name, Name),
[{xmlelement, "query", [{"xmlns", ?NS_PRIVACY}], {result,#xmlel{ns = ?NS_PRIVACY, name = 'query', children = [ListEl]}};
[{xmlelement, "list",
[{"name", Name}], LItems}]}]};
_ -> _ ->
{error, ?ERR_ITEM_NOT_FOUND} {error, 'item-not-found'}
end end
end; end.
process_list_get(_LUser, _LServer, false) ->
{error, ?ERR_BAD_REQUEST}.
item_to_xml(Item) -> item_to_xml(Item) ->
Attrs1 = [{"action", action_to_list(Item#listitem.action)}, Attrs1 = [#xmlattr{name = 'action', value = action_to_list(Item#listitem.action)},
{"order", order_to_list(Item#listitem.order)}], #xmlattr{name = 'order', value = order_to_list(Item#listitem.order)}],
Attrs2 = case Item#listitem.type of Attrs2 = case Item#listitem.type of
none -> none ->
Attrs1; Attrs1;
Type -> Type ->
[{"type", type_to_list(Item#listitem.type)}, [#xmlattr{name = 'type', value = type_to_list(Item#listitem.type)},
{"value", value_to_list(Type, Item#listitem.value)} | #xmlattr{name = 'value', value = value_to_list(Type, Item#listitem.value)} |
Attrs1] Attrs1]
end, end,
SubEls = case Item#listitem.match_all of SubEls = case Item#listitem.match_all of
@ -177,31 +169,31 @@ item_to_xml(Item) ->
false -> false ->
SE1 = case Item#listitem.match_iq of SE1 = case Item#listitem.match_iq of
true -> true ->
[{xmlelement, "iq", [], []}]; [#xmlel{ns = ?NS_PRIVACY, name = iq}];
false -> false ->
[] []
end, end,
SE2 = case Item#listitem.match_message of SE2 = case Item#listitem.match_message of
true -> true ->
[{xmlelement, "message", [], []} | SE1]; [#xmlel{ns = ?NS_PRIVACY, name = message} | SE1];
false -> false ->
SE1 SE1
end, end,
SE3 = case Item#listitem.match_presence_in of SE3 = case Item#listitem.match_presence_in of
true -> true ->
[{xmlelement, "presence-in", [], []} | SE2]; [#xmlel{ns = ?NS_PRIVACY, name = 'presence-in'} | SE2];
false -> false ->
SE2 SE2
end, end,
SE4 = case Item#listitem.match_presence_out of SE4 = case Item#listitem.match_presence_out of
true -> true ->
[{xmlelement, "presence-out", [], []} | SE3]; [#xmlel{ns = ?NS_PRIVACY, name = 'presence-out'} | SE3];
false -> false ->
SE3 SE3
end, end,
SE4 SE4
end, end,
{xmlelement, "item", Attrs2, SubEls}. exmpp_xml:set_attributes(#xmlel{ns = ?NS_PRIVACY, name = item, children = SubEls}, Attrs2).
action_to_list(Action) -> action_to_list(Action) ->
@ -222,7 +214,9 @@ type_to_list(Type) ->
value_to_list(Type, Val) -> value_to_list(Type, Val) ->
case Type of case Type of
jid -> jlib:jid_to_string(Val); jid ->
{N, D, R} = Val,
exmpp_jid:jid_to_list(N, D, R);
group -> Val; group -> Val;
subscription -> subscription ->
case Val of case Val of
@ -243,53 +237,27 @@ list_to_action(S) ->
process_iq_set(_, From, _To, #iq{sub_el = SubEl}) -> process_iq_set(_, From, _To, #iq{payload = SubEl}) ->
#jid{luser = LUser, lserver = LServer} = From, #jid{lnode = LUser, ldomain = LServer} = From,
{xmlelement, _, _, Els} = SubEl, case exmpp_xml:get_child_elements(SubEl) of
case xml:remove_cdata(Els) of [#xmlel{name = Name} = Child] ->
[{xmlelement, Name, Attrs, SubEls}] -> ListName = exmpp_xml:get_attribute(Child, 'name', false),
ListName = xml:get_attr("name", Attrs),
case Name of case Name of
"list" -> list ->
process_list_set(LUser, LServer, ListName, process_list_set(LUser, LServer, ListName,
xml:remove_cdata(SubEls)); exmpp_xml:get_child_elements(Child));
"active" -> active ->
process_active_set(LUser, LServer, ListName); process_active_set(LUser, LServer, ListName);
"default" -> default ->
process_default_set(LUser, LServer, ListName); process_default_set(LUser, LServer, ListName);
_ -> _ ->
{error, ?ERR_BAD_REQUEST} {error, 'bad-request'}
end; end;
_ -> _ ->
{error, ?ERR_BAD_REQUEST} {error, 'bad-request'}
end. end.
process_default_set(LUser, LServer, {value, Name}) ->
F = fun() ->
case mnesia:read({privacy, {LUser, LServer}}) of
[] ->
{error, ?ERR_ITEM_NOT_FOUND};
[#privacy{lists = Lists} = P] ->
case lists:keymember(Name, 1, Lists) of
true ->
mnesia:write(P#privacy{default = Name,
lists = Lists}),
{result, []};
false ->
{error, ?ERR_ITEM_NOT_FOUND}
end
end
end,
case mnesia:transaction(F) of
{atomic, {error, _} = Error} ->
Error;
{atomic, {result, _} = Res} ->
Res;
_ ->
{error, ?ERR_INTERNAL_SERVER_ERROR}
end;
process_default_set(LUser, LServer, false) -> process_default_set(LUser, LServer, false) ->
F = fun() -> F = fun() ->
case mnesia:read({privacy, {LUser, LServer}}) of case mnesia:read({privacy, {LUser, LServer}}) of
@ -306,31 +274,60 @@ process_default_set(LUser, LServer, false) ->
{atomic, {result, _} = Res} -> {atomic, {result, _} = Res} ->
Res; Res;
_ -> _ ->
{error, ?ERR_INTERNAL_SERVER_ERROR} {error, 'internal-server-error'}
end;
process_default_set(LUser, LServer, Name) ->
F = fun() ->
case mnesia:read({privacy, {LUser, LServer}}) of
[] ->
{error, 'item-not-found'};
[#privacy{lists = Lists} = P] ->
case lists:keymember(Name, 1, Lists) of
true ->
mnesia:write(P#privacy{default = Name,
lists = Lists}),
{result, []};
false ->
{error, 'item-not-found'}
end
end
end,
case mnesia:transaction(F) of
{atomic, {error, _} = Error} ->
Error;
{atomic, {result, _} = Res} ->
Res;
_ ->
{error, 'internal-server-error'}
end. end.
process_active_set(LUser, LServer, {value, Name}) -> process_active_set(_LUser, _LServer, false) ->
{result, [], #userlist{}};
process_active_set(LUser, LServer, Name) ->
case catch mnesia:dirty_read(privacy, {LUser, LServer}) of case catch mnesia:dirty_read(privacy, {LUser, LServer}) of
[] -> [] ->
{error, ?ERR_ITEM_NOT_FOUND}; {error, 'item-not-found'};
[#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}}; {result, [], #userlist{name = Name, list = List}};
false -> false ->
{error, ?ERR_ITEM_NOT_FOUND} {error, 'item-not-found'}
end end
end; end.
process_active_set(_LUser, _LServer, false) ->
{result, [], #userlist{}}.
process_list_set(LUser, LServer, {value, Name}, Els) ->
process_list_set(_LUser, _LServer, false, _Els) ->
{error, 'bad-request'};
process_list_set(LUser, LServer, Name, Els) ->
case parse_items(Els) of case parse_items(Els) of
false -> false ->
{error, ?ERR_BAD_REQUEST}; {error, 'bad-request'};
remove -> remove ->
F = F =
fun() -> fun() ->
@ -341,7 +338,7 @@ process_list_set(LUser, LServer, {value, Name}, Els) ->
% TODO: check active % TODO: check active
if if
Name == Default -> Name == Default ->
{error, ?ERR_CONFLICT}; {error, 'conflict'};
true -> true ->
NewLists = NewLists =
lists:keydelete(Name, 1, Lists), lists:keydelete(Name, 1, Lists),
@ -356,15 +353,15 @@ process_list_set(LUser, LServer, {value, Name}, Els) ->
Error; Error;
{atomic, {result, _} = Res} -> {atomic, {result, _} = Res} ->
ejabberd_router:route( ejabberd_router:route(
jlib:make_jid(LUser, LServer, ""), exmpp_jid:make_bare_jid(LUser, LServer),
jlib:make_jid(LUser, LServer, ""), exmpp_jid:make_bare_jid(LUser, LServer),
{xmlelement, "broadcast", [], #xmlel{name = 'broadcast',
[{privacy_list, children=[{privacy_list,
#userlist{name = Name, list = []}, #userlist{name = Name, list = []},
Name}]}), Name}]}),
Res; Res;
_ -> _ ->
{error, ?ERR_INTERNAL_SERVER_ERROR} {error, 'internal-server-error'}
end; end;
List -> List ->
F = F =
@ -387,20 +384,18 @@ process_list_set(LUser, LServer, {value, Name}, Els) ->
Error; Error;
{atomic, {result, _} = Res} -> {atomic, {result, _} = Res} ->
ejabberd_router:route( ejabberd_router:route(
jlib:make_jid(LUser, LServer, ""), exmpp_jid:make_bare_jid(LUser, LServer),
jlib:make_jid(LUser, LServer, ""), exmpp_jid:make_bare_jid(LUser, LServer),
{xmlelement, "broadcast", [], #xmlel{name = 'broadcast',
[{privacy_list, children=[{privacy_list,
#userlist{name = Name, list = List}, #userlist{name = Name, list = List},
Name}]}), Name}]}),
Res; Res;
_ -> _ ->
{error, ?ERR_INTERNAL_SERVER_ERROR} {error, 'internal_server_error'}
end end
end; end.
process_list_set(_LUser, _LServer, false, _Els) ->
{error, ?ERR_BAD_REQUEST}.
parse_items([]) -> parse_items([]) ->
@ -410,16 +405,16 @@ parse_items(Els) ->
parse_items([], Res) -> parse_items([], Res) ->
lists:reverse(Res); lists:reverse(Res);
parse_items([{xmlelement, "item", Attrs, SubEls} | Els], Res) -> parse_items([El = #xmlel{name = item} | Els], Res) ->
Type = xml:get_attr("type", Attrs), Type = exmpp_xml:get_attribute(El, type, false),
Value = xml:get_attr("value", Attrs), Value = exmpp_xml:get_attribute(El, value, false),
SAction = xml:get_attr("action", Attrs), SAction =exmpp_xml:get_attribute(El, action, false),
SOrder = xml:get_attr("order", Attrs), SOrder = exmpp_xml:get_attribute(El, order, false),
Action = case catch list_to_action(element(2, SAction)) of Action = case catch list_to_action(SAction) of
{'EXIT', _} -> false; {'EXIT', _} -> false;
Val -> Val Val -> Val
end, end,
Order = case catch list_to_integer(element(2, SOrder)) of Order = case catch list_to_integer(SOrder) of
{'EXIT', _} -> {'EXIT', _} ->
false; false;
IntVal -> IntVal ->
@ -434,16 +429,17 @@ parse_items([{xmlelement, "item", Attrs, SubEls} | Els], Res) ->
(Action /= false) and (Order /= false) -> (Action /= false) and (Order /= false) ->
I1 = #listitem{action = Action, order = Order}, I1 = #listitem{action = Action, order = Order},
I2 = case {Type, Value} of I2 = case {Type, Value} of
{{value, T}, {value, V}} -> {T, V} when is_list(T), is_list(V) ->
case T of case T of
"jid" -> "jid" ->
case jlib:string_to_jid(V) of try
error -> JID = exmpp_jid:list_to_jid(V),
false; I1#listitem{
JID -> type = jid,
I1#listitem{ value = jlib:short_prepd_jid(JID)}
type = jid, catch
value = jlib:jid_tolower(JID)} _ ->
false
end; end;
"group" -> "group" ->
I1#listitem{type = group, I1#listitem{type = group,
@ -466,7 +462,7 @@ parse_items([{xmlelement, "item", Attrs, SubEls} | Els], Res) ->
false false
end end
end; end;
{{value, _}, false} -> {T, false} when is_list(T) ->
false; false;
_ -> _ ->
I1 I1
@ -475,7 +471,7 @@ parse_items([{xmlelement, "item", Attrs, SubEls} | Els], Res) ->
false -> false ->
false; false;
_ -> _ ->
case parse_matches(I2, xml:remove_cdata(SubEls)) of case parse_matches(I2, exmpp_xml:get_child_elements(El)) of
false -> false ->
false; false;
I3 -> I3 ->
@ -497,15 +493,15 @@ parse_matches(Item, Els) ->
parse_matches1(Item, []) -> parse_matches1(Item, []) ->
Item; Item;
parse_matches1(Item, [{xmlelement, "message", _, _} | Els]) -> parse_matches1(Item, [#xmlel{name = message} | Els]) ->
parse_matches1(Item#listitem{match_message = true}, Els); parse_matches1(Item#listitem{match_message = true}, Els);
parse_matches1(Item, [{xmlelement, "iq", _, _} | Els]) -> parse_matches1(Item, [#xmlel{name = iq} | Els]) ->
parse_matches1(Item#listitem{match_iq = true}, Els); parse_matches1(Item#listitem{match_iq = true}, Els);
parse_matches1(Item, [{xmlelement, "presence-in", _, _} | Els]) -> parse_matches1(Item, [#xmlel{name = 'presence-in'} | Els]) ->
parse_matches1(Item#listitem{match_presence_in = true}, Els); parse_matches1(Item#listitem{match_presence_in = true}, Els);
parse_matches1(Item, [{xmlelement, "presence-out", _, _} | Els]) -> parse_matches1(Item, [#xmlel{name = 'presence-out'} | Els]) ->
parse_matches1(Item#listitem{match_presence_out = true}, Els); parse_matches1(Item#listitem{match_presence_out = true}, Els);
parse_matches1(_Item, [{xmlelement, _, _, _} | _Els]) -> parse_matches1(_Item, [#xmlel{} | _Els]) ->
false. false.
@ -515,24 +511,29 @@ parse_matches1(_Item, [{xmlelement, _, _, _} | _Els]) ->
get_user_list(_, User, Server) -> get_user_list(_, User, Server) ->
LUser = jlib:nodeprep(User), try
LServer = jlib:nameprep(Server), LUser = exmpp_stringprep:nodeprep(User),
case catch mnesia:dirty_read(privacy, {LUser, LServer}) of LServer = exmpp_stringprep:nameprep(Server),
[] -> case catch mnesia:dirty_read(privacy, {LUser, LServer}) of
#userlist{}; [] ->
[#privacy{default = Default, lists = Lists}] -> #userlist{};
case Default of [#privacy{default = Default, lists = Lists}] ->
none -> case Default of
#userlist{}; none ->
_ -> #userlist{};
case lists:keysearch(Default, 1, Lists) of _ ->
{value, {_, List}} -> case lists:keysearch(Default, 1, Lists) of
SortedList = lists:keysort(#listitem.order, List), {value, {_, List}} ->
#userlist{name = Default, list = SortedList}; SortedList = lists:keysort(#listitem.order, List),
_ -> #userlist{name = Default, list = SortedList};
#userlist{} _ ->
end #userlist{}
end; end
end;
_ ->
#userlist{}
end
catch
_ -> _ ->
#userlist{} #userlist{}
end. end.
@ -540,48 +541,45 @@ get_user_list(_, User, Server) ->
check_packet(_, User, Server, check_packet(_, User, Server,
#userlist{list = List}, #userlist{list = List},
{From, To, {xmlelement, PName, _, _}}, {From, To, #xmlel{name = PName}},
Dir) -> Dir) when PName =:= message ;
PName =:= iq ;
PName =:= presence ->
case List of case List of
[] -> [] ->
allow; allow;
_ -> _ ->
PType = case PName of case {PName, Dir} of
"message" -> message;
"iq" -> iq;
"presence" -> presence
end,
case {PType, Dir} of
{message, in} -> {message, in} ->
LJID = jlib:jid_tolower(From), LJID = jlib:short_prepd_jid(From),
{Subscription, Groups} = {Subscription, Groups} =
ejabberd_hooks:run_fold( ejabberd_hooks:run_fold(
roster_get_jid_info, jlib:nameprep(Server), roster_get_jid_info, exmpp_stringprep:nameprep(Server),
{none, []}, [User, Server, LJID]), {none, []}, [User, Server, From]),
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:short_prepd_jid(From),
{Subscription, Groups} = {Subscription, Groups} =
ejabberd_hooks:run_fold( ejabberd_hooks:run_fold(
roster_get_jid_info, jlib:nameprep(Server), roster_get_jid_info, exmpp_stringprep:nameprep(Server),
{none, []}, [User, Server, LJID]), {none, []}, [User, Server, From]),
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:short_prepd_jid(From),
{Subscription, Groups} = {Subscription, Groups} =
ejabberd_hooks:run_fold( ejabberd_hooks:run_fold(
roster_get_jid_info, jlib:nameprep(Server), roster_get_jid_info, exmpp_stringprep:nameprep(Server),
{none, []}, [User, Server, LJID]), {none, []}, [User, Server, From]),
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:short_prepd_jid(To),
{Subscription, Groups} = {Subscription, Groups} =
ejabberd_hooks:run_fold( ejabberd_hooks:run_fold(
roster_get_jid_info, jlib:nameprep(Server), roster_get_jid_info, exmpp_stringprep:nameprep(Server),
{none, []}, [User, Server, LJID]), {none, []}, [User, Server, To]),
check_packet_aux(List, presence_out, check_packet_aux(List, presence_out,
LJID, Subscription, Groups); LJID, Subscription, Groups);
_ -> _ ->
@ -635,14 +633,14 @@ is_type_match(Type, Value, JID, Subscription, Groups) ->
case Type of case Type of
jid -> jid ->
case Value of case Value of
{"", Server, ""} -> {undefined, Server, undefined} ->
case JID of case JID of
{_, Server, _} -> {_, Server, _} ->
true; true;
_ -> _ ->
false false
end; end;
{User, Server, ""} -> {User, Server, undefined} ->
case JID of case JID of
{User, Server, _} -> {User, Server, _} ->
true; true;
@ -675,7 +673,7 @@ update_table() ->
Fields = record_info(fields, privacy), Fields = record_info(fields, privacy),
case mnesia:table_info(privacy, attributes) of case mnesia:table_info(privacy, attributes) of
Fields -> Fields ->
ok; convert_to_exmpp();
[user, default, lists] -> [user, default, lists] ->
?INFO_MSG("Converting privacy table from " ?INFO_MSG("Converting privacy table from "
"{user, default, lists} format", []), "{user, default, lists} format", []),
@ -714,3 +712,42 @@ update_table() ->
end. end.
convert_to_exmpp() ->
Fun = fun() ->
mnesia:foldl(fun convert_to_exmpp2/2, done, privacy, write)
end,
mnesia:transaction(Fun).
convert_to_exmpp2(#privacy{us = {U, S} = Key, lists = L} = P, Acc) ->
U1 = convert_jid_to_exmpp(U),
L1 = convert_lists_to_exmpp(L),
New_P = P#privacy{
us = {U1, S},
lists = L1
},
if
New_P /= P -> mnesia:delete({privacy, Key}), mnesia:write(New_P);
true -> ok
end,
Acc.
convert_jid_to_exmpp("") -> undefined;
convert_jid_to_exmpp(V) -> V.
convert_lists_to_exmpp(L) ->
convert_lists_to_exmpp2(L, []).
convert_lists_to_exmpp2([{Name, List} | Rest], Result) ->
convert_lists_to_exmpp2(Rest,
[{Name, convert_list_to_exmpp(List, [])} | Result]);
convert_lists_to_exmpp2([], Result) ->
lists:reverse(Result).
convert_list_to_exmpp([#listitem{type = jid, value = {U, S, R}} = I | Rest],
Result) ->
U1 = convert_jid_to_exmpp(U),
R1 = convert_jid_to_exmpp(R),
New_I = I#listitem{value = {U1, S, R1}},
convert_list_to_exmpp(Rest, [New_I | Result]);
convert_list_to_exmpp([], Result) ->
lists:reverse(Result).

View File

@ -37,8 +37,9 @@
check_packet/6, check_packet/6,
updated_list/3]). updated_list/3]).
-include_lib("exmpp/include/exmpp.hrl").
-include("ejabberd.hrl"). -include("ejabberd.hrl").
-include("jlib.hrl").
-include("mod_privacy.hrl"). -include("mod_privacy.hrl").
start(Host, Opts) -> start(Host, Opts) ->
@ -69,28 +70,26 @@ stop(Host) ->
?MODULE, updated_list, 50), ?MODULE, updated_list, 50),
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_PRIVACY). gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_PRIVACY).
process_iq(_From, _To, IQ) -> process_iq(_From, _To, IQ_Rec) ->
SubEl = IQ#iq.sub_el, exmpp_iq:error(IQ_Rec, 'not-allowed').
IQ#iq{type = error, sub_el = [SubEl, ?ERR_NOT_ALLOWED]}.
process_iq_get(_, From, _To, #iq{sub_el = SubEl}, process_iq_get(_, From, _To, #iq{payload = SubEl},
#userlist{name = Active}) -> #userlist{name = Active}) ->
#jid{luser = LUser, lserver = LServer} = From, #jid{lnode = LUser, ldomain = LServer} = From,
{xmlelement, _, _, Els} = SubEl, case exmpp_xml:get_child_elements(SubEl) of
case xml:remove_cdata(Els) of
[] -> [] ->
process_lists_get(LUser, LServer, Active); process_lists_get(LUser, LServer, Active);
[{xmlelement, Name, Attrs, _SubEls}] -> [#xmlel{name = Name} = Child] ->
case Name of case Name of
"list" -> list ->
ListName = xml:get_attr("name", Attrs), ListName = exmpp_xml:get_attribute(Child, name, false),
process_list_get(LUser, LServer, ListName); process_list_get(LUser, LServer, ListName);
_ -> _ ->
{error, ?ERR_BAD_REQUEST} {error, 'bad-request'}
end; end;
_ -> _ ->
{error, ?ERR_BAD_REQUEST} {error, 'bad-request'}
end. end.
@ -105,40 +104,38 @@ process_lists_get(LUser, LServer, Active) ->
end, end,
case catch sql_get_privacy_list_names(LUser, LServer) of case catch sql_get_privacy_list_names(LUser, LServer) of
{selected, ["name"], []} -> {selected, ["name"], []} ->
{result, [{xmlelement, "query", [{"xmlns", ?NS_PRIVACY}], []}]}; {result, #xmlel{ns = ?NS_PRIVACY, name = 'query'}};
{selected, ["name"], Names} -> {selected, ["name"], Names} ->
LItems = lists:map( LItems = lists:map(
fun({N}) -> fun({N}) ->
{xmlelement, "list", exmpp_xml:set_attribute(#xmlel{ns = ?NS_PRIVACY, name = list}, name, N)
[{"name", N}], []}
end, Names), end, Names),
DItems = DItems =
case Default of case Default of
none -> none ->
LItems; LItems;
_ -> _ ->
[{xmlelement, "default", [exmpp_xml:set_attribute(#xmlel{ns = ?NS_PRIVACY, name = default}, name, Default) | LItems]
[{"name", Default}], []} | LItems]
end, end,
ADItems = ADItems =
case Active of case Active of
none -> none ->
DItems; DItems;
_ -> _ ->
[{xmlelement, "active", [exmpp_xml:set_attribute(#xmlel{ns = ?NS_PRIVACY, name = active}, name, Active) | DItems]
[{"name", Active}], []} | DItems]
end, end,
{result, {result, #xmlel{ns = ?NS_PRIVACY, name = 'query', children = ADItems}};
[{xmlelement, "query", [{"xmlns", ?NS_PRIVACY}],
ADItems}]};
_ -> _ ->
{error, ?ERR_INTERNAL_SERVER_ERROR} {error, 'internal-server-error'}
end. end.
process_list_get(LUser, LServer, {value, Name}) -> process_list_get(_LUser, _LServer, false) ->
{error, 'bad-request'};
process_list_get(LUser, LServer, Name) ->
case catch sql_get_privacy_list_id(LUser, LServer, Name) of case catch sql_get_privacy_list_id(LUser, LServer, Name) of
{selected, ["id"], []} -> {selected, ["id"], []} ->
{error, ?ERR_ITEM_NOT_FOUND}; {error, 'item-not-found'};
{selected, ["id"], [{ID}]} -> {selected, ["id"], [{ID}]} ->
case catch sql_get_privacy_list_data_by_id(ID, LServer) of case catch sql_get_privacy_list_data_by_id(ID, LServer) of
{selected, ["t", "value", "action", "ord", "match_all", {selected, ["t", "value", "action", "ord", "match_all",
@ -147,29 +144,29 @@ process_list_get(LUser, LServer, {value, Name}) ->
RItems} -> RItems} ->
Items = lists:map(fun raw_to_item/1, RItems), Items = lists:map(fun raw_to_item/1, RItems),
LItems = lists:map(fun item_to_xml/1, Items), LItems = lists:map(fun item_to_xml/1, Items),
{result, ListEl = exmpp_xml:set_attribute(#xmlel{name = list,
[{xmlelement, "query", [{"xmlns", ?NS_PRIVACY}], ns = ?NS_PRIVACY,
[{xmlelement, "list", children = LItems},
[{"name", Name}], LItems}]}]}; name,
_ -> Name),
{error, ?ERR_INTERNAL_SERVER_ERROR} {result, #xmlel{ns = ?NS_PRIVACY, name = 'query', children = [ListEl]}};
_ ->
{error, 'internal-server-error'}
end; end;
_ -> _ ->
{error, ?ERR_INTERNAL_SERVER_ERROR} {error, 'internal-server-error'}
end; end.
process_list_get(_LUser, _LServer, false) ->
{error, ?ERR_BAD_REQUEST}.
item_to_xml(Item) -> item_to_xml(Item) ->
Attrs1 = [{"action", action_to_list(Item#listitem.action)}, Attrs1 = [#xmlattr{name = 'action', value = action_to_list(Item#listitem.action)},
{"order", order_to_list(Item#listitem.order)}], #xmlattr{name = 'order', value = order_to_list(Item#listitem.order)}],
Attrs2 = case Item#listitem.type of Attrs2 = case Item#listitem.type of
none -> none ->
Attrs1; Attrs1;
Type -> Type ->
[{"type", type_to_list(Item#listitem.type)}, [#xmlattr{name = 'type', value = type_to_list(Item#listitem.type)},
{"value", value_to_list(Type, Item#listitem.value)} | #xmlattr{name = 'value', value = value_to_list(Type, Item#listitem.value)} |
Attrs1] Attrs1]
end, end,
SubEls = case Item#listitem.match_all of SubEls = case Item#listitem.match_all of
@ -178,31 +175,31 @@ item_to_xml(Item) ->
false -> false ->
SE1 = case Item#listitem.match_iq of SE1 = case Item#listitem.match_iq of
true -> true ->
[{xmlelement, "iq", [], []}]; [#xmlel{ns = ?NS_PRIVACY, name = iq}];
false -> false ->
[] []
end, end,
SE2 = case Item#listitem.match_message of SE2 = case Item#listitem.match_message of
true -> true ->
[{xmlelement, "message", [], []} | SE1]; [#xmlel{ns = ?NS_PRIVACY, name = message} | SE1];
false -> false ->
SE1 SE1
end, end,
SE3 = case Item#listitem.match_presence_in of SE3 = case Item#listitem.match_presence_in of
true -> true ->
[{xmlelement, "presence-in", [], []} | SE2]; [#xmlel{ns = ?NS_PRIVACY, name = 'presence-in'} | SE2];
false -> false ->
SE2 SE2
end, end,
SE4 = case Item#listitem.match_presence_out of SE4 = case Item#listitem.match_presence_out of
true -> true ->
[{xmlelement, "presence-out", [], []} | SE3]; [#xmlel{ns = ?NS_PRIVACY, name = 'presence-out'} | SE3];
false -> false ->
SE3 SE3
end, end,
SE4 SE4
end, end,
{xmlelement, "item", Attrs2, SubEls}. exmpp_xml:set_attributes(#xmlel{ns = ?NS_PRIVACY, name = item, children = SubEls}, Attrs2).
action_to_list(Action) -> action_to_list(Action) ->
@ -223,7 +220,9 @@ type_to_list(Type) ->
value_to_list(Type, Val) -> value_to_list(Type, Val) ->
case Type of case Type of
jid -> jlib:jid_to_string(Val); jid ->
{N, D, R} = Val,
exmpp_jid:jid_to_list(N, D, R);
group -> Val; group -> Val;
subscription -> subscription ->
case Val of case Val of
@ -244,40 +243,49 @@ list_to_action(S) ->
process_iq_set(_, From, _To, #iq{sub_el = SubEl}) -> process_iq_set(_, From, _To, #iq{payload = SubEl}) ->
#jid{luser = LUser, lserver = LServer} = From, #jid{lnode = LUser, ldomain = LServer} = From,
{xmlelement, _, _, Els} = SubEl, case exmpp_xml:get_child_elements(SubEl) of
case xml:remove_cdata(Els) of [#xmlel{name = Name} = Child] ->
[{xmlelement, Name, Attrs, SubEls}] -> ListName = exmpp_xml:get_attribute(Child, 'name', false),
ListName = xml:get_attr("name", Attrs),
case Name of case Name of
"list" -> list ->
process_list_set(LUser, LServer, ListName, process_list_set(LUser, LServer, ListName,
xml:remove_cdata(SubEls)); exmpp_xml:get_child_elements(Child));
"active" -> active ->
process_active_set(LUser, LServer, ListName); process_active_set(LUser, LServer, ListName);
"default" -> default ->
process_default_set(LUser, LServer, ListName); process_default_set(LUser, LServer, ListName);
_ -> _ ->
{error, ?ERR_BAD_REQUEST} {error, 'bad-request'}
end; end;
_ -> _ ->
{error, ?ERR_BAD_REQUEST} {error, 'bad-request'}
end. end.
process_default_set(LUser, LServer, {value, Name}) -> process_default_set(LUser, LServer, false) ->
case catch sql_unset_default_privacy_list(LUser, LServer) of
{'EXIT', _Reason} ->
{error, 'internal_server_error'};
{error, _Reason} ->
{error, 'internal_server_error'};
_ ->
{result, []}
end;
process_default_set(LUser, LServer, Name) ->
F = fun() -> F = fun() ->
case sql_get_privacy_list_names_t(LUser) of case sql_get_privacy_list_names_t(LUser) of
{selected, ["name"], []} -> {selected, ["name"], []} ->
{error, ?ERR_ITEM_NOT_FOUND}; {error, 'item-not-found'};
{selected, ["name"], Names} -> {selected, ["name"], Names} ->
case lists:member({Name}, Names) of case lists:member({Name}, Names) of
true -> true ->
sql_set_default_privacy_list(LUser, Name), sql_set_default_privacy_list(LUser, Name),
{result, []}; {result, []};
false -> false ->
{error, ?ERR_ITEM_NOT_FOUND} {error, 'item-not-found'}
end end
end end
end, end,
@ -287,24 +295,17 @@ process_default_set(LUser, LServer, {value, Name}) ->
{atomic, {result, _} = Res} -> {atomic, {result, _} = Res} ->
Res; Res;
_ -> _ ->
{error, ?ERR_INTERNAL_SERVER_ERROR} {error, 'internal-server-error'}
end;
process_default_set(LUser, LServer, false) ->
case catch sql_unset_default_privacy_list(LUser, LServer) of
{'EXIT', _Reason} ->
{error, ?ERR_INTERNAL_SERVER_ERROR};
{error, _Reason} ->
{error, ?ERR_INTERNAL_SERVER_ERROR};
_ ->
{result, []}
end. end.
process_active_set(LUser, LServer, {value, Name}) -> process_active_set(_LUser, _LServer, false) ->
{result, [], #userlist{}};
process_active_set(LUser, LServer, Name) ->
case catch sql_get_privacy_list_id(LUser, LServer, Name) of case catch sql_get_privacy_list_id(LUser, LServer, Name) of
{selected, ["id"], []} -> {selected, ["id"], []} ->
{error, ?ERR_ITEM_NOT_FOUND}; {error, 'item-not-found'};
{selected, ["id"], [{ID}]} -> {selected, ["id"], [{ID}]} ->
case catch sql_get_privacy_list_data_by_id(ID, LServer) of case catch sql_get_privacy_list_data_by_id(ID, LServer) of
{selected, ["t", "value", "action", "ord", "match_all", {selected, ["t", "value", "action", "ord", "match_all",
@ -314,24 +315,21 @@ process_active_set(LUser, LServer, {value, Name}) ->
Items = lists:map(fun raw_to_item/1, RItems), Items = lists:map(fun raw_to_item/1, RItems),
{result, [], #userlist{name = Name, list = Items}}; {result, [], #userlist{name = Name, list = Items}};
_ -> _ ->
{error, ?ERR_INTERNAL_SERVER_ERROR} {error, 'internal-server-error'}
end; end;
_ -> _ ->
{error, ?ERR_INTERNAL_SERVER_ERROR} {error, 'internal_server_error'}
end; end.
process_active_set(_LUser, _LServer, false) ->
{result, [], #userlist{}}.
process_list_set(_LUser, _LServer, false, _Els) ->
{error, 'bad-request'};
process_list_set(LUser, LServer, Name, Els) ->
process_list_set(LUser, LServer, {value, Name}, Els) ->
case parse_items(Els) of case parse_items(Els) of
false -> false ->
{error, ?ERR_BAD_REQUEST}; {error, 'bad-request'};
remove -> remove ->
F = F =
fun() -> fun() ->
@ -340,10 +338,10 @@ process_list_set(LUser, LServer, {value, Name}, Els) ->
sql_remove_privacy_list(LUser, Name), sql_remove_privacy_list(LUser, Name),
{result, []}; {result, []};
{selected, ["name"], [{Default}]} -> {selected, ["name"], [{Default}]} ->
%% TODO: check active % TODO: check active
if if
Name == Default -> Name == Default ->
{error, ?ERR_CONFLICT}; {error, 'conflict'};
true -> true ->
sql_remove_privacy_list(LUser, Name), sql_remove_privacy_list(LUser, Name),
{result, []} {result, []}
@ -355,15 +353,15 @@ process_list_set(LUser, LServer, {value, Name}, Els) ->
Error; Error;
{atomic, {result, _} = Res} -> {atomic, {result, _} = Res} ->
ejabberd_router:route( ejabberd_router:route(
jlib:make_jid(LUser, LServer, ""), exmpp_jid:make_bare_jid(LUser, LServer),
jlib:make_jid(LUser, LServer, ""), exmpp_jid:make_bare_jid(LUser, LServer),
{xmlelement, "broadcast", [], #xmlel{name = 'broadcast',
[{privacy_list, children=[{privacy_list,
#userlist{name = Name, list = []}, #userlist{name = Name, list = []},
Name}]}), Name}]}),
Res; Res;
_ -> _ ->
{error, ?ERR_INTERNAL_SERVER_ERROR} {error, 'internal-server-error'}
end; end;
List -> List ->
RItems = lists:map(fun item_to_raw/1, List), RItems = lists:map(fun item_to_raw/1, List),
@ -387,20 +385,18 @@ process_list_set(LUser, LServer, {value, Name}, Els) ->
Error; Error;
{atomic, {result, _} = Res} -> {atomic, {result, _} = Res} ->
ejabberd_router:route( ejabberd_router:route(
jlib:make_jid(LUser, LServer, ""), exmpp_jid:make_bare_jid(LUser, LServer),
jlib:make_jid(LUser, LServer, ""), exmpp_jid:make_bare_jid(LUser, LServer),
{xmlelement, "broadcast", [], #xmlel{name = 'broadcast',
[{privacy_list, children=[{privacy_list,
#userlist{name = Name, list = List}, #userlist{name = Name, list = List},
Name}]}), Name}]}),
Res; Res;
_ -> _ ->
{error, ?ERR_INTERNAL_SERVER_ERROR} {error, 'internal_server_error'}
end end
end; end.
process_list_set(_LUser, _LServer, false, _Els) ->
{error, ?ERR_BAD_REQUEST}.
parse_items([]) -> parse_items([]) ->
@ -410,16 +406,16 @@ parse_items(Els) ->
parse_items([], Res) -> parse_items([], Res) ->
lists:reverse(Res); lists:reverse(Res);
parse_items([{xmlelement, "item", Attrs, SubEls} | Els], Res) -> parse_items([El = #xmlel{name = item} | Els], Res) ->
Type = xml:get_attr("type", Attrs), Type = exmpp_xml:get_attribute(El, type, false),
Value = xml:get_attr("value", Attrs), Value = exmpp_xml:get_attribute(El, value, false),
SAction = xml:get_attr("action", Attrs), SAction =exmpp_xml:get_attribute(El, action, false),
SOrder = xml:get_attr("order", Attrs), SOrder = exmpp_xml:get_attribute(El, order, false),
Action = case catch list_to_action(element(2, SAction)) of Action = case catch list_to_action(SAction) of
{'EXIT', _} -> false; {'EXIT', _} -> false;
Val -> Val Val -> Val
end, end,
Order = case catch list_to_integer(element(2, SOrder)) of Order = case catch list_to_integer(SOrder) of
{'EXIT', _} -> {'EXIT', _} ->
false; false;
IntVal -> IntVal ->
@ -434,16 +430,17 @@ parse_items([{xmlelement, "item", Attrs, SubEls} | Els], Res) ->
(Action /= false) and (Order /= false) -> (Action /= false) and (Order /= false) ->
I1 = #listitem{action = Action, order = Order}, I1 = #listitem{action = Action, order = Order},
I2 = case {Type, Value} of I2 = case {Type, Value} of
{{value, T}, {value, V}} -> {T, V} when is_list(T), is_list(V) ->
case T of case T of
"jid" -> "jid" ->
case jlib:string_to_jid(V) of try
error -> JID = exmpp_jid:list_to_jid(V),
false; I1#listitem{
JID -> type = jid,
I1#listitem{ value = jlib:short_prepd_jid(JID)}
type = jid, catch
value = jlib:jid_tolower(JID)} _ ->
false
end; end;
"group" -> "group" ->
I1#listitem{type = group, I1#listitem{type = group,
@ -466,7 +463,7 @@ parse_items([{xmlelement, "item", Attrs, SubEls} | Els], Res) ->
false false
end end
end; end;
{{value, _}, false} -> {T, false} when is_list(T) ->
false; false;
_ -> _ ->
I1 I1
@ -475,7 +472,7 @@ parse_items([{xmlelement, "item", Attrs, SubEls} | Els], Res) ->
false -> false ->
false; false;
_ -> _ ->
case parse_matches(I2, xml:remove_cdata(SubEls)) of case parse_matches(I2, exmpp_xml:get_child_elements(El)) of
false -> false ->
false; false;
I3 -> I3 ->
@ -497,15 +494,15 @@ parse_matches(Item, Els) ->
parse_matches1(Item, []) -> parse_matches1(Item, []) ->
Item; Item;
parse_matches1(Item, [{xmlelement, "message", _, _} | Els]) -> parse_matches1(Item, [#xmlel{name = message} | Els]) ->
parse_matches1(Item#listitem{match_message = true}, Els); parse_matches1(Item#listitem{match_message = true}, Els);
parse_matches1(Item, [{xmlelement, "iq", _, _} | Els]) -> parse_matches1(Item, [#xmlel{name = iq} | Els]) ->
parse_matches1(Item#listitem{match_iq = true}, Els); parse_matches1(Item#listitem{match_iq = true}, Els);
parse_matches1(Item, [{xmlelement, "presence-in", _, _} | Els]) -> parse_matches1(Item, [#xmlel{name = 'presence-in'} | Els]) ->
parse_matches1(Item#listitem{match_presence_in = true}, Els); parse_matches1(Item#listitem{match_presence_in = true}, Els);
parse_matches1(Item, [{xmlelement, "presence-out", _, _} | Els]) -> parse_matches1(Item, [#xmlel{name = 'presence-out'} | Els]) ->
parse_matches1(Item#listitem{match_presence_out = true}, Els); parse_matches1(Item#listitem{match_presence_out = true}, Els);
parse_matches1(_Item, [{xmlelement, _, _, _} | _Els]) -> parse_matches1(_Item, [#xmlel{} | _Els]) ->
false. false.
@ -515,23 +512,27 @@ parse_matches1(_Item, [{xmlelement, _, _, _} | _Els]) ->
get_user_list(_, User, Server) -> get_user_list(_, User, Server) ->
LUser = jlib:nodeprep(User), try
LServer = jlib:nameprep(Server), LUser = exmpp_stringprep:nodeprep(User),
LServer = exmpp_stringprep:nameprep(Server),
case catch sql_get_default_privacy_list(LUser, LServer) of case catch sql_get_default_privacy_list(LUser, LServer) of
{selected, ["name"], []} -> {selected, ["name"], []} ->
#userlist{}; #userlist{};
{selected, ["name"], [{Default}]} -> {selected, ["name"], [{Default}]} ->
case catch sql_get_privacy_list_data(LUser, LServer, Default) of case catch sql_get_privacy_list_data(LUser, LServer, Default) of
{selected, ["t", "value", "action", "ord", "match_all", {selected, ["t", "value", "action", "ord", "match_all",
"match_iq", "match_message", "match_iq", "match_message",
"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}; #userlist{name = Default, list = Items};
_ -> _ ->
#userlist{} #userlist{}
end; end;
_ ->
#userlist{}
end
catch
_ -> _ ->
#userlist{} #userlist{}
end. end.
@ -539,48 +540,45 @@ get_user_list(_, User, Server) ->
check_packet(_, User, Server, check_packet(_, User, Server,
#userlist{list = List}, #userlist{list = List},
{From, To, {xmlelement, PName, _, _}}, {From, To, #xmlel{name = PName}},
Dir) -> Dir) when PName =:= message ;
PName =:= iq ;
PName =:= presence ->
case List of case List of
[] -> [] ->
allow; allow;
_ -> _ ->
PType = case PName of case {PName, Dir} of
"message" -> message;
"iq" -> iq;
"presence" -> presence
end,
case {PType, Dir} of
{message, in} -> {message, in} ->
LJID = jlib:jid_tolower(From), LJID = jlib:short_prepd_jid(From),
{Subscription, Groups} = {Subscription, Groups} =
ejabberd_hooks:run_fold( ejabberd_hooks:run_fold(
roster_get_jid_info, jlib:nameprep(Server), roster_get_jid_info, exmpp_stringprep:nameprep(Server),
{none, []}, [User, Server, LJID]), {none, []}, [User, Server, From]),
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:short_prepd_jid(From),
{Subscription, Groups} = {Subscription, Groups} =
ejabberd_hooks:run_fold( ejabberd_hooks:run_fold(
roster_get_jid_info, jlib:nameprep(Server), roster_get_jid_info, exmpp_stringprep:nameprep(Server),
{none, []}, [User, Server, LJID]), {none, []}, [User, Server, From]),
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:short_prepd_jid(From),
{Subscription, Groups} = {Subscription, Groups} =
ejabberd_hooks:run_fold( ejabberd_hooks:run_fold(
roster_get_jid_info, jlib:nameprep(Server), roster_get_jid_info, exmpp_stringprep:nameprep(Server),
{none, []}, [User, Server, LJID]), {none, []}, [User, Server, From]),
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:short_prepd_jid(To),
{Subscription, Groups} = {Subscription, Groups} =
ejabberd_hooks:run_fold( ejabberd_hooks:run_fold(
roster_get_jid_info, jlib:nameprep(Server), roster_get_jid_info, exmpp_stringprep:nameprep(Server),
{none, []}, [User, Server, LJID]), {none, []}, [User, Server, To]),
check_packet_aux(List, presence_out, check_packet_aux(List, presence_out,
LJID, Subscription, Groups); LJID, Subscription, Groups);
_ -> _ ->
@ -634,14 +632,14 @@ is_type_match(Type, Value, JID, Subscription, Groups) ->
case Type of case Type of
jid -> jid ->
case Value of case Value of
{"", Server, ""} -> {undefined, Server, undefined} ->
case JID of case JID of
{_, Server, _} -> {_, Server, _} ->
true; true;
_ -> _ ->
false false
end; end;
{User, Server, ""} -> {User, Server, undefined} ->
case JID of case JID of
{User, Server, _} -> {User, Server, _} ->
true; true;
@ -676,10 +674,8 @@ raw_to_item({SType, SValue, SAction, SOrder, SMatchAll, SMatchIQ,
"n" -> "n" ->
{none, none}; {none, none};
"j" -> "j" ->
case jlib:string_to_jid(SValue) of JID = exmpp_jid:list_to_jid(SValue),
#jid{} = JID -> {jid, jlib:short_prepd_jid(JID)};
{jid, jlib:jid_tolower(JID)}
end;
"g" -> "g" ->
{group, SValue}; {group, SValue};
"s" -> "s" ->
@ -731,7 +727,7 @@ item_to_raw(#listitem{type = Type,
none -> none ->
{"n", ""}; {"n", ""};
jid -> jid ->
{"j", jlib:jid_to_string(Value)}; {"j", exmpp_jid:jid_to_list(Value)};
group -> group ->
{"g", Value}; {"g", Value};
subscription -> subscription ->
@ -871,5 +867,5 @@ sql_set_privacy_list(ID, RItems) ->
"match_message, match_presence_in, " "match_message, match_presence_in, "
"match_presence_out " "match_presence_out "
") " ") "
"values ('", ID, "', ", Items, ");"]) "values ('", ID, "', ", Items, ");"])
end, RItems). end, RItems).