mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-24 16:23:40 +01:00
Convert to exmpp.
SVN Revision: 1565
This commit is contained in:
parent
4eaa8e19c9
commit
56a0c8ed1d
@ -1,3 +1,7 @@
|
|||||||
|
2008-09-18 Jean-Sébastien Pédron <js.pedron@meetic-corp.com>
|
||||||
|
|
||||||
|
* src/mod_roster_odbc.erl: Convert to exmpp.
|
||||||
|
|
||||||
2008-09-16 Jean-Sébastien Pédron <js.pedron@meetic-corp.com>
|
2008-09-16 Jean-Sébastien Pédron <js.pedron@meetic-corp.com>
|
||||||
|
|
||||||
Merge from trunk (r1457 to r1563).
|
Merge from trunk (r1457 to r1563).
|
||||||
|
@ -43,8 +43,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").
|
||||||
@ -99,39 +100,32 @@ stop(Host) ->
|
|||||||
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_ROSTER).
|
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_ROSTER).
|
||||||
|
|
||||||
|
|
||||||
process_iq(From, To, IQ) ->
|
process_iq(From, To, IQ_Rec) ->
|
||||||
#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_Rec);
|
||||||
_ ->
|
_ ->
|
||||||
IQ#iq{type = error, sub_el = [SubEl, ?ERR_ITEM_NOT_FOUND]}
|
exmpp_iq:error(IQ_Rec, 'item-not-found')
|
||||||
end.
|
end.
|
||||||
|
|
||||||
process_local_iq(From, To, #iq{type = Type} = IQ) ->
|
process_local_iq(From, To, #iq{type = get} = IQ_Rec) ->
|
||||||
case Type of
|
process_iq_get(From, To, IQ_Rec);
|
||||||
set ->
|
process_local_iq(From, To, #iq{type = set} = IQ_Rec) ->
|
||||||
process_iq_set(From, To, IQ);
|
process_iq_set(From, To, IQ_Rec).
|
||||||
get ->
|
|
||||||
process_iq_get(From, To, IQ)
|
|
||||||
end.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
process_iq_get(From, To, #iq{sub_el = SubEl} = IQ) ->
|
process_iq_get(From, To, IQ_Rec) ->
|
||||||
LUser = From#jid.luser,
|
US = {From#jid.lnode, From#jid.ldomain},
|
||||||
LServer = From#jid.lserver,
|
case catch ejabberd_hooks:run_fold(roster_get, To#jid.ldomain, [], [US]) of
|
||||||
US = {LUser, LServer},
|
|
||||||
case catch ejabberd_hooks:run_fold(roster_get, To#jid.lserver, [], [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,
|
Result = #xmlel{ns = ?NS_ROSTER, name = 'query',
|
||||||
sub_el = [{xmlelement, "query",
|
children = XItems},
|
||||||
[{"xmlns", ?NS_ROSTER}],
|
exmpp_iq:result(IQ_Rec, Result);
|
||||||
XItems}]};
|
|
||||||
_ ->
|
_ ->
|
||||||
IQ#iq{type = error, sub_el = [SubEl, ?ERR_INTERNAL_SERVER_ERROR]}
|
exmpp_iq:error(IQ_Rec, 'internal-server-error')
|
||||||
end.
|
end.
|
||||||
|
|
||||||
get_user_roster(Acc, {LUser, LServer}) ->
|
get_user_roster(Acc, {LUser, LServer}) ->
|
||||||
@ -162,7 +156,8 @@ get_roster(LUser, LServer) ->
|
|||||||
error ->
|
error ->
|
||||||
[];
|
[];
|
||||||
R ->
|
R ->
|
||||||
SJID = jlib:jid_to_string(R#roster.jid),
|
{U2, S2, R2} = R#roster.jid,
|
||||||
|
SJID = exmpp_jid:jid_to_list(U2, S2, R2),
|
||||||
Groups = lists:flatmap(
|
Groups = lists:flatmap(
|
||||||
fun({S, G}) when S == SJID ->
|
fun({S, G}) when S == SJID ->
|
||||||
[G];
|
[G];
|
||||||
@ -179,54 +174,50 @@ get_roster(LUser, LServer) ->
|
|||||||
|
|
||||||
|
|
||||||
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_list(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),
|
||||||
Attrs = case ask_to_pending(Item#roster.ask) of
|
Attrs = 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,
|
||||||
SubEls = lists:map(fun(G) ->
|
SubEls = 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),
|
||||||
{xmlelement, "item", Attrs, SubEls}.
|
#xmlel{ns = ?NS_ROSTER, name = 'item', attrs = Attrs, children = SubEls}.
|
||||||
|
|
||||||
|
|
||||||
process_iq_set(From, To, #iq{sub_el = SubEl} = IQ) ->
|
process_iq_set(From, To, #iq{payload = Request} = IQ_Rec) ->
|
||||||
{xmlelement, _Name, _Attrs, Els} = SubEl,
|
case Request 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;
|
|
||||||
_ ->
|
_ ->
|
||||||
LJID = jlib:jid_tolower(JID1),
|
ok
|
||||||
|
end,
|
||||||
|
exmpp_iq:result(IQ_Rec).
|
||||||
|
|
||||||
|
process_item_set(From, To, #xmlel{} = El) ->
|
||||||
|
try
|
||||||
|
JID1 = exmpp_jid:list_to_jid(exmpp_xml:get_attribute(El, 'jid', "")),
|
||||||
|
#jid{node = User, lnode = LUser, ldomain = LServer} = From,
|
||||||
|
LJID = jlib:short_prepd_jid(JID1),
|
||||||
Username = ejabberd_odbc:escape(LUser),
|
Username = ejabberd_odbc:escape(LUser),
|
||||||
SJID = ejabberd_odbc:escape(jlib:jid_to_string(LJID)),
|
SJID = ejabberd_odbc:escape(exmpp_jid:jid_to_list(LJID)),
|
||||||
F = fun() ->
|
F = fun() ->
|
||||||
{selected,
|
{selected,
|
||||||
["username", "jid", "nick", "subscription",
|
["username", "jid", "nick", "subscription",
|
||||||
@ -253,8 +244,8 @@ process_item_set(From, To, {xmlelement, _Name, Attrs, Els}) ->
|
|||||||
name = ""}
|
name = ""}
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
Item1 = process_item_attrs(Item, Attrs),
|
Item1 = process_item_attrs(Item, El#xmlel.attrs),
|
||||||
Item2 = process_item_els(Item1, Els),
|
Item2 = process_item_els(Item1, El#xmlel.children),
|
||||||
case Item2#roster.subscription of
|
case Item2#roster.subscription of
|
||||||
remove ->
|
remove ->
|
||||||
odbc_queries:del_roster(LServer, Username, SJID);
|
odbc_queries:del_roster(LServer, Username, SJID);
|
||||||
@ -284,22 +275,19 @@ process_item_set(From, To, {xmlelement, _Name, Attrs, Els}) ->
|
|||||||
from -> true;
|
from -> true;
|
||||||
_ -> false
|
_ -> false
|
||||||
end,
|
end,
|
||||||
|
{U, S, R} = OldItem#roster.jid,
|
||||||
if IsTo ->
|
if IsTo ->
|
||||||
ejabberd_router:route(
|
ejabberd_router:route(
|
||||||
jlib:jid_remove_resource(From),
|
exmpp_jid:jid_to_bare_jid(From),
|
||||||
jlib:make_jid(OldItem#roster.jid),
|
exmpp_jid:make_jid(U, S, R),
|
||||||
{xmlelement, "presence",
|
exmpp_presence:unsubscribe());
|
||||||
[{"type", "unsubscribe"}],
|
|
||||||
[]});
|
|
||||||
true -> ok
|
true -> ok
|
||||||
end,
|
end,
|
||||||
if IsFrom ->
|
if IsFrom ->
|
||||||
ejabberd_router:route(
|
ejabberd_router:route(
|
||||||
jlib:jid_remove_resource(From),
|
exmpp_jid:jid_to_bare_jid(From),
|
||||||
jlib:make_jid(OldItem#roster.jid),
|
exmpp_jid:make_jid(U, S, R),
|
||||||
{xmlelement, "presence",
|
exmpp_presence:unsubscribed());
|
||||||
[{"type", "unsubscribed"}],
|
|
||||||
[]});
|
|
||||||
true -> ok
|
true -> ok
|
||||||
end,
|
end,
|
||||||
ok;
|
ok;
|
||||||
@ -310,23 +298,18 @@ process_item_set(From, To, {xmlelement, _Name, Attrs, Els}) ->
|
|||||||
?DEBUG("ROSTER: roster item set error: ~p~n", [E]),
|
?DEBUG("ROSTER: roster item set error: ~p~n", [E]),
|
||||||
ok
|
ok
|
||||||
end
|
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" ->
|
'name' ->
|
||||||
case jlib:string_to_jid(Val) of
|
|
||||||
error ->
|
|
||||||
process_item_attrs(Item, Attrs);
|
|
||||||
JID1 ->
|
|
||||||
JID = {JID1#jid.luser, JID1#jid.lserver, JID1#jid.lresource},
|
|
||||||
process_item_attrs(Item#roster{jid = JID}, Attrs)
|
|
||||||
end;
|
|
||||||
"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},
|
||||||
@ -334,7 +317,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)
|
||||||
@ -343,24 +326,24 @@ process_item_attrs(Item, []) ->
|
|||||||
Item.
|
Item.
|
||||||
|
|
||||||
|
|
||||||
process_item_els(Item, [{xmlelement, Name, _Attrs, SEls} | Els]) ->
|
process_item_els(Item, [#xmlel{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);
|
||||||
_ ->
|
_ ->
|
||||||
process_item_els(Item, Els)
|
process_item_els(Item, Els)
|
||||||
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(#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}]}),
|
||||||
@ -370,19 +353,18 @@ push_item(User, Server, From, Item) ->
|
|||||||
|
|
||||||
% TODO: don't push to those who not load roster
|
% TODO: don't push to those who not 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),
|
try
|
||||||
LServer = jlib:nameprep(Server),
|
LUser = exmpp_stringprep:nodeprep(User),
|
||||||
|
LServer = exmpp_stringprep:nameprep(Server),
|
||||||
Username = ejabberd_odbc:escape(LUser),
|
Username = ejabberd_odbc:escape(LUser),
|
||||||
case catch odbc_queries:get_roster(LServer, Username) of
|
case catch odbc_queries:get_roster(LServer, Username) of
|
||||||
{selected, ["username", "jid", "nick", "subscription", "ask",
|
{selected, ["username", "jid", "nick", "subscription", "ask",
|
||||||
@ -391,6 +373,10 @@ get_subscription_lists(_, User, Server) ->
|
|||||||
fill_subscription_lists(LServer, Items, [], []);
|
fill_subscription_lists(LServer, Items, [], []);
|
||||||
_ ->
|
_ ->
|
||||||
{[], []}
|
{[], []}
|
||||||
|
end
|
||||||
|
catch
|
||||||
|
_ ->
|
||||||
|
{[], []}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
fill_subscription_lists(LServer, [RawI | Is], F, T) ->
|
fill_subscription_lists(LServer, [RawI | Is], F, T) ->
|
||||||
@ -428,11 +414,12 @@ 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),
|
try
|
||||||
LServer = jlib:nameprep(Server),
|
LUser = exmpp_stringprep:nodeprep(User),
|
||||||
LJID = jlib:jid_tolower(JID1),
|
LServer = exmpp_stringprep:nameprep(Server),
|
||||||
|
LJID = exmpp_jid:jid_to_bare_jid(JID1),
|
||||||
Username = ejabberd_odbc:escape(LUser),
|
Username = ejabberd_odbc:escape(LUser),
|
||||||
SJID = ejabberd_odbc:escape(jlib:jid_to_string(LJID)),
|
SJID = ejabberd_odbc:escape(exmpp_jid:jid_to_list(LJID)),
|
||||||
F = fun() ->
|
F = fun() ->
|
||||||
Item =
|
Item =
|
||||||
case odbc_queries:get_roster_by_jid(LServer, Username, SJID) of
|
case odbc_queries:get_roster_by_jid(LServer, Username, SJID) of
|
||||||
@ -492,7 +479,7 @@ process_subscription(Direction, User, Server, JID1, Type, Reason) ->
|
|||||||
{Subscription, Pending} ->
|
{Subscription, Pending} ->
|
||||||
NewItem = Item#roster{subscription = Subscription,
|
NewItem = Item#roster{subscription = Subscription,
|
||||||
ask = Pending,
|
ask = Pending,
|
||||||
askmessage = AskMessage},
|
askmessage = list_to_binary(AskMessage)},
|
||||||
ItemVals = record_to_string(NewItem),
|
ItemVals = record_to_string(NewItem),
|
||||||
odbc_queries:roster_subscribe(LServer, Username, SJID, ItemVals),
|
odbc_queries:roster_subscribe(LServer, Username, SJID, ItemVals),
|
||||||
{{push, NewItem}, AutoReply}
|
{{push, NewItem}, AutoReply}
|
||||||
@ -504,13 +491,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} ->
|
||||||
@ -520,7 +503,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 ->
|
||||||
@ -528,6 +511,10 @@ process_subscription(Direction, User, Server, JID1, Type, Reason) ->
|
|||||||
end;
|
end;
|
||||||
_ ->
|
_ ->
|
||||||
false
|
false
|
||||||
|
end
|
||||||
|
catch
|
||||||
|
_ ->
|
||||||
|
false
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
@ -628,38 +615,44 @@ in_auto_reply(_, _, _) -> none.
|
|||||||
|
|
||||||
|
|
||||||
remove_user(User, Server) ->
|
remove_user(User, Server) ->
|
||||||
LUser = jlib:nodeprep(User),
|
try
|
||||||
LServer = jlib:nameprep(Server),
|
LUser = exmpp_stringprep:nodeprep(User),
|
||||||
|
LServer = exmpp_stringprep:nameprep(Server),
|
||||||
Username = ejabberd_odbc:escape(LUser),
|
Username = ejabberd_odbc:escape(LUser),
|
||||||
odbc_queries:del_user_roster_t(LServer, Username),
|
odbc_queries:del_user_roster_t(LServer, Username),
|
||||||
ok.
|
ok
|
||||||
|
catch
|
||||||
|
_ ->
|
||||||
|
ok
|
||||||
|
end.
|
||||||
|
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
|
||||||
set_items(User, Server, SubEl) ->
|
set_items(User, Server, #xmlel{children = Els}) ->
|
||||||
{xmlelement, _Name, _Attrs, Els} = SubEl,
|
try
|
||||||
LUser = jlib:nodeprep(User),
|
LUser = exmpp_stringprep:nodeprep(User),
|
||||||
LServer = jlib:nameprep(Server),
|
LServer = exmpp_stringprep:nameprep(Server),
|
||||||
catch odbc_queries:sql_transaction(
|
catch odbc_queries:sql_transaction(
|
||||||
LServer,
|
LServer,
|
||||||
lists:map(fun(El) ->
|
lists:map(fun(El) ->
|
||||||
process_item_set_t(LUser, LServer, El)
|
process_item_set_t(LUser, LServer, El)
|
||||||
end, Els)).
|
end, Els))
|
||||||
|
catch
|
||||||
process_item_set_t(LUser, LServer, {xmlelement, _Name, Attrs, Els}) ->
|
|
||||||
JID1 = jlib:string_to_jid(xml:get_attr_s("jid", Attrs)),
|
|
||||||
case JID1 of
|
|
||||||
error ->
|
|
||||||
[];
|
|
||||||
_ ->
|
_ ->
|
||||||
LJID = {JID1#jid.luser, JID1#jid.lserver, JID1#jid.lresource},
|
ok
|
||||||
|
end.
|
||||||
|
|
||||||
|
process_item_set_t(LUser, LServer, #xmlel{} = El) ->
|
||||||
|
try
|
||||||
|
JID1 = exmpp_jid:list_to_jid(exmpp_xml:get_attribute(El, 'jid', "")),
|
||||||
|
LJID = jlib:short_prepd_jid(JID1),
|
||||||
Username = ejabberd_odbc:escape(LUser),
|
Username = ejabberd_odbc:escape(LUser),
|
||||||
SJID = ejabberd_odbc:escape(jlib:jid_to_string(LJID)),
|
SJID = ejabberd_odbc:escape(exmpp_jid:jid_to_list(LJID)),
|
||||||
Item = #roster{usj = {LUser, LServer, LJID},
|
Item = #roster{usj = {LUser, LServer, LJID},
|
||||||
us = {LUser, LServer},
|
us = {LUser, LServer},
|
||||||
jid = LJID},
|
jid = LJID},
|
||||||
Item1 = process_item_attrs_ws(Item, Attrs),
|
Item1 = process_item_attrs_ws(Item, El#xmlel.attrs),
|
||||||
Item2 = process_item_els(Item1, Els),
|
Item2 = process_item_els(Item1, El#xmlel.children),
|
||||||
case Item2#roster.subscription of
|
case Item2#roster.subscription of
|
||||||
remove ->
|
remove ->
|
||||||
odbc_queries:del_roster_sql(Username, SJID);
|
odbc_queries:del_roster_sql(Username, SJID);
|
||||||
@ -668,23 +661,18 @@ process_item_set_t(LUser, LServer, {xmlelement, _Name, Attrs, Els}) ->
|
|||||||
ItemGroups = groups_to_string(Item2),
|
ItemGroups = groups_to_string(Item2),
|
||||||
odbc_queries:update_roster_sql(Username, SJID, ItemVals, ItemGroups)
|
odbc_queries:update_roster_sql(Username, SJID, ItemVals, ItemGroups)
|
||||||
end
|
end
|
||||||
|
catch
|
||||||
|
_ ->
|
||||||
|
[]
|
||||||
end;
|
end;
|
||||||
process_item_set_t(_LUser, _LServer, _) ->
|
process_item_set_t(_LUser, _LServer, _) ->
|
||||||
[].
|
[].
|
||||||
|
|
||||||
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" ->
|
'name' ->
|
||||||
case jlib:string_to_jid(Val) of
|
|
||||||
error ->
|
|
||||||
process_item_attrs_ws(Item, Attrs);
|
|
||||||
JID1 ->
|
|
||||||
JID = {JID1#jid.luser, JID1#jid.lserver, JID1#jid.lresource},
|
|
||||||
process_item_attrs_ws(Item#roster{jid = JID}, Attrs)
|
|
||||||
end;
|
|
||||||
"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},
|
||||||
@ -704,7 +692,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)
|
||||||
@ -713,9 +701,9 @@ 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),
|
||||||
LUser = JID#jid.luser,
|
LUser = JID#jid.lnode,
|
||||||
LServer = JID#jid.lserver,
|
LServer = JID#jid.ldomain,
|
||||||
Username = ejabberd_odbc:escape(LUser),
|
Username = ejabberd_odbc:escape(LUser),
|
||||||
case catch odbc_queries:get_roster(LServer, Username) of
|
case catch odbc_queries:get_roster(LServer, Username) of
|
||||||
{selected, ["username", "jid", "nick", "subscription", "ask",
|
{selected, ["username", "jid", "nick", "subscription", "ask",
|
||||||
@ -724,12 +712,12 @@ get_in_pending_subscriptions(Ls, User, Server) ->
|
|||||||
Ls ++ lists:map(
|
Ls ++ lists:map(
|
||||||
fun(R) ->
|
fun(R) ->
|
||||||
Message = R#roster.askmessage,
|
Message = R#roster.askmessage,
|
||||||
{xmlelement, "presence",
|
{U, S, R} = R#roster.jid,
|
||||||
[{"from", jlib:jid_to_string(R#roster.jid)},
|
Pres1 = exmpp_presence:subscribe(),
|
||||||
{"to", jlib:jid_to_string(JID)},
|
Pres2 = exmpp_stanza:set_jids(Pres1,
|
||||||
{"type", "subscribe"}],
|
exmpp_jid:jid_to_list(U, S, R),
|
||||||
[{xmlelement, "status", [],
|
exmpp_jid:jid_to_list(JID)),
|
||||||
[{xmlcdata, Message}]}]}
|
exmpp_presence:set_status(Pres2, Message)
|
||||||
end,
|
end,
|
||||||
lists:flatmap(
|
lists:flatmap(
|
||||||
fun(I) ->
|
fun(I) ->
|
||||||
@ -754,11 +742,12 @@ get_in_pending_subscriptions(Ls, User, Server) ->
|
|||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
|
||||||
get_jid_info(_, User, Server, JID) ->
|
get_jid_info(_, User, Server, JID) ->
|
||||||
LUser = jlib:nodeprep(User),
|
try
|
||||||
LServer = jlib:nameprep(Server),
|
LUser = exmpp_stringprep:nodeprep(User),
|
||||||
LJID = jlib:jid_tolower(JID),
|
LServer = exmpp_stringprep:nameprep(Server),
|
||||||
|
LJID = jlib:short_prepd_jid(JID),
|
||||||
Username = ejabberd_odbc:escape(LUser),
|
Username = ejabberd_odbc:escape(LUser),
|
||||||
SJID = ejabberd_odbc:escape(jlib:jid_to_string(LJID)),
|
SJID = ejabberd_odbc:escape(exmpp_jid:jid_to_list(LJID)),
|
||||||
case catch odbc_queries:get_subscription(LServer, Username, SJID) of
|
case catch odbc_queries:get_subscription(LServer, Username, SJID) of
|
||||||
{selected, ["subscription"], [{SSubscription}]} ->
|
{selected, ["subscription"], [{SSubscription}]} ->
|
||||||
Subscription = case SSubscription of
|
Subscription = case SSubscription of
|
||||||
@ -775,12 +764,12 @@ get_jid_info(_, User, Server, JID) ->
|
|||||||
end,
|
end,
|
||||||
{Subscription, Groups};
|
{Subscription, Groups};
|
||||||
_ ->
|
_ ->
|
||||||
LRJID = jlib:jid_tolower(jlib:jid_remove_resource(JID)),
|
LRJID = jlib:short_prepd_bare_jid(JID),
|
||||||
if
|
if
|
||||||
LRJID == LJID ->
|
LRJID == LJID ->
|
||||||
{none, []};
|
{none, []};
|
||||||
true ->
|
true ->
|
||||||
SRJID = ejabberd_odbc:escape(jlib:jid_to_string(LRJID)),
|
SRJID = ejabberd_odbc:escape(exmpp_jid:jid_to_list(LRJID)),
|
||||||
case catch odbc_queries:get_subscription(LServer, Username, SRJID) of
|
case catch odbc_queries:get_subscription(LServer, Username, SRJID) of
|
||||||
{selected, ["subscription"], [{SSubscription}]} ->
|
{selected, ["subscription"], [{SSubscription}]} ->
|
||||||
Subscription = case SSubscription of
|
Subscription = case SSubscription of
|
||||||
@ -800,17 +789,19 @@ get_jid_info(_, User, Server, JID) ->
|
|||||||
{none, []}
|
{none, []}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
catch
|
||||||
|
_ ->
|
||||||
|
{none, []}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
|
||||||
raw_to_record(LServer, {User, SJID, Nick, SSubscription, SAsk, SAskMessage,
|
raw_to_record(LServer, {User, SJID, Nick, SSubscription, SAsk, SAskMessage,
|
||||||
_SServer, _SSubscribe, _SType}) ->
|
_SServer, _SSubscribe, _SType}) ->
|
||||||
case jlib:string_to_jid(SJID) of
|
try
|
||||||
error ->
|
JID = exmpp_jid:list_to_jid(SJID),
|
||||||
error;
|
LJID = jlib:short_prepd_jid(JID),
|
||||||
JID ->
|
|
||||||
LJID = jlib:jid_tolower(JID),
|
|
||||||
Subscription = case SSubscription of
|
Subscription = case SSubscription of
|
||||||
"B" -> both;
|
"B" -> both;
|
||||||
"T" -> to;
|
"T" -> to;
|
||||||
@ -831,7 +822,10 @@ raw_to_record(LServer, {User, SJID, Nick, SSubscription, SAsk, SAskMessage,
|
|||||||
name = Nick,
|
name = Nick,
|
||||||
subscription = Subscription,
|
subscription = Subscription,
|
||||||
ask = Ask,
|
ask = Ask,
|
||||||
askmessage = SAskMessage}
|
askmessage = list_to_binary(SAskMessage)}
|
||||||
|
catch
|
||||||
|
_ ->
|
||||||
|
error
|
||||||
end.
|
end.
|
||||||
|
|
||||||
record_to_string(#roster{us = {User, _Server},
|
record_to_string(#roster{us = {User, _Server},
|
||||||
@ -841,7 +835,8 @@ record_to_string(#roster{us = {User, _Server},
|
|||||||
ask = Ask,
|
ask = Ask,
|
||||||
askmessage = AskMessage}) ->
|
askmessage = AskMessage}) ->
|
||||||
Username = ejabberd_odbc:escape(User),
|
Username = ejabberd_odbc:escape(User),
|
||||||
SJID = ejabberd_odbc:escape(jlib:jid_to_string(jlib:jid_tolower(JID))),
|
{U, S, R} = jlib:short_prepd_jid(JID),
|
||||||
|
SJID = ejabberd_odbc:escape(exmpp_jid:jid_to_list(U, S, R)),
|
||||||
Nick = ejabberd_odbc:escape(Name),
|
Nick = ejabberd_odbc:escape(Name),
|
||||||
SSubscription = case Subscription of
|
SSubscription = case Subscription of
|
||||||
both -> "B";
|
both -> "B";
|
||||||
@ -857,7 +852,7 @@ record_to_string(#roster{us = {User, _Server},
|
|||||||
in -> "I";
|
in -> "I";
|
||||||
none -> "N"
|
none -> "N"
|
||||||
end,
|
end,
|
||||||
SAskMessage = ejabberd_odbc:escape(AskMessage),
|
SAskMessage = ejabberd_odbc:escape(binary_to_list(AskMessage)),
|
||||||
["'", Username, "',"
|
["'", Username, "',"
|
||||||
"'", SJID, "',"
|
"'", SJID, "',"
|
||||||
"'", Nick, "',"
|
"'", Nick, "',"
|
||||||
@ -870,7 +865,8 @@ groups_to_string(#roster{us = {User, _Server},
|
|||||||
jid = JID,
|
jid = JID,
|
||||||
groups = Groups}) ->
|
groups = Groups}) ->
|
||||||
Username = ejabberd_odbc:escape(User),
|
Username = ejabberd_odbc:escape(User),
|
||||||
SJID = ejabberd_odbc:escape(jlib:jid_to_string(jlib:jid_tolower(JID))),
|
{U, S, R} = jlib:short_prepd_jid(JID),
|
||||||
|
SJID = ejabberd_odbc:escape(exmpp_jid:jid_to_list(U, S, R)),
|
||||||
|
|
||||||
%% Empty groups do not need to be converted to string to be inserted in
|
%% Empty groups do not need to be converted to string to be inserted in
|
||||||
%% the database
|
%% the database
|
||||||
@ -892,8 +888,9 @@ webadmin_page(_, Host,
|
|||||||
webadmin_page(Acc, _, _) -> Acc.
|
webadmin_page(Acc, _, _) -> Acc.
|
||||||
|
|
||||||
user_roster(User, Server, Query, Lang) ->
|
user_roster(User, Server, Query, Lang) ->
|
||||||
LUser = jlib:nodeprep(User),
|
try
|
||||||
LServer = jlib:nameprep(Server),
|
LUser = exmpp_stringprep:nodeprep(User),
|
||||||
|
LServer = exmpp_stringprep:nameprep(Server),
|
||||||
US = {LUser, LServer},
|
US = {LUser, LServer},
|
||||||
Items1 = get_roster(LUser, LServer),
|
Items1 = get_roster(LUser, LServer),
|
||||||
Res = user_roster_parse_query(User, Server, Items1, Query),
|
Res = user_roster_parse_query(User, Server, Items1, Query),
|
||||||
@ -922,9 +919,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_list(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"}],
|
||||||
@ -960,7 +958,17 @@ user_roster(User, Server, Query, Lang) ->
|
|||||||
[?P,
|
[?P,
|
||||||
?INPUT("text", "newjid", ""), ?C(" "),
|
?INPUT("text", "newjid", ""), ?C(" "),
|
||||||
?INPUTT("submit", "addjid", "Add Jabber ID")
|
?INPUTT("submit", "addjid", "Add Jabber ID")
|
||||||
])].
|
])]
|
||||||
|
catch
|
||||||
|
_ ->
|
||||||
|
[?XC("h1", ?T("Roster of ") ++ us_to_list({User, Server}))] ++
|
||||||
|
[?CT("Bad format"), ?P] ++
|
||||||
|
[?XAE("form", [{"action", ""}, {"method", "post"}],
|
||||||
|
[?P,
|
||||||
|
?INPUT("text", "newjid", ""), ?C(" "),
|
||||||
|
?INPUTT("submit", "addjid", "Add Jabber ID")
|
||||||
|
])]
|
||||||
|
end.
|
||||||
|
|
||||||
user_roster_parse_query(User, Server, Items, Query) ->
|
user_roster_parse_query(User, Server, Items, Query) ->
|
||||||
case lists:keysearch("addjid", 1, Query) of
|
case lists:keysearch("addjid", 1, Query) of
|
||||||
@ -969,11 +977,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:list_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 ->
|
||||||
@ -994,9 +1003,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 = jlib: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(
|
||||||
@ -1005,28 +1014,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 = jlib:make_bare_jid(User, Server),
|
||||||
|
Attrs1 = exmpp_xml:set_attribute_in_list([],
|
||||||
|
'jid', exmpp_jid:jid_to_list(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
|
||||||
@ -1037,7 +1050,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_list(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")])].
|
||||||
|
Loading…
Reference in New Issue
Block a user