diff --git a/ChangeLog b/ChangeLog index eac4416f9..ba619b6ce 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,10 @@ * src/mod_pubsub/mod_pubsub.erl: Fix typo. + * src/mod_caps.erl, src/ejabberd_c2s.erl: Apply commit + 1212 (caps handling fix), was incorrectly overwritten on + 1770. + 2009-01-11 Christophe Romain * src/mod_pubsub/mod_pubsub.erl: fix owners cache and fix unsubscribe diff --git a/src/ejabberd_c2s.erl b/src/ejabberd_c2s.erl index 266130320..7e3be2d8e 100644 --- a/src/ejabberd_c2s.erl +++ b/src/ejabberd_c2s.erl @@ -37,8 +37,7 @@ send_element/2, socket_type/0, get_presence/1, - get_subscribed/1, - get_subscribed_and_online/1]). + get_subscribed/1]). %% gen_fsm callbacks -export([init/1, @@ -88,7 +87,6 @@ pres_f = ?SETS:new(), pres_a = ?SETS:new(), pres_i = ?SETS:new(), - pres_available = ?DICT:new(), pres_last, pres_pri, pres_timestamp, pres_invis = false, @@ -212,13 +210,8 @@ init([{SockMod, Socket}, Opts]) -> end. %% Return list of all available resources of contacts, -%% in form [{JID, Caps}]. get_subscribed(FsmRef) -> - gen_fsm:sync_send_all_state_event( - FsmRef, get_subscribed, 1000). -get_subscribed_and_online(FsmRef) -> - gen_fsm:sync_send_all_state_event( - FsmRef, get_subscribed_and_online, 1000). + gen_fsm:sync_send_all_state_event(FsmRef, get_subscribed, 1000). %%---------------------------------------------------------------------- @@ -969,29 +962,9 @@ handle_sync_event({get_presence}, _From, StateName, StateData) -> fsm_reply(Reply, StateName, StateData); handle_sync_event(get_subscribed, _From, StateName, StateData) -> - Subscribed = StateData#state.pres_f, - Online = StateData#state.pres_available, - Pred = fun({U, S, _} = User, _Caps) -> - ?SETS:is_element({U, S, undefined}, - Subscribed) orelse - ?SETS:is_element(User, Subscribed) - end, - SubscribedAndOnline = ?DICT:filter(Pred, Online), - SubscribedWithCaps = ?SETS:fold(fun(User, Acc) -> - [{User, undefined}|Acc] - end, ?DICT:to_list(SubscribedAndOnline), Subscribed), - {reply, SubscribedWithCaps, StateName, StateData}; + Subscribed = ?SETS:to_list(StateData#state.pres_f), + {reply, Subscribed, StateName, StateData}; -handle_sync_event(get_subscribed_and_online, _From, StateName, StateData) -> - Subscribed = StateData#state.pres_f, - Online = StateData#state.pres_available, - Pred = fun({U, S, _R} = User, _Caps) -> - ?SETS:is_element({U, S, undefined}, - Subscribed) orelse - ?SETS:is_element(User, Subscribed) - end, - SubscribedAndOnline = ?DICT:filter(Pred, Online), - {reply, ?DICT:to_list(SubscribedAndOnline), StateName, StateData}; handle_sync_event(_Event, _From, StateName, StateData) -> Reply = ok, @@ -1084,43 +1057,40 @@ handle_info({route, From, To, Packet}, StateName, StateData) -> LBFrom = jlib:short_prepd_bare_jid(From), %% Note contact availability Els = Packet#xmlel.children, - Caps = mod_caps:read_caps(Els), - ServerString = binary_to_list(StateData#state.server), - mod_caps:note_caps(ServerString, From, Caps), - NewAvailable = case exmpp_presence:get_type(Packet) of - 'unavailable' -> - ?DICT:erase(LFrom, StateData#state.pres_available); - _ -> - %?DICT:store(LFrom, Caps, StateData#state.pres_available) - StateData#state.pres_available - end, - NewStateData = StateData#state{pres_available = NewAvailable}, + case exmpp_presence:get_type(Packet) of + 'unavailable' -> + mod_caps:clear_caps(From); + _ -> + ServerString = binary_to_list(StateData#state.server), + Caps = mod_caps:read_caps(Els), + mod_caps:note_caps(ServerString, From, Caps) + end, case ?SETS:is_element( - LFrom, NewStateData#state.pres_a) orelse + LFrom, StateData#state.pres_a) orelse ?SETS:is_element( - LBFrom, NewStateData#state.pres_a) of + LBFrom, StateData#state.pres_a) of true -> - {true, Attrs, NewStateData}; + {true, Attrs, StateData}; false -> case ?SETS:is_element( - LFrom, NewStateData#state.pres_f) of + LFrom, StateData#state.pres_f) of true -> A = ?SETS:add_element( LFrom, - NewStateData#state.pres_a), + StateData#state.pres_a), {true, Attrs, - NewStateData#state{pres_a = A}}; + StateData#state{pres_a = A}}; false -> case ?SETS:is_element( - LBFrom, NewStateData#state.pres_f) of + LBFrom, StateData#state.pres_f) of true -> A = ?SETS:add_element( LBFrom, - NewStateData#state.pres_a), + StateData#state.pres_a), {true, Attrs, - NewStateData#state{pres_a = A}}; + StateData#state{pres_a = A}}; false -> - {true, Attrs, NewStateData} + {true, Attrs, StateData} end end end; diff --git a/src/mod_caps.erl b/src/mod_caps.erl index 4363722d7..9d694c5db 100644 --- a/src/mod_caps.erl +++ b/src/mod_caps.erl @@ -96,9 +96,9 @@ get_caps({U, S, R}) -> end. %% clear_caps removes user caps from database -clear_caps({U, S, R}) -> - BJID = exmpp_jid:jid_to_binary(U, S, R), - BUID = exmpp_jid:jid_to_binary(U, S), +clear_caps(JID) -> + BJID = exmpp_jid:jid_to_binary(JID), + BUID = exmpp_jid:bare_jid_to_binary(JID), catch mnesia:dirty_delete({user_caps, BJID}), case catch mnesia:dirty_read({user_caps_default, BUID}) of [#user_caps_default{resource=R}] ->