diff --git a/ChangeLog b/ChangeLog index f163feb2d..4d9262994 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2006-01-24 Alexey Shchepin + + * src/mod_roster_odbc.erl: Bugfix + 2006-01-23 Alexey Shchepin * src/ejabberd_sm.erl: Partially rewritten to work more diff --git a/src/mod_roster_odbc.erl b/src/mod_roster_odbc.erl index be4392e2e..1748d16dc 100644 --- a/src/mod_roster_odbc.erl +++ b/src/mod_roster_odbc.erl @@ -108,9 +108,22 @@ 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{sub_el = SubEl} = IQ) -> LUser = From#jid.luser, LServer = From#jid.lserver, + US = {LUser, LServer}, + case catch ejabberd_hooks:run_fold(roster_get, To#jid.lserver, [], [US]) of + Items when is_list(Items) -> + XItems = lists:map(fun item_to_xml/1, Items), + IQ#iq{type = result, + sub_el = [{xmlelement, "query", + [{"xmlns", ?NS_ROSTER}], + XItems}]}; + _ -> + IQ#iq{type = error, sub_el = [SubEl, ?ERR_INTERNAL_SERVER_ERROR]} + end. + +get_user_roster(Acc, {LUser, LServer}) -> Username = ejabberd_odbc:escape(LUser), case catch ejabberd_odbc:sql_query( LServer, @@ -130,7 +143,7 @@ process_iq_get(From, _To, #iq{sub_el = SubEl} = IQ) -> _ -> [] end, - XItems = lists:flatmap( + RItems = lists:flatmap( fun(I) -> case raw_to_record(I) of error -> @@ -146,33 +159,6 @@ process_iq_get(From, _To, #iq{sub_el = SubEl} = IQ) -> [item_to_xml(R#roster{groups = Groups})] end end, Items), - IQ#iq{type = result, - sub_el = [{xmlelement, "query", - [{"xmlns", ?NS_ROSTER}], - XItems}]}; - _ -> - IQ#iq{type = error, sub_el = [SubEl, ?ERR_INTERNAL_SERVER_ERROR]} - end. - -get_user_roster(Acc, {LUser, LServer}) -> - Username = ejabberd_odbc:escape(LUser), - case catch ejabberd_odbc:sql_query( - LServer, - ["select username, jid, nick, subscription, ask, " - "server, subscribe, type from rosterusers " - "where username='", Username, "'"]) of - {selected, ["username", "jid", "nick", "subscription", "ask", - "server", "subscribe", "type"], - Items} when is_list(Items) -> - RItems = lists:flatmap( - fun(I) -> - case raw_to_record(I) of - error -> - []; - R -> - [R] - end - end, Items), RItems ++ Acc; _ -> Acc