mirror of
https://github.com/processone/ejabberd.git
synced 2024-12-26 17:38:45 +01:00
* src/mod_roster_odbc.erl: Bugfix
SVN Revision: 504
This commit is contained in:
parent
6eac737807
commit
73073d4af5
@ -25,14 +25,7 @@
|
|||||||
|
|
||||||
-include("ejabberd.hrl").
|
-include("ejabberd.hrl").
|
||||||
-include("jlib.hrl").
|
-include("jlib.hrl").
|
||||||
|
-include("mod_roster.hrl").
|
||||||
-record(roster, {user,
|
|
||||||
jid,
|
|
||||||
name = "",
|
|
||||||
subscription = none,
|
|
||||||
ask = none,
|
|
||||||
groups = []
|
|
||||||
}).
|
|
||||||
|
|
||||||
start(Host, Opts) ->
|
start(Host, Opts) ->
|
||||||
IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
|
IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
|
||||||
@ -74,8 +67,8 @@ stop(Host) ->
|
|||||||
process_iq(From, To, IQ) ->
|
process_iq(From, To, IQ) ->
|
||||||
#iq{sub_el = SubEl} = IQ,
|
#iq{sub_el = SubEl} = IQ,
|
||||||
#jid{lserver = LServer} = From,
|
#jid{lserver = LServer} = From,
|
||||||
case ?MYNAME of
|
case lists:member(LServer, ?MYHOSTS) of
|
||||||
LServer ->
|
true ->
|
||||||
ResIQ = process_local_iq(From, To, IQ),
|
ResIQ = process_local_iq(From, To, IQ),
|
||||||
ejabberd_router:route(From, From,
|
ejabberd_router:route(From, From,
|
||||||
jlib:iq_to_xml(ResIQ)),
|
jlib:iq_to_xml(ResIQ)),
|
||||||
@ -89,8 +82,8 @@ process_iq(From, To, IQ) ->
|
|||||||
process_iq(From, To, IQ) ->
|
process_iq(From, To, IQ) ->
|
||||||
#iq{sub_el = SubEl} = IQ,
|
#iq{sub_el = SubEl} = IQ,
|
||||||
#jid{lserver = LServer} = From,
|
#jid{lserver = LServer} = From,
|
||||||
case ?MYNAME of
|
case lists:member(LServer, ?MYHOSTS) of
|
||||||
LServer ->
|
true ->
|
||||||
process_local_iq(From, To, IQ);
|
process_local_iq(From, To, IQ);
|
||||||
_ ->
|
_ ->
|
||||||
IQ#iq{type = error, sub_el = [SubEl, ?ERR_ITEM_NOT_FOUND]}
|
IQ#iq{type = error, sub_el = [SubEl, ?ERR_ITEM_NOT_FOUND]}
|
||||||
@ -145,7 +138,7 @@ get_user_roster(Acc, {LUser, LServer}) ->
|
|||||||
end,
|
end,
|
||||||
RItems = lists:flatmap(
|
RItems = lists:flatmap(
|
||||||
fun(I) ->
|
fun(I) ->
|
||||||
case raw_to_record(I) of
|
case raw_to_record(LServer, I) of
|
||||||
error ->
|
error ->
|
||||||
[];
|
[];
|
||||||
R ->
|
R ->
|
||||||
@ -227,11 +220,14 @@ process_item_set(From, To, {xmlelement, _Name, Attrs, Els}) ->
|
|||||||
"and jid='", SJID, "'"]),
|
"and jid='", SJID, "'"]),
|
||||||
Item = case Res of
|
Item = case Res of
|
||||||
[] ->
|
[] ->
|
||||||
#roster{user = LUser,
|
#roster{usj = {LUser, LServer, LJID},
|
||||||
|
us = {LUser, LServer},
|
||||||
jid = LJID};
|
jid = LJID};
|
||||||
[I] ->
|
[I] ->
|
||||||
(raw_to_record(I))#roster{user = LUser,
|
(raw_to_record(LServer, I))#roster{
|
||||||
jid = JID,
|
usj = {LUser, LServer, LJID},
|
||||||
|
us = {LUser, LServer},
|
||||||
|
jid = LJID,
|
||||||
name = ""}
|
name = ""}
|
||||||
end,
|
end,
|
||||||
Item1 = process_item_attrs(Item, Attrs),
|
Item1 = process_item_attrs(Item, Attrs),
|
||||||
@ -325,7 +321,7 @@ process_item_attrs(Item, [{Attr, Val} | Attrs]) ->
|
|||||||
error ->
|
error ->
|
||||||
process_item_attrs(Item, Attrs);
|
process_item_attrs(Item, Attrs);
|
||||||
JID1 ->
|
JID1 ->
|
||||||
JID = {JID1#jid.user, JID1#jid.server, JID1#jid.resource},
|
JID = {JID1#jid.luser, JID1#jid.lserver, JID1#jid.lresource},
|
||||||
process_item_attrs(Item#roster{jid = JID}, Attrs)
|
process_item_attrs(Item#roster{jid = JID}, Attrs)
|
||||||
end;
|
end;
|
||||||
"name" ->
|
"name" ->
|
||||||
@ -413,25 +409,25 @@ get_subscription_lists(_, User, Server) ->
|
|||||||
{selected, ["username", "jid", "nick", "subscription", "ask",
|
{selected, ["username", "jid", "nick", "subscription", "ask",
|
||||||
"server", "subscribe", "type"],
|
"server", "subscribe", "type"],
|
||||||
Items} when is_list(Items) ->
|
Items} when is_list(Items) ->
|
||||||
fill_subscription_lists(Items, [], []);
|
fill_subscription_lists(LServer, Items, [], []);
|
||||||
_ ->
|
_ ->
|
||||||
{[], []}
|
{[], []}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
fill_subscription_lists([RawI | Is], F, T) ->
|
fill_subscription_lists(LServer, [RawI | Is], F, T) ->
|
||||||
I = raw_to_record(RawI),
|
I = raw_to_record(LServer, RawI),
|
||||||
J = I#roster.jid,
|
J = I#roster.jid,
|
||||||
case I#roster.subscription of
|
case I#roster.subscription of
|
||||||
both ->
|
both ->
|
||||||
fill_subscription_lists(Is, [J | F], [J | T]);
|
fill_subscription_lists(LServer, Is, [J | F], [J | T]);
|
||||||
from ->
|
from ->
|
||||||
fill_subscription_lists(Is, [J | F], T);
|
fill_subscription_lists(LServer, Is, [J | F], T);
|
||||||
to ->
|
to ->
|
||||||
fill_subscription_lists(Is, F, [J | T]);
|
fill_subscription_lists(LServer, Is, F, [J | T]);
|
||||||
_ ->
|
_ ->
|
||||||
fill_subscription_lists(Is, F, T)
|
fill_subscription_lists(LServer, Is, F, T)
|
||||||
end;
|
end;
|
||||||
fill_subscription_lists([], F, T) ->
|
fill_subscription_lists(_LServer, [], F, T) ->
|
||||||
{F, T}.
|
{F, T}.
|
||||||
|
|
||||||
ask_to_pending(subscribe) -> out;
|
ask_to_pending(subscribe) -> out;
|
||||||
@ -463,7 +459,7 @@ process_subscription(Direction, User, Server, JID1, Type) ->
|
|||||||
["username", "jid", "nick", "subscription", "ask",
|
["username", "jid", "nick", "subscription", "ask",
|
||||||
"server", "subscribe", "type"],
|
"server", "subscribe", "type"],
|
||||||
[I]} ->
|
[I]} ->
|
||||||
R = raw_to_record(I),
|
R = raw_to_record(LServer, I),
|
||||||
Groups =
|
Groups =
|
||||||
case ejabberd_odbc:sql_query_t(
|
case ejabberd_odbc:sql_query_t(
|
||||||
["select grp from rostergroups "
|
["select grp from rostergroups "
|
||||||
@ -479,7 +475,8 @@ process_subscription(Direction, User, Server, JID1, Type) ->
|
|||||||
["username", "jid", "nick", "subscription", "ask",
|
["username", "jid", "nick", "subscription", "ask",
|
||||||
"server", "subscribe", "type"],
|
"server", "subscribe", "type"],
|
||||||
[]} ->
|
[]} ->
|
||||||
#roster{user = LUser,
|
#roster{usj = {LUser, LServer, LJID},
|
||||||
|
us = {LUser, LServer},
|
||||||
jid = LJID}
|
jid = LJID}
|
||||||
end,
|
end,
|
||||||
NewState = case Direction of
|
NewState = case Direction of
|
||||||
@ -681,7 +678,8 @@ process_item_set_t(LUser, LServer, {xmlelement, _Name, Attrs, Els}) ->
|
|||||||
LJID = {JID1#jid.luser, JID1#jid.lserver, JID1#jid.lresource},
|
LJID = {JID1#jid.luser, JID1#jid.lserver, JID1#jid.lresource},
|
||||||
Username = ejabberd_odbc:escape(LUser),
|
Username = ejabberd_odbc:escape(LUser),
|
||||||
SJID = ejabberd_odbc:escape(jlib:jid_to_string(LJID)),
|
SJID = ejabberd_odbc:escape(jlib:jid_to_string(LJID)),
|
||||||
Item = #roster{user = LUser,
|
Item = #roster{usj = {LUser, LServer, LJID},
|
||||||
|
us = {LUser, LServer},
|
||||||
jid = LJID},
|
jid = LJID},
|
||||||
Item1 = process_item_attrs_ws(Item, Attrs),
|
Item1 = process_item_attrs_ws(Item, Attrs),
|
||||||
Item2 = process_item_els(Item1, Els),
|
Item2 = process_item_els(Item1, Els),
|
||||||
@ -723,7 +721,7 @@ process_item_attrs_ws(Item, [{Attr, Val} | Attrs]) ->
|
|||||||
error ->
|
error ->
|
||||||
process_item_attrs_ws(Item, Attrs);
|
process_item_attrs_ws(Item, Attrs);
|
||||||
JID1 ->
|
JID1 ->
|
||||||
JID = {JID1#jid.user, JID1#jid.server, JID1#jid.resource},
|
JID = {JID1#jid.luser, JID1#jid.lserver, JID1#jid.lresource},
|
||||||
process_item_attrs_ws(Item#roster{jid = JID}, Attrs)
|
process_item_attrs_ws(Item#roster{jid = JID}, Attrs)
|
||||||
end;
|
end;
|
||||||
"name" ->
|
"name" ->
|
||||||
@ -826,7 +824,7 @@ get_jid_info(_, User, Server, JID) ->
|
|||||||
|
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
|
||||||
raw_to_record({User, SJID, Nick, SSubscription, SAsk,
|
raw_to_record(LServer, {User, SJID, Nick, SSubscription, SAsk,
|
||||||
_SServer, _SSubscribe, _SType}) ->
|
_SServer, _SSubscribe, _SType}) ->
|
||||||
case jlib:string_to_jid(SJID) of
|
case jlib:string_to_jid(SJID) of
|
||||||
error ->
|
error ->
|
||||||
@ -847,14 +845,15 @@ raw_to_record({User, SJID, Nick, SSubscription, SAsk,
|
|||||||
"I" -> in;
|
"I" -> in;
|
||||||
_ -> none
|
_ -> none
|
||||||
end,
|
end,
|
||||||
#roster{user = User,
|
#roster{usj = {User, LServer, LJID},
|
||||||
|
us = {User, LServer},
|
||||||
jid = LJID,
|
jid = LJID,
|
||||||
name = Nick,
|
name = Nick,
|
||||||
subscription = Subscription,
|
subscription = Subscription,
|
||||||
ask = Ask}
|
ask = Ask}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
record_to_string(#roster{user = User,
|
record_to_string(#roster{us = {User, _Server},
|
||||||
jid = JID,
|
jid = JID,
|
||||||
name = Name,
|
name = Name,
|
||||||
subscription = Subscription,
|
subscription = Subscription,
|
||||||
@ -884,7 +883,7 @@ record_to_string(#roster{user = User,
|
|||||||
"'", SAsk, "',"
|
"'", SAsk, "',"
|
||||||
"'N', '', 'item')"].
|
"'N', '', 'item')"].
|
||||||
|
|
||||||
groups_to_string(#roster{user = User,
|
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),
|
||||||
|
Loading…
Reference in New Issue
Block a user