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

Apply commit 1212 (caps handling fix), was incorrectly overwritten on 1770.

SVN Revision: 1807
This commit is contained in:
Pablo Polvorin 2009-01-12 18:15:44 +00:00
parent 96c0ff44f9
commit 49210e3099
3 changed files with 29 additions and 55 deletions

View File

@ -2,6 +2,10 @@
* src/mod_pubsub/mod_pubsub.erl: Fix typo. * 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 <christophe.romain@process-one.net> 2009-01-11 Christophe Romain <christophe.romain@process-one.net>
* src/mod_pubsub/mod_pubsub.erl: fix owners cache and fix unsubscribe * src/mod_pubsub/mod_pubsub.erl: fix owners cache and fix unsubscribe

View File

@ -37,8 +37,7 @@
send_element/2, send_element/2,
socket_type/0, socket_type/0,
get_presence/1, get_presence/1,
get_subscribed/1, get_subscribed/1]).
get_subscribed_and_online/1]).
%% gen_fsm callbacks %% gen_fsm callbacks
-export([init/1, -export([init/1,
@ -88,7 +87,6 @@
pres_f = ?SETS:new(), pres_f = ?SETS:new(),
pres_a = ?SETS:new(), pres_a = ?SETS:new(),
pres_i = ?SETS:new(), pres_i = ?SETS:new(),
pres_available = ?DICT:new(),
pres_last, pres_pri, pres_last, pres_pri,
pres_timestamp, pres_timestamp,
pres_invis = false, pres_invis = false,
@ -212,13 +210,8 @@ init([{SockMod, Socket}, Opts]) ->
end. end.
%% Return list of all available resources of contacts, %% Return list of all available resources of contacts,
%% in form [{JID, Caps}].
get_subscribed(FsmRef) -> get_subscribed(FsmRef) ->
gen_fsm:sync_send_all_state_event( gen_fsm:sync_send_all_state_event(FsmRef, get_subscribed, 1000).
FsmRef, get_subscribed, 1000).
get_subscribed_and_online(FsmRef) ->
gen_fsm:sync_send_all_state_event(
FsmRef, get_subscribed_and_online, 1000).
%%---------------------------------------------------------------------- %%----------------------------------------------------------------------
@ -969,29 +962,9 @@ handle_sync_event({get_presence}, _From, StateName, StateData) ->
fsm_reply(Reply, StateName, StateData); fsm_reply(Reply, StateName, StateData);
handle_sync_event(get_subscribed, _From, StateName, StateData) -> handle_sync_event(get_subscribed, _From, StateName, StateData) ->
Subscribed = StateData#state.pres_f, Subscribed = ?SETS:to_list(StateData#state.pres_f),
Online = StateData#state.pres_available, {reply, Subscribed, StateName, StateData};
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};
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) -> handle_sync_event(_Event, _From, StateName, StateData) ->
Reply = ok, Reply = ok,
@ -1084,43 +1057,40 @@ handle_info({route, From, To, Packet}, StateName, StateData) ->
LBFrom = jlib:short_prepd_bare_jid(From), LBFrom = jlib:short_prepd_bare_jid(From),
%% Note contact availability %% Note contact availability
Els = Packet#xmlel.children, Els = Packet#xmlel.children,
Caps = mod_caps:read_caps(Els), case exmpp_presence:get_type(Packet) of
ServerString = binary_to_list(StateData#state.server), 'unavailable' ->
mod_caps:note_caps(ServerString, From, Caps), mod_caps:clear_caps(From);
NewAvailable = case exmpp_presence:get_type(Packet) of _ ->
'unavailable' -> ServerString = binary_to_list(StateData#state.server),
?DICT:erase(LFrom, StateData#state.pres_available); Caps = mod_caps:read_caps(Els),
_ -> mod_caps:note_caps(ServerString, From, Caps)
%?DICT:store(LFrom, Caps, StateData#state.pres_available) end,
StateData#state.pres_available
end,
NewStateData = StateData#state{pres_available = NewAvailable},
case ?SETS:is_element( case ?SETS:is_element(
LFrom, NewStateData#state.pres_a) orelse LFrom, StateData#state.pres_a) orelse
?SETS:is_element( ?SETS:is_element(
LBFrom, NewStateData#state.pres_a) of LBFrom, StateData#state.pres_a) of
true -> true ->
{true, Attrs, NewStateData}; {true, Attrs, StateData};
false -> false ->
case ?SETS:is_element( case ?SETS:is_element(
LFrom, NewStateData#state.pres_f) of LFrom, StateData#state.pres_f) of
true -> true ->
A = ?SETS:add_element( A = ?SETS:add_element(
LFrom, LFrom,
NewStateData#state.pres_a), StateData#state.pres_a),
{true, Attrs, {true, Attrs,
NewStateData#state{pres_a = A}}; StateData#state{pres_a = A}};
false -> false ->
case ?SETS:is_element( case ?SETS:is_element(
LBFrom, NewStateData#state.pres_f) of LBFrom, StateData#state.pres_f) of
true -> true ->
A = ?SETS:add_element( A = ?SETS:add_element(
LBFrom, LBFrom,
NewStateData#state.pres_a), StateData#state.pres_a),
{true, Attrs, {true, Attrs,
NewStateData#state{pres_a = A}}; StateData#state{pres_a = A}};
false -> false ->
{true, Attrs, NewStateData} {true, Attrs, StateData}
end end
end end
end; end;

View File

@ -96,9 +96,9 @@ get_caps({U, S, R}) ->
end. end.
%% clear_caps removes user caps from database %% clear_caps removes user caps from database
clear_caps({U, S, R}) -> clear_caps(JID) ->
BJID = exmpp_jid:jid_to_binary(U, S, R), BJID = exmpp_jid:jid_to_binary(JID),
BUID = exmpp_jid:jid_to_binary(U, S), BUID = exmpp_jid:bare_jid_to_binary(JID),
catch mnesia:dirty_delete({user_caps, BJID}), catch mnesia:dirty_delete({user_caps, BJID}),
case catch mnesia:dirty_read({user_caps_default, BUID}) of case catch mnesia:dirty_read({user_caps_default, BUID}) of
[#user_caps_default{resource=R}] -> [#user_caps_default{resource=R}] ->