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

Convert to exmpp.

SVN Revision: 1463
This commit is contained in:
Jean-Sébastien Pédron 2008-07-21 15:29:52 +00:00
parent 75a8be230b
commit 6e91399922
3 changed files with 230 additions and 224 deletions

View File

@ -4,6 +4,8 @@
the new format to a built-in list of modules known to support them. the new format to a built-in list of modules known to support them.
Other modules will still receive arguments in the old format. Other modules will still receive arguments in the old format.
* src/mod_roster.erl, src/gen_iq_handler.erl: Convert to exmpp.
2008-07-17 Jean-Sébastien Pédron <js.pedron@meetic-corp.com> 2008-07-17 Jean-Sébastien Pédron <js.pedron@meetic-corp.com>
Merge revisions from 1444 to revision 1457 from trunk. Merge revisions from 1444 to revision 1457 from trunk.

View File

@ -59,6 +59,7 @@
% XXX OLD FORMAT: modules not in the following list will receive % XXX OLD FORMAT: modules not in the following list will receive
% old format strudctures. % old format strudctures.
-define(CONVERTED_MODULES, [ -define(CONVERTED_MODULES, [
mod_roster
]). ]).
%%==================================================================== %%====================================================================

View File

@ -44,8 +44,9 @@
webadmin_page/3, webadmin_page/3,
webadmin_user/4]). webadmin_user/4]).
-include_lib("exmpp/include/exmpp.hrl").
-include("ejabberd.hrl"). -include("ejabberd.hrl").
-include("jlib.hrl").
-include("mod_roster.hrl"). -include("mod_roster.hrl").
-include("web/ejabberd_http.hrl"). -include("web/ejabberd_http.hrl").
-include("web/ejabberd_web_admin.hrl"). -include("web/ejabberd_web_admin.hrl").
@ -77,7 +78,8 @@ start(Host, Opts) ->
?MODULE, webadmin_page, 50), ?MODULE, webadmin_page, 50),
ejabberd_hooks:add(webadmin_user, Host, ejabberd_hooks:add(webadmin_user, Host,
?MODULE, webadmin_user, 50), ?MODULE, webadmin_user, 50),
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_ROSTER, % XXX OLD FORMAT: NS as string.
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, atom_to_list(?NS_ROSTER),
?MODULE, process_iq, IQDisc). ?MODULE, process_iq, IQDisc).
stop(Host) -> stop(Host) ->
@ -101,21 +103,22 @@ stop(Host) ->
?MODULE, webadmin_page, 50), ?MODULE, webadmin_page, 50),
ejabberd_hooks:delete(webadmin_user, Host, ejabberd_hooks:delete(webadmin_user, Host,
?MODULE, webadmin_user, 50), ?MODULE, webadmin_user, 50),
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_ROSTER). % XXX OLD FORMAT: NS as string.
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host,
atom_to_list(?NS_ROSTER)).
process_iq(From, To, IQ) -> process_iq(From, To, IQ) ->
#iq{sub_el = SubEl} = IQ, #jid{ldomain = LServer} = From,
#jid{lserver = LServer} = From,
case lists:member(LServer, ?MYHOSTS) of case lists:member(LServer, ?MYHOSTS) of
true -> true ->
process_local_iq(From, To, IQ); process_local_iq(From, To, IQ);
_ -> _ ->
IQ#iq{type = error, sub_el = [SubEl, ?ERR_ITEM_NOT_FOUND]} exmpp_iq:error(IQ, 'item-not-found')
end. end.
process_local_iq(From, To, #iq{type = Type} = IQ) -> process_local_iq(From, To, IQ) ->
case Type of case exmpp_iq:get_type(IQ) of
set -> set ->
process_iq_set(From, To, IQ); process_iq_set(From, To, IQ);
get -> get ->
@ -124,19 +127,17 @@ process_local_iq(From, To, #iq{type = Type} = IQ) ->
process_iq_get(From, To, #iq{sub_el = SubEl} = IQ) -> process_iq_get(From, To, IQ) ->
LUser = From#jid.luser, LUser = From#jid.lnode,
LServer = From#jid.lserver, LServer = From#jid.ldomain,
US = {LUser, LServer}, US = {LUser, LServer},
case catch ejabberd_hooks:run_fold(roster_get, To#jid.lserver, [], [US]) of case catch ejabberd_hooks:run_fold(roster_get, To#jid.ldomain, [], [US]) of
Items when is_list(Items) -> Items when is_list(Items) ->
XItems = lists:map(fun item_to_xml/1, Items), XItems = lists:map(fun item_to_xml/1, Items),
IQ#iq{type = result, exmpp_iq:result(IQ, #xmlel{ns = ?NS_ROSTER, name = 'query',
sub_el = [{xmlelement, "query", children = XItems});
[{"xmlns", ?NS_ROSTER}],
XItems}]};
_ -> _ ->
IQ#iq{type = error, sub_el = [SubEl, ?ERR_INTERNAL_SERVER_ERROR]} exmpp_iq:error(IQ, 'internal-server-error')
end. end.
get_user_roster(Acc, US) -> get_user_roster(Acc, US) ->
@ -153,139 +154,138 @@ get_user_roster(Acc, US) ->
item_to_xml(Item) -> item_to_xml(Item) ->
Attrs1 = [{"jid", jlib:jid_to_string(Item#roster.jid)}], {U, S, R} = Item#roster.jid,
Attrs1 = exmpp_xml:set_attribute_in_list([],
'jid', exmpp_jid:jid_to_string(U, S, R)),
Attrs2 = case Item#roster.name of Attrs2 = case Item#roster.name of
"" -> "" ->
Attrs1; Attrs1;
Name -> Name ->
[{"name", Name} | Attrs1] exmpp_xml:set_attribute_in_list(Attrs1, 'name', Name)
end,
Attrs3 = case Item#roster.subscription of
none ->
[{"subscription", "none"} | Attrs2];
from ->
[{"subscription", "from"} | Attrs2];
to ->
[{"subscription", "to"} | Attrs2];
both ->
[{"subscription", "both"} | Attrs2];
remove ->
[{"subscription", "remove"} | Attrs2]
end, end,
Attrs3 = exmpp_xml:set_attribute_in_list(Attrs2,
'subscription', Item#roster.subscription),
Attrs4 = case ask_to_pending(Item#roster.ask) of Attrs4 = case ask_to_pending(Item#roster.ask) of
out -> out ->
[{"ask", "subscribe"} | Attrs3]; exmpp_xml:set_attribute_in_list(Attrs3,
'ask', "subscribe");
both -> both ->
[{"ask", "subscribe"} | Attrs3]; exmpp_xml:set_attribute_in_list(Attrs3,
'ask', "subscribe");
_ -> _ ->
Attrs3 Attrs3
end, end,
SubEls1 = lists:map(fun(G) -> SubEls1 = lists:map(fun(G) ->
{xmlelement, "group", [], [{xmlcdata, G}]} exmpp_xml:set_cdata(
#xmlel{ns = ?NS_ROSTER, name = 'group'}, G)
end, Item#roster.groups), end, Item#roster.groups),
SubEls = SubEls1 ++ Item#roster.xs, SubEls = SubEls1 ++ Item#roster.xs,
{xmlelement, "item", Attrs4, SubEls}. #xmlel{ns = ?NS_ROSTER, name = 'item', attrs = Attrs4, children = SubEls}.
process_iq_set(From, To, #iq{sub_el = SubEl} = IQ) -> process_iq_set(From, To, IQ) ->
{xmlelement, _Name, _Attrs, Els} = SubEl, case exmpp_iq:get_request(IQ) of
lists:foreach(fun(El) -> process_item_set(From, To, El) end, Els), #xmlel{children = Els} ->
IQ#iq{type = result, sub_el = []}. lists:foreach(fun(El) -> process_item_set(From, To, El) end, Els);
process_item_set(From, To, {xmlelement, _Name, Attrs, Els}) ->
JID1 = jlib:string_to_jid(xml:get_attr_s("jid", Attrs)),
#jid{user = User, luser = LUser, lserver = LServer} = From,
case JID1 of
error ->
ok;
_ -> _ ->
JID = {JID1#jid.user, JID1#jid.server, JID1#jid.resource}, ok
LJID = jlib:jid_tolower(JID1), end,
F = fun() -> exmpp_iq:result(IQ).
Res = mnesia:read({roster, {LUser, LServer, LJID}}),
Item = case Res of process_item_set(From, To, #xmlel{} = Item) ->
[] -> try
#roster{usj = {LUser, LServer, LJID}, JID1 = exmpp_jid:string_to_jid(exmpp_xml:get_attribute(Item, 'jid')),
us = {LUser, LServer}, % XXX OLD FORMAT: old JID (with empty strings).
jid = JID}; #jid{node = User, lnode = LUser, ldomain = LServer} =
[I] -> jlib:to_old_jid(From),
I#roster{jid = JID, JID = {JID1#jid.node, JID1#jid.domain, JID1#jid.resource},
name = "", LJID = jlib:short_jid(JID1),
groups = [], F = fun() ->
xs = []} Res = mnesia:read({roster, {LUser, LServer, LJID}}),
end, Item = case Res of
Item1 = process_item_attrs(Item, Attrs), [] ->
Item2 = process_item_els(Item1, Els), #roster{usj = {LUser, LServer, LJID},
case Item2#roster.subscription of us = {LUser, LServer},
remove -> jid = JID};
mnesia:delete({roster, {LUser, LServer, LJID}}); [I] ->
_ -> I#roster{jid = JID,
mnesia:write(Item2) name = "",
end, groups = [],
%% If the item exist in shared roster, take the xs = []}
%% subscription information from there: end,
Item3 = ejabberd_hooks:run_fold(roster_process_item, Item1 = process_item_attrs(Item, Item#xmlel.attrs),
LServer, Item2, [LServer]), Item2 = process_item_els(Item1, Item#xmlel.children),
{Item, Item3} case Item2#roster.subscription of
end,
case mnesia:transaction(F) of
{atomic, {OldItem, Item}} ->
push_item(User, LServer, To, Item),
case Item#roster.subscription of
remove -> remove ->
IsTo = case OldItem#roster.subscription of mnesia:delete({roster, {LUser, LServer, LJID}});
both -> true;
to -> true;
_ -> false
end,
IsFrom = case OldItem#roster.subscription of
both -> true;
from -> true;
_ -> false
end,
if IsTo ->
ejabberd_router:route(
jlib:jid_remove_resource(From),
jlib:make_jid(OldItem#roster.jid),
{xmlelement, "presence",
[{"type", "unsubscribe"}],
[]});
true -> ok
end,
if IsFrom ->
ejabberd_router:route(
jlib:jid_remove_resource(From),
jlib:make_jid(OldItem#roster.jid),
{xmlelement, "presence",
[{"type", "unsubscribed"}],
[]});
true -> ok
end,
ok;
_ -> _ ->
ok mnesia:write(Item2)
end; end,
E -> %% If the item exist in shared roster, take the
?DEBUG("ROSTER: roster item set error: ~p~n", [E]), %% subscription information from there:
ok Item3 = ejabberd_hooks:run_fold(roster_process_item,
end LServer, Item2, [LServer]),
{Item, Item3}
end,
case mnesia:transaction(F) of
{atomic, {OldItem, Item}} ->
push_item(User, LServer, To, Item),
case Item#roster.subscription of
remove ->
IsTo = case OldItem#roster.subscription of
both -> true;
to -> true;
_ -> false
end,
IsFrom = case OldItem#roster.subscription of
both -> true;
from -> true;
_ -> false
end,
{U, S, R} = OldItem#roster.jid,
if IsTo ->
ejabberd_router:route(
exmpp_jid:jid_to_bare_jid(From),
exmpp_jid:make_jid(U, S, R),
exmpp_presence:unsubscribe());
true -> ok
end,
if IsFrom ->
ejabberd_router:route(
exmpp_jid:jid_to_bare_jid(From),
exmpp_jid:make_jid(U, S, R),
exmpp_presence:unsubscribed());
true -> ok
end,
ok;
_ ->
ok
end;
E ->
?DEBUG("ROSTER: roster item set error: ~p~n", [E]),
ok
end
catch
_ ->
ok
end; end;
process_item_set(_From, _To, _) -> process_item_set(_From, _To, _) ->
ok. ok.
process_item_attrs(Item, [{Attr, Val} | Attrs]) -> process_item_attrs(Item, [#xmlattr{name = Attr, value = Val} | Attrs]) ->
case Attr of case Attr of
"jid" -> 'jid' ->
case jlib:string_to_jid(Val) of try
error -> JID1 = exmpp_jid:string_to_jid(Val),
process_item_attrs(Item, Attrs); JID = {JID1#jid.node, JID1#jid.domain, JID1#jid.resource},
JID1 -> process_item_attrs(Item#roster{jid = JID}, Attrs)
JID = {JID1#jid.user, JID1#jid.server, JID1#jid.resource}, catch
process_item_attrs(Item#roster{jid = JID}, Attrs) _ ->
process_item_attrs(Item, Attrs)
end; end;
"name" -> 'name' ->
process_item_attrs(Item#roster{name = Val}, Attrs); process_item_attrs(Item#roster{name = Val}, Attrs);
"subscription" -> 'subscription' ->
case Val of case Val of
"remove" -> "remove" ->
process_item_attrs(Item#roster{subscription = remove}, process_item_attrs(Item#roster{subscription = remove},
@ -293,7 +293,7 @@ process_item_attrs(Item, [{Attr, Val} | Attrs]) ->
_ -> _ ->
process_item_attrs(Item, Attrs) process_item_attrs(Item, Attrs)
end; end;
"ask" -> 'ask' ->
process_item_attrs(Item, Attrs); process_item_attrs(Item, Attrs);
_ -> _ ->
process_item_attrs(Item, Attrs) process_item_attrs(Item, Attrs)
@ -302,30 +302,30 @@ process_item_attrs(Item, []) ->
Item. Item.
process_item_els(Item, [{xmlelement, Name, Attrs, SEls} | Els]) -> process_item_els(Item, [#xmlel{ns = NS, name = Name} = El | Els]) ->
case Name of case Name of
"group" -> 'group' ->
Groups = [xml:get_cdata(SEls) | Item#roster.groups], Groups = [exmpp_xml:get_cdata(El) | Item#roster.groups],
process_item_els(Item#roster{groups = Groups}, Els); process_item_els(Item#roster{groups = Groups}, Els);
_ -> _ ->
case xml:get_attr_s("xmlns", Attrs) of if
"" -> NS == ?NS_JABBER_CLIENT; NS == ?NS_JABBER_SERVER ->
process_item_els(Item, Els); process_item_els(Item, Els);
_ -> true ->
XEls = [{xmlelement, Name, Attrs, SEls} | Item#roster.xs], XEls = [El | Item#roster.xs],
process_item_els(Item#roster{xs = XEls}, Els) process_item_els(Item#roster{xs = XEls}, Els)
end end
end; end;
process_item_els(Item, [{xmlcdata, _} | Els]) -> process_item_els(Item, [_ | Els]) ->
process_item_els(Item, Els); process_item_els(Item, Els);
process_item_els(Item, []) -> process_item_els(Item, []) ->
Item. Item.
push_item(User, Server, From, Item) -> push_item(User, Server, From, Item) ->
ejabberd_sm:route(jlib:make_jid("", "", ""), ejabberd_sm:route(exmpp_jid:make_bare_jid(""),
jlib:make_jid(User, Server, ""), exmpp_jid:make_bare_jid(User, Server),
{xmlelement, "broadcast", [], #xmlel{name = 'broadcast', children =
[{item, [{item,
Item#roster.jid, Item#roster.jid,
Item#roster.subscription}]}), Item#roster.subscription}]}),
@ -335,19 +335,17 @@ push_item(User, Server, From, Item) ->
% TODO: don't push to those who didn't load roster % TODO: don't push to those who didn't load roster
push_item(User, Server, Resource, From, Item) -> push_item(User, Server, Resource, From, Item) ->
ResIQ = #iq{type = set, xmlns = ?NS_ROSTER, Request = #xmlel{ns = ?NS_ROSTER, name = 'query',
id = "push", children = item_to_xml(Item)},
sub_el = [{xmlelement, "query", ResIQ = exmpp_iq:set(?NS_JABBER_CLIENT, Request, "push"),
[{"xmlns", ?NS_ROSTER}],
[item_to_xml(Item)]}]},
ejabberd_router:route( ejabberd_router:route(
From, From,
jlib:make_jid(User, Server, Resource), exmpp_jid:make_jid(User, Server, Resource),
jlib:iq_to_xml(ResIQ)). ResIQ).
get_subscription_lists(_, User, Server) -> get_subscription_lists(_, User, Server) ->
LUser = jlib:nodeprep(User), LUser = exmpp_stringprep:nodeprep(User),
LServer = jlib:nameprep(Server), LServer = exmpp_stringprep:nameprep(Server),
US = {LUser, LServer}, US = {LUser, LServer},
case mnesia:dirty_index_read(roster, US, #roster.us) of case mnesia:dirty_index_read(roster, US, #roster.us) of
Items when is_list(Items) -> Items when is_list(Items) ->
@ -384,15 +382,15 @@ out_subscription(User, Server, JID, Type) ->
process_subscription(out, User, Server, JID, Type, []). process_subscription(out, User, Server, JID, Type, []).
process_subscription(Direction, User, Server, JID1, Type, Reason) -> process_subscription(Direction, User, Server, JID1, Type, Reason) ->
LUser = jlib:nodeprep(User), LUser = exmpp_stringprep:nodeprep(User),
LServer = jlib:nameprep(Server), LServer = exmpp_stringprep:nameprep(Server),
US = {LUser, LServer}, US = {LUser, LServer},
LJID = jlib:jid_tolower(JID1), LJID = jlib:short_jid(JID1),
F = fun() -> F = fun() ->
Item = case mnesia:read({roster, {LUser, LServer, LJID}}) of Item = case mnesia:read({roster, {LUser, LServer, LJID}}) of
[] -> [] ->
JID = {JID1#jid.user, JID = {JID1#jid.node,
JID1#jid.server, JID1#jid.domain,
JID1#jid.resource}, JID1#jid.resource},
#roster{usj = {LUser, LServer, LJID}, #roster{usj = {LUser, LServer, LJID},
us = US, us = US,
@ -444,13 +442,9 @@ process_subscription(Direction, User, Server, JID1, Type, Reason) ->
none -> none ->
ok; ok;
_ -> _ ->
T = case AutoReply of
subscribed -> "subscribed";
unsubscribed -> "unsubscribed"
end,
ejabberd_router:route( ejabberd_router:route(
jlib:make_jid(User, Server, ""), JID1, exmpp_jid:make_bare_jid(User, Server), JID1,
{xmlelement, "presence", [{"type", T}], []}) exmpp_presence:AutoReply())
end, end,
case Push of case Push of
{push, Item} -> {push, Item} ->
@ -460,7 +454,7 @@ process_subscription(Direction, User, Server, JID1, Type, Reason) ->
ok; ok;
true -> true ->
push_item(User, Server, push_item(User, Server,
jlib:make_jid(User, Server, ""), Item) exmpp_jid:make_bare_jid(User, Server), Item)
end, end,
true; true;
none -> none ->
@ -567,8 +561,8 @@ in_auto_reply(_, _, _) -> none.
remove_user(User, Server) -> remove_user(User, Server) ->
LUser = jlib:nodeprep(User), LUser = exmpp_stringpre:nodeprep(User),
LServer = jlib:nameprep(Server), LServer = exmpp_stringprep:nameprep(Server),
US = {LUser, LServer}, US = {LUser, LServer},
F = fun() -> F = fun() ->
lists:foreach(fun(R) -> lists:foreach(fun(R) ->
@ -582,8 +576,8 @@ remove_user(User, Server) ->
set_items(User, Server, SubEl) -> set_items(User, Server, SubEl) ->
{xmlelement, _Name, _Attrs, Els} = SubEl, {xmlelement, _Name, _Attrs, Els} = SubEl,
LUser = jlib:nodeprep(User), LUser = exmpp_stringprep:nodeprep(User),
LServer = jlib:nameprep(Server), LServer = exmpp_stringprep:nameprep(Server),
F = fun() -> F = fun() ->
lists:foreach(fun(El) -> lists:foreach(fun(El) ->
process_item_set_t(LUser, LServer, El) process_item_set_t(LUser, LServer, El)
@ -591,42 +585,43 @@ set_items(User, Server, SubEl) ->
end, end,
mnesia:transaction(F). mnesia:transaction(F).
process_item_set_t(LUser, LServer, {xmlelement, _Name, Attrs, Els}) -> process_item_set_t(LUser, LServer, #xmlel{} = El) ->
JID1 = jlib:string_to_jid(xml:get_attr_s("jid", Attrs)), try
case JID1 of JID1 = exmpp_jid:string_to_jid(exmpp_xml:get_attribute(El, 'jid')),
error -> JID = {JID1#jid.node, JID1#jid.domain, JID1#jid.resource},
ok; LJID = {JID1#jid.lnode, JID1#jid.ldomain, JID1#jid.lresource},
Item = #roster{usj = {LUser, LServer, LJID},
us = {LUser, LServer},
jid = JID},
Item1 = process_item_attrs_ws(Item, El#xmlel.attrs),
Item2 = process_item_els(Item1, El#xmlel.children),
case Item2#roster.subscription of
remove ->
mnesia:delete({roster, {LUser, LServer, LJID}});
_ ->
mnesia:write(Item2)
end
catch
_ -> _ ->
JID = {JID1#jid.user, JID1#jid.server, JID1#jid.resource}, ok
LJID = {JID1#jid.luser, JID1#jid.lserver, JID1#jid.lresource},
Item = #roster{usj = {LUser, LServer, LJID},
us = {LUser, LServer},
jid = JID},
Item1 = process_item_attrs_ws(Item, Attrs),
Item2 = process_item_els(Item1, Els),
case Item2#roster.subscription of
remove ->
mnesia:delete({roster, {LUser, LServer, LJID}});
_ ->
mnesia:write(Item2)
end
end; end;
process_item_set_t(_LUser, _LServer, _) -> process_item_set_t(_LUser, _LServer, _) ->
ok. ok.
process_item_attrs_ws(Item, [{Attr, Val} | Attrs]) -> process_item_attrs_ws(Item, [#xmlattr{name = Attr, value = Val} | Attrs]) ->
case Attr of case Attr of
"jid" -> 'jid' ->
case jlib:string_to_jid(Val) of try
error -> JID1 = exmpp_jid:string_to_jid(Val),
process_item_attrs_ws(Item, Attrs); JID = {JID1#jid.node, JID1#jid.domain, JID1#jid.resource},
JID1 -> process_item_attrs_ws(Item#roster{jid = JID}, Attrs)
JID = {JID1#jid.user, JID1#jid.server, JID1#jid.resource}, catch
process_item_attrs_ws(Item#roster{jid = JID}, Attrs) _ ->
process_item_attrs_ws(Item, Attrs)
end; end;
"name" -> 'name' ->
process_item_attrs_ws(Item#roster{name = Val}, Attrs); process_item_attrs_ws(Item#roster{name = Val}, Attrs);
"subscription" -> 'subscription' ->
case Val of case Val of
"remove" -> "remove" ->
process_item_attrs_ws(Item#roster{subscription = remove}, process_item_attrs_ws(Item#roster{subscription = remove},
@ -646,7 +641,7 @@ process_item_attrs_ws(Item, [{Attr, Val} | Attrs]) ->
_ -> _ ->
process_item_attrs_ws(Item, Attrs) process_item_attrs_ws(Item, Attrs)
end; end;
"ask" -> 'ask' ->
process_item_attrs_ws(Item, Attrs); process_item_attrs_ws(Item, Attrs);
_ -> _ ->
process_item_attrs_ws(Item, Attrs) process_item_attrs_ws(Item, Attrs)
@ -655,8 +650,8 @@ process_item_attrs_ws(Item, []) ->
Item. Item.
get_in_pending_subscriptions(Ls, User, Server) -> get_in_pending_subscriptions(Ls, User, Server) ->
JID = jlib:make_jid(User, Server, ""), JID = exmpp_jid:make_bare_jid(User, Server),
US = {JID#jid.luser, JID#jid.lserver}, US = {JID#jid.lnode, JID#jid.ldomain},
case mnesia:dirty_index_read(roster, US, #roster.us) of case mnesia:dirty_index_read(roster, US, #roster.us) of
Result when list(Result) -> Result when list(Result) ->
Ls ++ lists:map( Ls ++ lists:map(
@ -667,12 +662,14 @@ get_in_pending_subscriptions(Ls, User, Server) ->
true -> true ->
"" ""
end, end,
{xmlelement, "presence", {U, S, R} = R#roster.jid,
[{"from", jlib:jid_to_string(R#roster.jid)}, Attrs1 = exmpp_stanza:set_sender_in_list([],
{"to", jlib:jid_to_string(JID)}, exmpp_jid:jid_to_string(U, S, R)),
{"type", "subscribe"}], Attrs2 = exmpp_stanza:set_recipient_in_list(Attrs1,
[{xmlelement, "status", [], exmpp_jid:jid_to_string(JID)),
[{xmlcdata, Status}]}]} Pres1 = exmpp_presence:subscribe(),
Pres2 = Pres1#xmlel{attrs = Attrs2},
exmpp_presence:set_status(Pres2, Status)
end, end,
lists:filter( lists:filter(
fun(R) -> fun(R) ->
@ -691,14 +688,14 @@ get_in_pending_subscriptions(Ls, User, Server) ->
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
get_jid_info(_, User, Server, JID) -> get_jid_info(_, User, Server, JID) ->
LUser = jlib:nodeprep(User), LUser = exmpp_stringprep:nodeprep(User),
LJID = jlib:jid_tolower(JID), LJID = jlib:short_jid(JID),
LServer = jlib:nameprep(Server), LServer = exmpp_stringprep:nameprep(Server),
case catch mnesia:dirty_read(roster, {LUser, LServer, LJID}) of case catch mnesia:dirty_read(roster, {LUser, LServer, LJID}) of
[#roster{subscription = Subscription, groups = Groups}] -> [#roster{subscription = Subscription, groups = Groups}] ->
{Subscription, Groups}; {Subscription, Groups};
_ -> _ ->
LRJID = jlib:jid_tolower(jlib:jid_remove_resource(JID)), LRJID = jlib:short_jid(exmpp_jid:jid_to_bare_jid(JID)),
if if
LRJID == LJID -> LRJID == LJID ->
{none, []}; {none, []};
@ -787,7 +784,7 @@ webadmin_page(_, Host,
webadmin_page(Acc, _, _) -> Acc. webadmin_page(Acc, _, _) -> Acc.
user_roster(User, Server, Query, Lang) -> user_roster(User, Server, Query, Lang) ->
US = {jlib:nodeprep(User), jlib:nameprep(Server)}, US = {exmpp_stringprep:nodeprep(User), exmpp_stringprep:nameprep(Server)},
Items1 = mnesia:dirty_index_read(roster, US, #roster.us), Items1 = mnesia:dirty_index_read(roster, US, #roster.us),
Res = user_roster_parse_query(User, Server, Items1, Query), Res = user_roster_parse_query(User, Server, Items1, Query),
Items = mnesia:dirty_index_read(roster, US, #roster.us), Items = mnesia:dirty_index_read(roster, US, #roster.us),
@ -815,9 +812,10 @@ user_roster(User, Server, Query, Lang) ->
[?C(Group), ?BR] [?C(Group), ?BR]
end, R#roster.groups), end, R#roster.groups),
Pending = ask_to_pending(R#roster.ask), Pending = ask_to_pending(R#roster.ask),
{U, S, R} = R#roster.jid,
?XE("tr", ?XE("tr",
[?XAC("td", [{"class", "valign"}], [?XAC("td", [{"class", "valign"}],
jlib:jid_to_string(R#roster.jid)), catch exmpp_jid:jid_to_string(U, S, R)),
?XAC("td", [{"class", "valign"}], ?XAC("td", [{"class", "valign"}],
R#roster.name), R#roster.name),
?XAC("td", [{"class", "valign"}], ?XAC("td", [{"class", "valign"}],
@ -862,11 +860,12 @@ user_roster_parse_query(User, Server, Items, Query) ->
{value, {_, undefined}} -> {value, {_, undefined}} ->
error; error;
{value, {_, SJID}} -> {value, {_, SJID}} ->
case jlib:string_to_jid(SJID) of try
JID when is_record(JID, jid) -> JID = exmpp_jid:string_to_jid(SJID),
user_roster_subscribe_jid(User, Server, JID), user_roster_subscribe_jid(User, Server, JID),
ok; ok
error -> catch
_ ->
error error
end; end;
false -> false ->
@ -887,9 +886,9 @@ user_roster_parse_query(User, Server, Items, Query) ->
user_roster_subscribe_jid(User, Server, JID) -> user_roster_subscribe_jid(User, Server, JID) ->
out_subscription(User, Server, JID, subscribe), out_subscription(User, Server, JID, subscribe),
UJID = jlib:make_jid(User, Server, ""), UJID = exmpp_jid:make_bare_jid(User, Server),
ejabberd_router:route( ejabberd_router:route(
UJID, JID, {xmlelement, "presence", [{"type", "subscribe"}], []}). UJID, JID, exmpp_presence:subscribe()).
user_roster_item_parse_query(User, Server, Items, Query) -> user_roster_item_parse_query(User, Server, Items, Query) ->
lists:foreach( lists:foreach(
@ -898,28 +897,32 @@ user_roster_item_parse_query(User, Server, Items, Query) ->
case lists:keysearch( case lists:keysearch(
"validate" ++ ejabberd_web_admin:term_to_id(JID), 1, Query) of "validate" ++ ejabberd_web_admin:term_to_id(JID), 1, Query) of
{value, _} -> {value, _} ->
JID1 = jlib:make_jid(JID), {U, S, R} = JID,
JID1 = exmpp_jid:make_jid(U, S, R),
out_subscription( out_subscription(
User, Server, JID1, subscribed), User, Server, JID1, subscribed),
UJID = jlib:make_jid(User, Server, ""), UJID = exmpp_jid:make_bare_jid(User, Server),
ejabberd_router:route( ejabberd_router:route(
UJID, JID1, {xmlelement, "presence", UJID, JID1, exmpp_presence:subscribed()),
[{"type", "subscribed"}], []}),
throw(submitted); throw(submitted);
false -> false ->
case lists:keysearch( case lists:keysearch(
"remove" ++ ejabberd_web_admin:term_to_id(JID), 1, Query) of "remove" ++ ejabberd_web_admin:term_to_id(JID), 1, Query) of
{value, _} -> {value, _} ->
UJID = jlib:make_jid(User, Server, ""), UJID = exmpp_jid:make_bare_jid(User, Server),
Attrs1 = exmpp_xml:set_attribute_in_list([],
'jid', exmpp_jid:jid_to_string(JID)),
Attrs2 = exmpp_xml:set_attribute_in_list(Attrs1,
'subscription', "remove"),
Item = #xmlel{ns = ?NS_ROSTER, name = 'item',
attrs = Attrs2},
Request = #xmlel{
ns = ?NS_ROSTER,
name = 'query',
children = [Item]},
process_iq( process_iq(
UJID, UJID, UJID, UJID,
#iq{type = set, exmpp_iq:set(?NS_JABBER_CLIENT, Request)),
sub_el = {xmlelement, "query",
[{"xmlns", ?NS_ROSTER}],
[{xmlelement, "item",
[{"jid", jlib:jid_to_string(JID)},
{"subscription", "remove"}],
[]}]}}),
throw(submitted); throw(submitted);
false -> false ->
ok ok
@ -930,7 +933,7 @@ user_roster_item_parse_query(User, Server, Items, Query) ->
nothing. nothing.
us_to_list({User, Server}) -> us_to_list({User, Server}) ->
jlib:jid_to_string({User, Server, ""}). exmpp_jid:bare_jid_to_string(User, Server).
webadmin_user(Acc, _User, _Server, Lang) -> webadmin_user(Acc, _User, _Server, Lang) ->
Acc ++ [?XE("h3", [?ACT("roster/", "Roster")])]. Acc ++ [?XE("h3", [?ACT("roster/", "Roster")])].