25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-24 16:23:40 +01:00

EJAB-491 fix

SVN Revision: 1145
This commit is contained in:
Christophe Romain 2008-01-11 01:39:10 +00:00
parent 04eb1c6641
commit 20c27ea9d9
2 changed files with 65 additions and 63 deletions

View File

@ -1403,11 +1403,8 @@ process_presence_probe(From, To, StateData) ->
deny ->
ok;
allow ->
Caps = case ?DICT:find(jlib:jid_tolower(To), StateData#state.pres_available) of
{ok, Value} -> Value;
_ -> mod_caps:read_caps(element(4, Packet)) % This is From=To case, so we can read Caps from Packet
end,
ejabberd_hooks:run(presence_probe_hook, StateData#state.server, [From, To, Caps]),
Pid=element(2, StateData#state.sid),
ejabberd_hooks:run(presence_probe_hook, StateData#state.server, [From, To, Pid]),
ejabberd_router:route(To, From, Packet)
end;
Cond2 ->

View File

@ -396,9 +396,11 @@ disco_sm_items(Acc, _From, To, Node, _Lang) ->
%% presence hooks handling functions
%%
presence_probe(#jid{lserver = Host} = From, To, Caps) ->
presence_probe(#jid{lserver = Host} = JID, JID, Pid) ->
Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
gen_server:cast(Proc, {presence, From, To, Caps}).
gen_server:cast(Proc, {presence, JID, Pid});
presence_probe(_, _, _) ->
ok.
%% -------
%% user remove hook handling function
@ -437,66 +439,72 @@ handle_call(stop, _From, State) ->
%% Description: Handling cast messages
%%--------------------------------------------------------------------
%% @private
handle_cast({presence, From, To, Caps}, State) ->
handle_cast({presence, JID, Pid}, State) ->
%% A new resource is available. send last published items
LFrom = jlib:jid_tolower(From),
LJID = jlib:jid_tolower(JID),
Host = State#state.host,
ServerHost = State#state.server_host,
if From == To ->
%% for each node From is subscribed to
%% and if the node is so configured, send the last published item to From
lists:foreach(fun(Type) ->
{result, Subscriptions} = node_action(Type, get_entity_subscriptions, [Host, From]),
lists:foreach(
fun({Node, subscribed}) ->
case tree_action(Host, get_node, [Host, Node]) of
#pubsub_node{options = Options} ->
case get_option(Options, send_last_published_item) of
on_sub_and_presence ->
send_last_item(Host, Node, LFrom);
_ ->
ok
end;
_ ->
ok
end;
(_) ->
ok
end, Subscriptions)
end, State#state.plugins);
true ->
ok
end,
%% and send to From last PEP events published by To
?DEBUG("got presence probe from ~s to ~s",[jlib:jid_to_string(From),jlib:jid_to_string(To)]),
PepKey = jlib:jid_tolower(jlib:jid_remove_resource(To)),
lists:foreach(fun(#pubsub_node{nodeid = {_, Node}, options = Options}) ->
case get_option(Options, send_last_published_item) of
on_sub_and_presence ->
case is_caps_notify(ServerHost, Node, Caps) of
true ->
Subscribed = case get_option(Options, access_model) of
open -> true;
presence -> true;
whitelist -> false; % subscribers are added manually
authorize -> false; % likewise
roster ->
Grps = get_option(Options, roster_groups_allowed),
element(2, get_roster_info(To#jid.luser, To#jid.lserver, LFrom, Grps))
end,
if Subscribed ->
?DEBUG("send ~s's ~s event to ~s",[jlib:jid_to_string(PepKey),Node,jlib:jid_to_string(From)]),
send_last_item(PepKey, Node, LFrom);
true ->
ok
%% for each node From is subscribed to
%% and if the node is so configured, send the last published item to From
lists:foreach(fun(Type) ->
{result, Subscriptions} = node_action(Type, get_entity_subscriptions, [Host, JID]),
lists:foreach(
fun({Node, subscribed}) ->
case tree_action(Host, get_node, [Host, Node]) of
#pubsub_node{options = Options} ->
case get_option(Options, send_last_published_item) of
on_sub_and_presence ->
send_last_item(Host, Node, LJID);
_ ->
ok
end;
false ->
_ ->
ok
end;
_ ->
(_) ->
ok
end
end, tree_action(Host, get_nodes, [PepKey])),
end, Subscriptions)
end, State#state.plugins),
%% and send to From last PEP events published by its contacts
case catch ejabberd_c2s:get_subscribed_and_online(Pid) of
ContactsWithCaps when is_list(ContactsWithCaps) ->
Caps = proplists:get_value(LJID, ContactsWithCaps),
ContactsUsers = lists:usort(lists:map(
fun({{User, Server, _}, _}) -> {User, Server} end, ContactsWithCaps)),
lists:foreach(
fun({User, Server}) ->
PepKey = {User, Server, ""},
lists:foreach(fun(#pubsub_node{nodeid = {_, Node}, options = Options}) ->
case get_option(Options, send_last_published_item) of
on_sub_and_presence ->
case is_caps_notify(ServerHost, Node, Caps) of
true ->
Subscribed = case get_option(Options, access_model) of
open -> true;
presence -> true;
whitelist -> false; % subscribers are added manually
authorize -> false; % likewise
roster ->
Grps = get_option(Options, roster_groups_allowed),
element(2, get_roster_info(User, Server, LJID, Grps))
end,
if Subscribed ->
?DEBUG("send ~s's ~s event to ~s",[jlib:jid_to_string(PepKey),Node,jlib:jid_to_string(LJID)]),
send_last_item(PepKey, Node, LJID);
true ->
ok
end;
false ->
ok
end;
_ ->
ok
end
end, tree_action(Host, get_nodes, [PepKey]))
end, ContactsUsers);
_ ->
ok
end,
{noreply, State};
handle_cast({remove, User, Server}, State) ->
@ -641,9 +649,6 @@ do_route(ServerHost, Access, Plugins, Host, From, To, Packet) ->
_ ->
ok
end;
"presence" ->
presence_probe(From, To, Packet),
ok;
"message" ->
case xml:get_attr_s("type", Attrs) of
"error" ->